从Postman发送消息给Microsoft Bot

Joa*_*ins 7 botframework

我正在尝试向我创建并发布到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
Run Code Online (Sandbox Code Playgroud)

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

{
  "token_type": "Bearer",
  "expires_in": 3599,
  "ext_expires_in": 0,
  "access_token": "eyJ0eXA..."
}
Run Code Online (Sandbox Code Playgroud)

然后我继续以下请求:

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"
}
Run Code Online (Sandbox Code Playgroud)

作为回应,我得到了匹配"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
Run Code Online (Sandbox Code Playgroud)

我收到以下回复:

400 Bad Request

{
  "error": {
    "code": "ServiceError",
    "message": "The conversationId 29... and bot .... doesn't match a known conversation"
  }
}
Run Code Online (Sandbox Code Playgroud)

看起来问题出现在第二个和第三个post方法之间.看起来https://skype.botframework.com/v3/conversations没有与我输入的ID生成与机器人的对话.

因此,当我最终调用bot时:https://skype.botframework.com/v3/conversations/.../activities我总是收到serviceError消息.

Eze*_*dib 7

根据您的评论,您正在尝试创建自定义"频道/客户端"以与机器人交谈.

为此,我建议您查看Direct Line,这似乎是实现您的要求的方法.

我不确定您使用的是哪种语言,因此我将向您发送指向C#和Node的指针.

这些示例将向您展示如何使用Direct Line创建自定义客户端以与您的bot进行交互:

C#

Node.js

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

  • 上面提到的链接无效,返回404。 (3认同)