首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从输入式自适应卡中检索数据

从输入式自适应卡中检索数据
EN

Stack Overflow用户
提问于 2017-11-09 14:56:01
回答 1查看 2.1K关注 0票数 0

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

有人能给我举个代码的例子吗,因为我似乎无法让它工作?

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

代码语言:javascript
复制
    {
  "$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"
    }
  ]
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-11-10 07:34:59

关于在AdaptiveCards上使用node.js的示例有https://github.com/Microsoft/BotBuilder-Samples/tree/master/Node/cards-AdaptiveCards。你可以参考更多细节。

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

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

代码语言:javascript
复制
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()作为参考:

代码语言:javascript
复制
function processSubmitAction(session, value) {
    session.send(JSON.stringify(value));
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/47204965

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档