考虑有来自 MS 机器人的操作卡响应,它在 Skype 中如下所示:
当 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它完全支持附件。
或者,如果您想支持卡片,您可能需要执行一些自定义操作,如 DirectLine 中所示。样本。在那里,机器人是 sending the hero card通过ChannelData字段,客户端是parsing that因此。但是,您可能需要添加逻辑来检测谁在与机器人交谈,以便仅当调用者是 DirectLine 而不是其他客户端(例如 Skype)时才将卡片作为 ChannelData 发送
关于botframework - 我如何解释/感知 directline api 响应中按钮的存在?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40992292/