botframework – 从Postman发送消息给Microsoft Bot

前端之家收集整理的这篇文章主要介绍了botframework – 从Postman发送消息给Microsoft Bot前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试向我创建并发布到azure服务的机器人发送消息,以便机器人可以开始向其某些用户发送消息.

我首先尝试在Postman上发出请求,然后我可以为该交互构建一个控制器.

我正在做以下要求:

  1. POST https://login.microsoftonline.com/botframework.com/oauth2/v2.0/token
  2. Content-Type: application/x-www-form-urlencoded
  3. Body:
  4. grant_type:client_credentials
  5. client_id: my_ms_app_id
  6. client_secret: my_ms_app_secret
  7. scope: https://api.botframework.com/.default

从此,我得到了承载授权的回应:

  1. {
  2. "token_type": "Bearer","expires_in": 3599,"ext_expires_in": 0,"access_token": "eyJ0eXA..."
  3. }

然后我继续以下请求:

  1. POST https://skype.botframework.com/v3/conversations
  2. Content-Type: application/json
  3. Authorization: Bearer eyJ0eXAi....
  4.  
  5. {
  6. "bot": {
  7. "id": "i don't have this id so i pass some string","name": "connector controller"
  8. },"isGroup": false,"members": [
  9. {
  10. "id": "28:...",//ID of the bot I want to send the message to
  11. "name": "Sp Bot"//Name of the bot I want to talk to
  12. },{
  13. "id": "i don't have this id so i pass some string","name": "connector controller"
  14. }
  15. ],"topicName": "News Alert"
  16. }

作为回应,我得到了匹配“id”的会话ID:“我没有这个id所以我传递了一些字符串”:
{
“id”:“我没有这个id所以我传了一些字符串”
}

然后我继续执行以下POST请求:

  1. POST. https://skype.botframework.com/v3/conversations/i don't have this id so i pass some string/activities
  2. Authorization: Bearer eyJ0...
  3. Content-Type:application/json

我收到以下回复

  1. 400 Bad Request
  2.  
  3. {
  4. "error": {
  5. "code": "ServiceError","message": "The conversationId 29... and bot .... doesn't match a known conversation"
  6. }
  7. }

看起来问题出现在第二个和第三个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

所有示例都使用控制台应用程序作为“自定义渠道”.

猜你在找的Windows相关文章