MS Bot,直线 API,无法发送 activity,如何解决?
MS Bot, Direct line API, cannot send an activity, how to fix it?
我一直在尝试在应用程序中设置 MS Bot。到目前为止,我做了以下。
为 Bot 设置一个 REST 端点,该连接器会监听它。
app.post("/botapi/messages", connector);
获取APP_ID和APP_PASSWORD,模拟器成功连接如下,
http://localhost:4000/botapi/messages
APP_ID
APP_PASSWORD
这是成功的,机器人如期回复。
尝试使用直线 API 与机器人对话。成功开始对话。其中一则回复如下
{
"conversationId": "3JYZyAn5VYB3HNcO3tcgtn",
token: ....
.....
}
我使用 "node-fetch" 包发出 POST 请求,如文档所述。
但是,我无法使用直线 API 发送 activity,收到
internal server error 500
文档说 POST 请求应该像下面这样。
POST
https://directline.botframework.com/v3/directline/conversations
Authorization: Bearer my_secret
这非常适合开始对话,但不适用于发送活动。
我发送的activity是:
{
"type": "message",
"from": {
"id": "user1"
},
"text": "hello Bot, say something"
}
我认为 "id" 不重要,所以这就是我发布到
的内容
https://directline.botframework.com/v3/directline/conversations/{conversationId}/activities
我使用了开始对话时收到的 conversationId。
我四处搜索,但没有找到我的问题的答案。
此外,我的问题很少,也许他们的回答对我有帮助。
Q1:url“https://directline.botframework.com/v3/directline/" is the same for everybody using Direct Line API? When I replace it with the endpoint of the bot, "http://localhost:3000/botapi/messages/conversations”,我什至无法开始对话,没有任何作用。
Q2:直线API如何运作?我向 API 发出 POST 和我的秘密,那么 API 如何找到我的机器人? Bot 和 API 是如何通信的?我在这里遗漏了什么吗?
Q3:当我发出 POST 发送一个 activity 时,我遵循了文档。
在授权中,我尝试了我的秘密和开始对话时获得的令牌,但都没有用。我相信两者都应该有效。我错了吗?
问题 4:我需要用 Bot Connector Service 做些什么吗?我读了这篇文章,但我不知道它的目的是什么。我错了吗?
那么,我在这里缺少什么?如何发送活动?
注意:我的机器人没有部署到 azuri 或 aws,它只在我的 Mac 上。
但是,如文档所述,我得到了 APP_ID、APP_PASSWORD 和 DirectLine 的 SECRET。
documentation 指定这是通过直线向机器人发送 activity(消息)的端点:
https://directline.botframework.com/v3/directline/conversations/{conversationId}/activities
在此 URI 中,{conversationId}
是您在 started the conversation 时在响应 body 中收到的对话 ID(conversationId
值)。并且请求的 body 应指定有关您发送的 activity 的信息,例如:
{
"type": "message",
"from": {
"id": "user1"
},
"text": "hello"
}
最后,回答您的问题:
Q1:所有直线 API 请求的基本 URI is the same。
Q2:您在请求的 Authorization
header 中指定的 Direct Line 机密或令牌用于识别应将请求定向到的机器人
Q3:是的,您应该能够指定您在 Start Conversation 响应中收到的秘密或 token
值 发送 Activity 请求的 Authorization
header。但是请注意,您在 开始对话 响应 中收到的令牌只能用于与该特定对话.
交互
问题 4:您链接到的文章与使用直线没有直接关系 API。 (但正如@EzequielJadib 在他的评论中提到的,您确实需要为您的机器人启用 Direct Line 通道。)
我一直在尝试在应用程序中设置 MS Bot。到目前为止,我做了以下。
为 Bot 设置一个 REST 端点,该连接器会监听它。
app.post("/botapi/messages", connector);
获取APP_ID和APP_PASSWORD,模拟器成功连接如下,
http://localhost:4000/botapi/messages APP_ID APP_PASSWORD
这是成功的,机器人如期回复。
尝试使用直线 API 与机器人对话。成功开始对话。其中一则回复如下
{ "conversationId": "3JYZyAn5VYB3HNcO3tcgtn", token: .... ..... }
我使用 "node-fetch" 包发出 POST 请求,如文档所述。
但是,我无法使用直线 API 发送 activity,收到
internal server error 500
文档说 POST 请求应该像下面这样。
POST
https://directline.botframework.com/v3/directline/conversations
Authorization: Bearer my_secret
这非常适合开始对话,但不适用于发送活动。
我发送的activity是:
{
"type": "message",
"from": {
"id": "user1"
},
"text": "hello Bot, say something"
}
我认为 "id" 不重要,所以这就是我发布到
的内容 https://directline.botframework.com/v3/directline/conversations/{conversationId}/activities
我使用了开始对话时收到的 conversationId。 我四处搜索,但没有找到我的问题的答案。 此外,我的问题很少,也许他们的回答对我有帮助。
Q1:url“https://directline.botframework.com/v3/directline/" is the same for everybody using Direct Line API? When I replace it with the endpoint of the bot, "http://localhost:3000/botapi/messages/conversations”,我什至无法开始对话,没有任何作用。
Q2:直线API如何运作?我向 API 发出 POST 和我的秘密,那么 API 如何找到我的机器人? Bot 和 API 是如何通信的?我在这里遗漏了什么吗?
Q3:当我发出 POST 发送一个 activity 时,我遵循了文档。 在授权中,我尝试了我的秘密和开始对话时获得的令牌,但都没有用。我相信两者都应该有效。我错了吗?
问题 4:我需要用 Bot Connector Service 做些什么吗?我读了这篇文章,但我不知道它的目的是什么。我错了吗?
那么,我在这里缺少什么?如何发送活动?
注意:我的机器人没有部署到 azuri 或 aws,它只在我的 Mac 上。 但是,如文档所述,我得到了 APP_ID、APP_PASSWORD 和 DirectLine 的 SECRET。
documentation 指定这是通过直线向机器人发送 activity(消息)的端点:
https://directline.botframework.com/v3/directline/conversations/{conversationId}/activities
在此 URI 中,{conversationId}
是您在 started the conversation 时在响应 body 中收到的对话 ID(conversationId
值)。并且请求的 body 应指定有关您发送的 activity 的信息,例如:
{
"type": "message",
"from": {
"id": "user1"
},
"text": "hello"
}
最后,回答您的问题:
Q1:所有直线 API 请求的基本 URI is the same。
Q2:您在请求的
Authorization
header 中指定的 Direct Line 机密或令牌用于识别应将请求定向到的机器人Q3:是的,您应该能够指定您在 Start Conversation 响应中收到的秘密或
交互token
值 发送 Activity 请求的Authorization
header。但是请注意,您在 开始对话 响应 中收到的令牌只能用于与该特定对话.问题 4:您链接到的文章与使用直线没有直接关系 API。 (但正如@EzequielJadib 在他的评论中提到的,您确实需要为您的机器人启用 Direct Line 通道。)