2016-09-24 55 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> 
}