2016-12-06 48 views
2

考慮有來自MS BOT &一個動作卡響應它看起來Skype的如下: enter image description here如何在directline api的響應中解釋/察覺按鈕的存在?

當此相似的反應來自於REST API的使用即專線直達的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屬性?唯一的方法是啪答比賽?

有沒有人遇到或知道解決方案,請把一些光在這裏太;)


更新:如果如Skype /網上聊天不同的信道/等。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" 
      } 
     ] 
     } 
    } 
    ] 
+0

是否使用DirectLine v1 .1或v3? –

+0

DirectLine v1.1 –

+0

[Direct Line API - Bot Framework/Hero卡和附件]的可能重複(http://stackoverflow.com/questions/40852909/direct-line-api-bot-framework-hero-cards-and -attachments) –

回答

2

正如評論中所述,您正在使用DirectLine v1.1。不幸的是,v1.1不支持附件/卡,所以沒有理解/解析卡的好方法。

您可能需要考慮轉向支持附件的DirectLine v3

enter image description here

另外,如果你想支持卡,你可能有如圖所示DirectLine樣品中的自定義做一些事情。在那裏,機器人通過ChannelData字段是sending the hero card,客戶端相應地是parsing that。但是,您可能需要添加邏輯來檢測誰正在與機器人通話,因此只有在調用者是DirectLine而不是其他客戶端(如skype)時纔將其作爲ChannelData發送。