从Botframework中的自适应卡`Action.Submit`中获取变量

时间:2018-03-02 17:06:08

标签: node.js bots botframework

如何在用户点击按钮时获取值?我有这个示例卡。

{
  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
  "type": "AdaptiveCard",
  "version": "1.0",
  "speak": "<s>Your  meeting about \"Adaptive Card design session\"<break strength='weak'/> is starting at 12:30pm</s><s>Do you want to snooze <break strength='weak'/> or do you want to send a late notification to the attendees?</s>",
  "body": [
    {
      "type": "TextBlock",
      "text": "Adaptive Card design session",
      "size": "large",
      "weight": "bolder"
    },
    {
      "type": "TextBlock",
      "text": "Conf Room 112/3377 (10)",
      "isSubtle":true
    },
    {
      "type": "TextBlock",
      "text": "12:30 PM - 1:30 PM",
      "isSubtle":true,
      "spacing":"none"
    },
    {
      "type": "TextBlock",
      "text": "Snooze for"
    },
    {
      "type": "Input.ChoiceSet",
      "id": "snooze",
      "style":"compact",
      "value": "5",
      "choices": [
        {
          "title": "5 minutes",
          "value": "5",
          "isSelected": true
        },
        {
          "title": "15 minutes",
          "value": "15"
        },
        {
          "title": "30 minutes",
          "value": "30"
        }
      ]
    }
  ],
  "actions": [
    {
      "type": "Action.Submit",
      "title": "Snooze",
      "data": { "x": "snooze" }
    },
    {
      "type": "Action.Submit",
      "title": "I'll be late",
      "data": { "x": "late" }
    }
  ]
}

示例如下:http://adaptivecards.io/samples/CalendarReminder.html

如何在session.message对象中访问它?

1 个答案:

答案 0 :(得分:0)

我明白了。在这种情况下,它是x,所以要回复它将是:

if (session.message && session.message.value) {
    // A Card's Submit Action obj was received
    session.send(session.message.value.x)
}