从输入表单自适应卡

时间:2017-11-09 14:56:01

标签: node.js bots botframework

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

有人可以给我一个代码示例,因为我似乎无法让它工作吗?

我正在使用下一张自适应卡: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"
    }
  ]
}

1 个答案:

答案 0 :(得分:1)

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

  

使用Submit方法时,Bot Framework将处理提交,并且您的机器人将收到一条新消息,其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));
}