无法通过 REST Api Botframework 向 Facebook 机器人发送消息

Can't send message to Facebook bot via REST Api Botframework


我想从 c# 应用程序向我使用 Microsoft Bot Framework 创建的 Facebook 机器人发送一条简单消息。
使用 Skype 时效果很好,但是当我尝试使用 Messenger 机器人时,我收到以下请求错误:

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

我正在使用以下 activity 发送消息:

{
"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' 字段时,请求消息说它是必需的,所以它以某种方式识别了该字段。也许它只是格式错误。
那么我怎样才能让它发挥作用呢?

尝试使用较少的参数构建消息。
对于 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>
}