我一直在尝试在应用程序中设置 MS Bot。到目前为止,我做了以下。
app.post("/botapi/messages", connector);
http://localhost:4000/botapi/messages
APP_ID
APP_PASSWORD
这是成功的,机器人按预期回复。
{
"conversationId": "3JYZyAn5VYB3HNcO3tcgtn",
token: ....
.....
}
正如文档所说,我使用“node-fetch”包来发出 POST 请求。
但是,我无法使用 Direct Line API 发送事件,已收到
internal server error 500
文档说 POST 请求应该如下所示。
POST
https://directline.botframework.com/v3/directline/conversations
Authorization: Bearer my_secret
这非常适合开始对话,但不适用于发送事件。
我发送的事件是:
{
"type": "message",
"from": {
"id": "user1"
},
"text": "hello Bot, say something"
}
我不认为“id”很重要,所以这就是我发布的内容
https://directline.botframework.com/v3/directline/conversations/{conversationId}/activities
我使用了从开始对话时收到的对话 ID。
我用谷歌搜索,但没有找到我的问题的答案。
此外,我的问题很少,也许他们的回答会对我有所帮助。
Q1:使用 Direct Line API 的每个人的 url "https://directline.botframework.com/v3/directline/ "都一样吗?当我用机器人的端点“http://localhost:3000/botapi/messages/conversations”替换它时,我什至无法开始对话,没有任何效果。
Q2:Direct Line API 是如何工作的?我向 API 发出了带有我的 secret 的 POST,然后 API 如何找到我的机器人? Bot 和 API 如何通信?我在这里错过了什么吗?
Q3:当我发出 POST 以发送事件时,我遵循了文档。
在授权中,我尝试了我的 secret 和从开始对话中获得的 token ,两者都不起作用。我相信两者都应该有效。我错了吗?
Q4:我需要对Bot Connector Service做些什么吗? ?我读了这篇文章,但我不知道它是为了什么。我错了吗?
那么,我在这里缺少什么?如何发送事件?
备注 :我的机器人没有部署到 azuri 或 aws,它只在我的 Mac 上。
但是,如文档所述,我获得了 DirectLine 的 APP_ID、APP_PASSWORD 和 SECRET。
最佳答案
documentation指定这是通过 Direct Line 向机器人发送事件(消息)的端点:
https://directline.botframework.com/v3/directline/conversations/{conversationId}/activities
在此 URI 中,
{conversationId}
是您在 started the conversation 时在响应正文中收到的对话 ID(conversationId
值) .并且请求的正文应指定有关您发送的事件的信息,例如:{
"type": "message",
"from": {
"id": "user1"
},
"text": "hello"
}
最后,回答你的问题:
Authorization
中指定的 Direct Line secret 或 token 请求的 header 用于标识应将请求定向到 token
您在 中收到的值开始对话 Authorization
中的响应 的标题发送事件 要求。但是请注意,您在 中收到的 token 开始对话 response 只能用于与该特定对话进行交互。 关于botframework - MS Bot,Direct line API,无法发送事件,如何解决?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46684849/