首页 > 解决方案 > 如何在 Microsoft bot v4 中从英雄卡中捕获用户回复

问题描述

单击 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;
    }
    */
}

标签: c#botframework

解决方案


如果您使用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();
        }

推荐阅读