Retrieve data from input form adaptive card

2019-08-17 08:36发布

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?

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"
    }
  ]
}

1条回答
劫难
2楼-- · 2019-08-17 08:59

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.

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.

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;
    }

    // ...
});

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

function processSubmitAction(session, value) {
    session.send(JSON.stringify(value));
}
查看更多
登录 后发表回答