从 Postman 向 Microsoft Bot 发送消息

Send message from Postman to Microsoft Bot

我正在尝试向我创建并发布到 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:"i don't have this id so i pass some string": { "id": "i don't have this id so i pass some string" }

然后我继续执行以下 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 的机器人的对话。

因此,当我对机器人进行最后一次调用时:https://skype.botframework.com/v3/conversations/.../activities 我总是收到 serviceError 消息。

根据您的评论,您正在尝试创建自定义 "channel/client" 来与机器人对话。

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

我不确定你使用的是哪种语言,所以我会向你发送指向 C# 和 Node 的指针。

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

C#

Node.js

所有示例都使用控制台应用作为 "custom channel"。

因为您要让应用程序与您的机器人对话并且很可能会使用 DirectLine after you and Ezequiel chatted, I created a series of screencaps on connecting to the DirectLine endpoint through Potsman. I'm going to assume that you know how to use environmental and global variables in Postman, here are Postman's documentation for other people's benefit. Also, the DirectLine v3.0 docs are here

下面是您将从中请求令牌的直线端点的捕获,{{DLsecret}} 的内容看起来像这样,Bearer <your-dl-secret>

以下是您在有效调用中收到的响应正文示例:

您可能已经注意到我有一些测试结果,在下面的屏幕显示中有五个(对四个)测试,因为我添加了验证 conversationId 在环境变量中设置:

这是发送的第二个查询,其中包含一条实际消息:

这是包含消息的请求正文:

这是响应正文: