2016-09-24 57 views
1


我想從一個c#應用程序發送一個簡單的消息到我的Facebook機器人使用Microsoft Bot Framework創建。
與Skype的作品perfeclty,但是當我嘗試使者BOT我得到以下請求錯誤:
無法通過REST API發送消息給Facebook機器人Bot Botworkwork

{ 
    "message": "The 'form' field is unrecognized" 
} 

我使用下列活動來發送消息:

{ 
"type": "message", 
"id": "...", 
"timestamp": "2016-09-24T02:47:03.8956722Z", 
"serviceUrl": "https://facebook.botframework.com", 
"channelId": "facebook", 
"from": { 
    "id": "...", 
    "name": "..." 
}, 
"conversation": { 
    "id": "..." 
}, 
"recipient": { 
    "id": "...", 
    "name": "..." 
}, 
"text": "Hy, from remote!", 
"channelData": { 
    "sender": { 
    "id": "..." 
}, 
"recipient": { 
    "id": "..." 
}, 
"timestamp": 1474685223681, 
"message": { 
    "mid": "...", 
    "seq": 35, 
    "text": "Testtest" 
} 

} }


所以'from'字段實際上就在這裏。
當我刪除'from'字段時,請求消息說它是必需的,所以它以某種方式識別該字段。也許它只是格式錯誤的方式。
那麼我怎樣才能使這個工作?

+0

當然你沒有一個錯字:

的數據可以從這樣的消息被髮送到機器人中提取?上面的消息是說「form」字段不被識別,而不是「from」字段。 – Lars

回答

2

嘗試使用更少的參數來構建消息。
對於Facebook,由於某些原因您需要使用from字段,但您不必提供所有其他參數。

請嘗試以下要求:

{ 
    "type": "message", 
    "textFormat": "plain", 
    "text": "Hello messenger!", 
    "from": 
    { 
    "id": "your-id-from-recipient-id-in-the-message-received", 
    "name": "your-name-from-recipient-name-in-the-message-received" 
    } 
} 

它使用完全相同的ID,當用戶發送的消息,您收到的名字是很重要的。

{ 
    "type": "message", 
    "id": "<snip>", 
    "timestamp": "2017-01-06T14:09:36.8882093Z", 
    "serviceUrl": "https://facebook.botframework.com", 
    "channelId": "facebook", 
    "from": { 
    "id": "<snip>", 
    "name": "<snip>" 
    }, 
    "conversation": { 
    "isGroup": false, 
    "id": "<snip>" 
    }, 
    "recipient": { 
    "id": "your-id-from-recipient-id-in-the-message-received", 
    "name": "your-name-from-recipient-name-in-the-message-received" 
    }, 
    <snip> 
}