我正在使用 REST API 创建一个机器人。确实,我想从我的机器人向我发送一条消息,如下所示
我从“认证”开始
要求:
curl -k -X POST https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token -d "grant_type=client_credentials&client_id={app_id}&client_secret={app_password}&scope=https://graph.microsoft.com/.default"
回复:
{
"token_type": "Bearer",
"expires_in": 3599,
"ext_expires_in": 0,
"access_token": "<access_token>"
}
接下来,我开始新的对话
要求:
POST https://skype.botframework.com/v3/conversations
Authorization: Bearer <access_token>
Content-Type: application/json
{
"bot": {
"id": "standupalice",
"name": "Standup Alice"
},
"isGroup": false,
"members": [
{
"id": "<my bot id>",
"name": "Standup Alice"
},
{
"id": "<my user id>",
"name": "Bao"
}
],
"topicName": "News Alert"
}
注意:并且是从 Skype 应用程序发送到 Standup Alice 机器人的回调消息中获得的。
回复:
{
"id": "<conversation id>"
}
这很奇怪,因为对话 ID 与 . 好吧,现在我编写一条消息发送给我,如下请求:
POST https://skype.botframework.com/v3/conversations/<conversation id>/activities
Authorization: Bearer <access_token>
Content-Type: application/json
{
"type": "message",
"from": {
"id": "<my bot id>",
"name": "Standup Alice"
},
"conversation": {
"id": "<conversation id>",
"name": "News Alert"
},
"recipient": {
"id": "<my user id>",
"name": "Bao"
},
"channelId": "skype",
"text": "My bot's reply"
}
响应(http 错误 400 - 错误请求):
{
"error": {
"code": "ServiceError",
"message": "The conversationId <conversation id>and bot <my bot id> doesn't match a known conversation"
}
}
您知道我的请求和参数有什么问题吗?
注意 1:我尝试按照https://docs.botframework.com/en-us/core-concepts/overview/#navtitle中的描述向 https:// api .botframework.com/v3/conversations 发起请求,但始终收到 http 错误 404 - 找不到资源。
注意 2:我刚刚尝试了与 webchat 相同的方法,它工作正常,但 MS Teams 不起作用(http 错误 500 - 内部服务器错误)