【问题标题】:Can not get adaptive card value from Json file无法从 Json 文件中获取自适应卡值
【发布时间】:2020-02-13 00:35:48
【问题描述】:

我有以下 Json 文件

{
  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
  "type": "AdaptiveCard",
  "version": "1.0",
  "body": [
    {
      "type": "TextBlock",
      "size": "Medium",
      "weight": "Bolder",
      "text": "Customer Information Form",
      "horizontalAlignment": "Center"
    },
    {
      "type": "Input.Text",
      "placeholder": "First Name",
      "style": "text",
      "maxLength": 0,
      "id": "SimpleVal",
      "color": "Red"
    },
    {
      "type": "Input.Text",
      "placeholder": "Last Name",
      "style": "Url",
      "maxLength": 0,
      "id": "UrlVal"
    },
    {
      "type": "Input.Text",
      "placeholder": "Company Name",
      "style": "text",
      "maxLength": 0,
      "id": "companyname",
      "color": "Red"
    },
    {
      "type": "Input.Text",
      "placeholder": "Email",
      "style": "Email",
      "maxLength": 0,
      "id": "EmailVal"
    },
    {
      "type": "Input.ChoiceSet",
      "placeholder": "Country",
      "id": "CompactSelectVal",
      "value": "1",
      "choices": [
        {
          "title": "Country",
          "value": "1"
        },
        {
          "title": "United States",
          "value": "2"
        },
        {
          "title": "Algeria",
          "value": "3"
        }
      ]
    },
    {
      "type": "Input.Text",
      "placeholder": "Phone Number",
      "style": "Tel",
      "maxLength": 0,
      "id": "TelVal"
    }




  ],
  "actions": [
    {
      "type": "Action.Submit",
      "title": "Submit",
      "data": {
        "id": "1234567890"
      }
    }
  ]
}

这是我的 Bot 输入表单:

当我尝试从 turnContext 中检索值时,我得到了 null 值。请看下面的代码:

protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
    {
        Random r = new Random();
        var cardAttachment = CreateAdaptiveCardAttachment(_cards[r.Next(_cards.Length)]);

        await turnContext.SendActivityAsync(MessageFactory.Attachment(cardAttachment), cancellationToken);
        await turnContext.SendActivityAsync(MessageFactory.Text("Your Request has submitted. Thank you"), cancellationToken);
    } 

我认为我应该从 turnContext 活动中获得价值。但它看起来是空的。

【问题讨论】:

    标签: botframework azure-bot-service adaptive-cards


    【解决方案1】:

    尝试使用以下代码从自适应卡片中获取价值:

    //Captature sumitted value
    var txt = turnContext.Activity.Text;
    dynamic val = turnContext.Activity.Value;
    

    希望对您有所帮助!

    【讨论】:

    • 你的意思是我应该在 OnMessageActivityAsync 这个方法中做吗?
    • 是的。在 OnMessageActivityAsync 中插入代码获取自适应卡片值
    猜你喜欢
    • 2023-03-21
    • 1970-01-01
    • 2021-11-26
    • 2013-03-02
    • 2020-11-07
    • 2017-11-07
    • 1970-01-01
    • 2019-12-16
    • 1970-01-01
    相关资源
    最近更新 更多