从输入表单自适应卡中检索数据 [英] Retrieve data from input form adaptive card

查看:110
本文介绍了从输入表单自适应卡中检索数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using an input form as an adaptive card in my bot framework. Now i want to retrieve the data that the user gave in the form and show it on the screen after the user click the submit button.

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

Can someone give me an example of the code, because i can't seem to get it work?

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

I'm using next adaptive card: 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"
    }
  ]
}

推荐答案

There is a sample about using AdaptiveCards on node.js at https://github.com/Microsoft/BotBuilder-Samples/tree/master/Node/cards-AdaptiveCards. You can refer for more details.

使用Submit方法时,Bot框架将处理提交,并且您的机器人将收到一条新消息,其value字段将表单数据作为JSON对象填充.

When using the Submit method, the Bot Framework will handle the submission and your bot will receive a new message with its value field filled with the form data as a JSON object.

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

In this sample, it create a function processSubmitAction to handle the submission message.

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()作为参考:

To output the user input value, you can simply use session.send() for reference:

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

这篇关于从输入表单自适应卡中检索数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆