2017-07-12 46 views
0

如何確定消息來自哪個平臺?如何確定API中的平臺類型.AI

我想支持像Telegram和Facebook Messenger這樣的不同平臺,當我的webhook收到消息時,我想根據平臺回覆消息的形式。

例如,如果消息來自電報,我想返回一條文本消息,但是如果消息來自使者,我想返回一張卡。

回答

0

你有財產sourceoriginalRequest對象,見履行docs here

{ 
"lang": "en", 
"status": { 
    "errorType": "success", 
    "code": 200 
}, 
"timestamp": "2017-02-09T16:06:01.908Z", 
"sessionId": "1486656220806", 
"result": { 
    "parameters": { 
     "city": "Rome", 
     "name": "Ana" 
    }, 
    "contexts": [], 
    "resolvedQuery": "my name is Ana and I live in Rome", 
    "source": "agent", 
    "score": 1.0, 
    "speech": "", 
    "fulfillment": { 
     "messages": [ 
      { 
       "speech": "Hi Ana! Nice to meet you!", 
       "type": 0 
      } 
     ], 
     "speech": "Hi Ana! Nice to meet you!" 
    }, 
    "actionIncomplete": false, 
    "action": "greetings", 
    "metadata": { 
     "intentId": "9f41ef7c-82fa-42a7-9a30-49a93e2c14d0", 
     "webhookForSlotFillingUsed": "false", 
     "intentName": "greetings", 
     "webhookUsed": "true" 
    } 
}, 
"id": "ab30d214-f4bb-4cdd-ae36-31caac7a6693", 
"originalRequest": { 
    "source": "google", 
    "data": { 
     "inputs": [ 
      { 
       "raw_inputs": [ 
        { 
         "query": "my name is Ana and I live in Rome", 
         "input_type": 2 
        } 
       ], 
       "intent": "assistant.intent.action.TEXT", 
       "arguments": [ 
        { 
         "text_value": "my name is Ana and I live in Rome", 
         "raw_text": "my name is Ana and I live in Rome", 
         "name": "text" 
        } 
       ] 
      } 
     ], 
     "user": { 
      "user_id": "PuQndWs1OMjUYwVJMYqwJv0/KT8satJHAUQGiGPDQ7A=" 
     }, 
     "conversation": { 
      "conversation_id": "1486656220806", 
      "type": 2, 
      "conversation_token": "[]" 
     } 
    } 
} } 
+0

這個JSON對象對於每個平臺都是一樣的嗎? – Maysara

+0

結構相同,但屬性因平臺而異。快樂的編碼。 –