如何在具有相应卡的机器人中实现按钮点击功能

时间:2017-11-23 06:08:51

标签: c# visual-studio-2015 bots adaptive-cards

您好我正在研究Bot,因为我有一个要求,例如用户点击按钮我想在下一张卡片中显示相关内容,如下所示。

enter image description here

任何人都可以告诉我如何使用自适应卡,富卡或缩略图卡等机器人在机器人中实现上述方案吗?

1 个答案:

答案 0 :(得分:1)

使用自适应卡,您可以使用AdaptiveSubmitAction

new AdaptiveSubmitAction()
{
    Data = "show me the next card"
};

这会生成一条新的传入消息,message.Text的值为Data,您可以像处理来自用户的常规消息一样处理它。

您可以使用ImBackPostBack操作与其他富卡/缩略图卡实现相同的效果:

new CardAction()
{
    Type = ActionTypes.ImBack,
    Value = "show me the next card"
}

AdaptiveSubmitAction还有DataJson属性,您可以使用Data而不是DataJson(如果您同时使用message.Value,则message.Text无效)。您可以在那里放置一个json结构,最终会在传入消息的DataJson = "{ \"CardName\": \"City\", \"Name\": \"New York\" }"中结束,而在这种情况下protected override async Task MessageReceived(IDialogContext context, IAwaitable<IMessageActivity> item) { var message = await item; if (string.IsNullOrEmpty(message.Text)) { dynamic value = message.Value; if (value == null) { // empty message - show help, error etc. } dynamic cardName = value.CardName; // check the name, respond with the wanted card ... } else { // process as usual await base.MessageReceived(context, item); } } 将为null。

当您需要传递更多细节时,这可能很方便,例如: { "_40":0,"_65":0,"_55":null,"_72":null }可能意味着您要为纽约开设一张城市卡。然后你可以检索这样的结构:

console.log

Here是一个使用json方法的示例项目。