简体   繁体   English

发送英雄或自适应卡片并在欢迎时获取用户输入

[英]Send Hero or Adaptive card & Get User Input on Welcome

I am developing Bot in .NET Core 3.1 C#.我正在 .NET Core 3.1 C# 中开发 Bot。 I want to send Hero card with 4 buttons & welcome prompt as soon as user joins /activates bot.我想在用户加入/激活机器人后立即发送带有 4 个按钮和欢迎提示的英雄卡。 I have tried it in OnMembersAddedAsync我已经在 OnMembersAddedAsync 中尝试过

if (member.Id != turnContext.Activity.Recipient.Id)
            {
                var welcomeCard = CreateAdaptiveCardAttachment();
                var response = MessageFactory.Attachment(welcomeCard);

                await turnContext.SendActivityAsync( response,  cancellationToken);
            }     

This will display adaptive card where type is Action.Submit.这将显示类型为 Action.Submit 的自适应卡片。 But I am not sure how to get values of the button which customer click on.但我不确定如何获取客户点击的按钮的值。 I tried it on OnMessageActivityAsync我在 OnMessageActivityAsync 上试过了

 if (turnContext.Activity.Value != null)
        {
            var mainMenu = turnContext.Activity.Value;
        }

But values are always null.但值始终为 null。 Json for adaptive card is:自适应卡的 Json 为:

 {
  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
  "type": "AdaptiveCard",
  "version": "1.0",
  "body": [   
    {
      "type": "TextBlock",
      "spacing": "medium",
      "size": "default",
      "weight": "bolder",
      "text": "Welcome to ABC Bank !",
      "wrap": true,
      "maxLines": 0
    },
    {
      "type": "TextBlock",
      "size": "default",
      "isSubtle": true,
      "text": "Please select user type from below ....",
      "wrap": true,
      "maxLines": 0
    }
  ],
  "actions": [
    {
      "type": "Action.Submit",
      "title": "Consumer"
    },
    {
      "type": "Action.Submit",
      "title": "Client"
    },
    {
      "type": "Action.Submit",
      "title": "Merchant"
    }
  ]
}

Yes.是的。 As said in comments you need to add data property.如评论中所述,您需要添加data属性。 This is not required.这不是必需的。 But if you want to collect which option user has provided you need to specify it.但是如果你想收集用户提供的选项,你需要指定它。 Since you don't have any other input field.由于您没有任何其他输入字段。 This will act as an input to carry further operations.这将作为进行进一步操作的输入。

Note : For any input element you need to use id property to identify collected input when submit action is performed.注意:对于任何输入元素,您需要在执行提交操作时使用id属性来识别收集的输入。
Similarly for Submit action data .提交操作data也是如此。 Make sure value in data for each action is unique.确保每个操作的数据值是唯一的。 If you want 2 buttons to perform same action (nativate to same dialog) then you can specify same value in data如果您希望 2 个按钮执行相同的操作(进入相同的对话框),那么您可以在data中指定相同的值

Here is the official link which gives you an idea.这是给你一个想法的官方链接。 Submit action提交操作

Hope this helps希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM