我想从c#应用程序向我使用Microsoft Bot Framework创建的Facebook bot发送一条简单的消息
使用Skype这是完美的,但是当我尝试使用Messenger僵尸程序时,我收到以下请求错误:
{
"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 :(得分: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>
}