我正在尝试向我创建并发布到azure服务的机器人发送消息,以便机器人可以开始向其某些用户发送消息.
我首先尝试在Postman上发出请求,然后我可以为该交互构建一个控制器.
我正在做以下要求:
POST https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token Content-Type: application/x-www-form-urlencoded Body: grant_type:client_credentials client_id: my_ms_app_id client_secret: my_ms_app_secret scope: https://api.botframework.com/.default
从此,我得到了承载授权的回应:
{ "token_type": "Bearer","expires_in": 3599,"ext_expires_in": 0,"access_token": "eyJ0eXA..." }
然后我继续以下请求:
POST https://skype.botframework.com/v3/conversations Content-Type: application/json Authorization: Bearer eyJ0eXAi.... { "bot": { "id": "i don't have this id so i pass some string","name": "connector controller" },"isGroup": false,"members": [ { "id": "28:...",//ID of the bot I want to send the message to "name": "Sp Bot"//Name of the bot I want to talk to },{ "id": "i don't have this id so i pass some string","name": "connector controller" } ],"topicName": "News Alert" }
作为回应,我得到了匹配“id”的会话ID:“我没有这个id所以我传递了一些字符串”:
{
“id”:“我没有这个id所以我传了一些字符串”
}
然后我继续执行以下POST请求:
POST. https://skype.botframework.com/v3/conversations/i don't have this id so i pass some string/activities Authorization: Bearer eyJ0... Content-Type:application/json
我收到以下回复:
400 Bad Request { "error": { "code": "ServiceError","message": "The conversationId 29... and bot .... doesn't match a known conversation" } }
看起来问题出现在第二个和第三个post方法之间.看起来https://skype.botframework.com/v3/conversations没有与我输入的ID生成与机器人的对话.
因此,当我最终调用bot:https://skype.botframework.com/v3/conversations/…/activities时,我总是收到serviceError消息.
根据您的评论,您正在尝试创建自定义“频道/客户端”以与机器人交谈.
为此,我建议您查看Direct Line,这似乎是实现您的要求的方法.
我不确定您使用的是哪种语言,因此我将向您发送指向C#和Node的指针.
这些示例将向您展示如何使用Direct Line创建自定义客户端以与您的bot进行交互:
C#
> Basic Direct Line sample
> Direct Line sample using Web Sockets
Node.js的
> Basic Direct Line sample
> Direct Line sample using Web Sockets
所有示例都使用控制台应用程序作为“自定义渠道”.