botframework - 我如何解释/感知 directline api 响应中按钮的存在?

标签 botframework direct-line-botframework

考虑有来自 MS 机器人的操作卡响应,它在 Skype 中如下所示: enter image description here

当 REST API 中出现类似的响应时,即使用 Direct Line API。以下是JSON响应的相关部分。

{
  "id": "1t90Ym3PEry|000000000000000014",
  "conversationId": "1t90Ym3PEry",
  "created": "2016-12-06T09:34:55.6280699Z",
  "from": "rich3cards",
  "images": [
    "https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/Seattlenighttimequeenanne.jpg/320px-Seattlenighttimequeenanne.jpg"
  ],
  "attachments": [],
  "eTag": "W/\"datetime'2016-12-06T09%3A34%3A54.94083Z'\""
},
{
  "id": "1t90Ym3PEry|000000000000000014",
  "conversationId": "1t90Ym3PEry",
  "created": "2016-12-06T09:34:55.6280699Z",
  "from": "rich3cards",
  "text": "Hero Card\n\nSpace Needle\n\nThe <b>Space Needle</b> is an observation tower in Seattle, Washington, a landmark of the Pacific Northwest, and an icon of Seattle.\n\n(Current Weather) action?weather=Seattle, WA",
  "images": [],
  "attachments": [],
  "eTag": "W/\"datetime'2016-12-06T09%3A34%3A54.94083Z'\""
}

现在的问题是我们如何解析这个 json 来获取按钮数据 [ (Current Weather) action?weather=Seattle, WA" ]出text属性?唯一的方法是模式匹配吗?

有谁遇到过或知道解决方案,也请在这里放一些信息;)


更新:如果它是不同的 channel ,如 skype/webchat/etc.. JSON 响应看起来非常适合使用,以下是示例 JSON。

{
  "type": "message",
  "id": "5AdoK89rtSc|000000000000000018",
  "timestamp": "2016-12-06T09:53:20.4777291Z",
  "channelId": "webchat",
  "from": {
    "id": "rich3cards",
    "name": "RichCards"
  },
  "conversation": {
    "id": "5AdoK89rtSc"
  },
  "attachments": [
    {
      "contentType": "application/vnd.microsoft.card.hero",
      "content": {
        "title": "Hero Card",
        "subtitle": "Space Needle",
        "text": "The <b>Space Needle</b> is an observation tower in Seattle, Washington, a landmark of the Pacific Northwest, and an icon of Seattle.",
        "images": [
          {
            "url": "https://upload.wikimedia.org/wikipedia/commons/thumb/7/7c/Seattlenighttimequeenanne.jpg/320px-Seattlenighttimequeenanne.jpg"
          }
        ],
        "buttons": [
          {
            "type": "postBack",
            "value": "action?weather=Seattle, WA",
            "title": "Current Weather"
          }
        ]
      }
    }
  ]

最佳答案

正如评论中提到的,您正在使用 DirectLine v1.1。不幸的是,v1.1 不支持附件/卡片,因此没有一个好的方法来理解/解析卡片。

您可能需要考虑转移到 DirectLine v3它完全支持附件。

enter image description here

或者,如果您想支持卡片,您可能需要执行一些自定义操作,如 DirectLine 中所示。样本。在那里,机器人是 sending the hero card通过ChannelData字段,客户端是parsing that因此。但是,您可能需要添加逻辑来检测谁在与机器人交谈,以便仅当调用者是 DirectLine 而不是其他客户端(例如 Skype)时才将卡片作为 ChannelData 发送

关于botframework - 我如何解释/感知 directline api 响应中按钮的存在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40992292/

相关文章:

botframework - 为 Azure Bot 创建 Facebook Messenger channel 时出错

javascript - 如何在机器人回复建议操作时隐藏/显示发送箱

azure - 如何发布 Azure 机器人

azure - 使用 botframework 在聊天机器人中发送图片

azure - 无法在 Slack 中向机器人发送 DM。机器人是使用 azure botframework 创建的,并使用了 channel 集成

azure - 是否可以通过 HTTP 请求 header 确认机器人的身份?

azure - 新的 ms botbuilder 直线语音是否适合调用中心场景?

c# - Microsoft.Azure.KeyVault.Core 无法使用 NETStandard20 进行恢复

node.js - Bot 框架 Directline - 使用 node.js 更改 Bot 名称运行时

c# - 如何将实时音频流传递到 Direct Line Speech 端点?