如何在Microsoft bot v4中捕获来自Hero卡的用户回复

时间:2019-09-11 14:15:10

标签: c# botframework

我想在Microsoft bot v4中的英雄卡上单击选项之一后捕获用户答复。 请你帮助我好吗? 谢谢

var card777 = new HeroCard
{
    //Text = "Could you please click on the below button to continue?",
    Buttons = new List<CardAction>
    {
        new CardAction(ActionTypes.ImBack, title: "Yes", value: "contain"),
        new CardAction(ActionTypes.ImBack, title: "No", value: "Does not contain"),
    },
};

var reply777 = MessageFactory.Attachment(card777.ToAttachment());
await turnContext.SendActivityAsync(reply777, cancellationToken);

在聊天室中显示英雄卡片后,用户将选择卡片动作之一。 然后,我想在答案变量中捕获该选定值,以便我可以对答案变量进行进一步的操作

  /*  if (answer = "contain")
    {
        countAccessRequest = 1;

    }
    else
    {

        countAccessRequest = 4;
        startAccessRequestFlow = false;
    }
    */
}

1 个答案:

答案 0 :(得分:0)

如果您使用 ActionTypes.MessageBack ,则可以通过以下方式从 Activity.Value 捕获

   var card777 = new HeroCard
        {
            //Text = "Could you please click on the below button to continue?",
            Buttons = new List<CardAction>
             {
            new CardAction(ActionTypes.MessageBack, title: "Yes", value: "contain"),
            new CardAction(ActionTypes.MessageBack, title: "No", value: "Does not contain"),
             },
        };

        if (context.Activity.Value != null)
        {
            // payload will either be "contain" or "does not contain"
            string payload = context.Activity.Value.ToString();
        }