【问题标题】:Retrieve data from input form adaptive card从输入表单自适应卡中检索数据
【发布时间】:2018-04-22 15:08:49
【问题描述】:

我在我的机器人框架中使用输入表单作为自适应卡片。 现在我想检索用户在表单中提供的数据,并在用户单击提交按钮后将其显示在屏幕上。

谁能给我一个代码示例,因为我似乎无法让它工作?

我正在使用下一张自适应卡:http://adaptivecards.io/samples/InputForm.html

    {
  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
  "type": "AdaptiveCard",
  "version": "1.0",
  "body": [
    {
      "type": "ColumnSet",
      "columns": [
        {
          "type": "Column",
          "width": 2,
          "items": [
            {
              "type": "TextBlock",
              "text": "Tell us about yourself",
              "weight": "bolder",
              "size": "medium"
            },
            {
              "type": "TextBlock",
              "text": "We just need a few more details to get you booked for the trip of a lifetime!",
              "isSubtle": true,
              "wrap": true
            },
            {
              "type": "TextBlock",
              "text": "Don't worry, we'll never share or sell your information.",
              "isSubtle": true,
              "wrap": true,
              "size": "small"
            },
            {
              "type": "TextBlock",
              "text": "Your name",
              "wrap": true
            },
            {
              "type": "Input.Text",
              "id": "myName",
              "placeholder": "Last, First"
            },
            {
              "type": "TextBlock",
              "text": "Your email",
              "wrap": true
            },
            {
              "type": "Input.Text",
              "id": "myEmail",
              "placeholder": "youremail@example.com",
              "style": "email"
            },
            {
              "type": "TextBlock",
              "text": "Phone Number"
            },
            {
              "type": "Input.Text",
              "id": "myTel",
              "placeholder": "xxx.xxx.xxxx",
              "style": "tel"
            }
          ]
        },
        {
          "type": "Column",
          "width": 1,
          "items": [
            {
              "type": "Image",
              "url": "https://upload.wikimedia.org/wikipedia/commons/b/b2/Diver_Silhouette%2C_Great_Barrier_Reef.jpg",
              "size": "auto"
            }
          ]
        }
      ]
    }
  ],
  "actions": [
    {
      "type": "Action.Submit",
      "title": "Submit"
    }
  ]
}

【问题讨论】:

    标签: node.js bots botframework


    【解决方案1】:

    https://github.com/Microsoft/BotBuilder-Samples/tree/master/Node/cards-AdaptiveCards 有一个关于在 node.js 上使用 AdaptiveCards 的示例。您可以参考了解更多详情。

    使用 Submit 方法时,Bot Framework 将处理提交,您的 bot 将收到一条新消息,其 value 字段填充了作为 JSON 对象的表单数据。

    在这个示例中,它创建了一个函数processSubmitAction 来处理提交消息。

    var bot = new builder.UniversalBot(connector, function (session) {
    
        if (session.message && session.message.value) {
            // A Card's Submit Action obj was received
            processSubmitAction(session, session.message.value);
            return;
        }
    
        // ...
    });
    

    要输出用户输入的值,你可以简单地使用session.send()作为参考:

    function processSubmitAction(session, value) {
        session.send(JSON.stringify(value));
    }
    

    【讨论】:

    • 感谢您的反应,但是当我实施它时,我的代码似乎崩溃了。有什么方法可以联系你吗?
    • @KHaemels,不方便直接联系我,抱歉。但是,您可以在 SO 上打开一个新线程,使用您的问题和代码 sn-p,社区将始终为您提供帮助。
    猜你喜欢
    • 2019-04-08
    • 1970-01-01
    • 2018-04-30
    • 1970-01-01
    • 1970-01-01
    • 2017-09-16
    • 2019-08-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多