如何在 Microsoft Bot 服务中使用直线 post 进行网络聊天?

How to post to a webchat using direct line in Microsoft Bot Service?

在 Azure 门户中的测试网络聊天中,我通过从 session.message.address.conversation.id.

获取对话 ID 让机器人回复我对话 ID

然后我希望使用此处描述的方法查看此对话 ID 的活动:

https://docs.microsoft.com/en-us/bot-framework/rest-api/bot-framework-rest-direct-line-3-0-send-activity

(POST https://directline.botframework.com/v3/directline/conversations/abc123/activities )

但是,我收到以下错误:

{
"error": {
    "code": "BadArgument",
    "message": "Unknown conversation"
    }
}

我也试过:

POST https://webchat.botframework.com/v3/directline/conversations/9323c31ab1ba42328edc9191621f9c9c/activities

关于如何使用直接线路进行网络聊天的 post/view 活动有什么帮助吗?

谢谢!

解释您的问题

我无法通过 POST 对话重现您的问题。实际上,我只能通过以下步骤重现您的问题:

生成直线令牌 => 利用响应 conversationIdtoken 直接调用 Retrieve activities with HTTP GET 并使用:

GET https://directline.botframework.com/v3/directline/conversations/abc123/activities
Authorization: Bearer token

正确的步骤是: 生成令牌 => POST 开始对话 => GETRetrieve activities with HTTP GET.

根据您的要求 我不认为我们可以在转换之外中断,如 Generate a Direct Line token

的描述

To generate a Direct Line token that can be used to access a single conversation.

因此您从其他任何地方请求的令牌无法请求网络聊天中的活动。

解决方法

您可以利用 BotFramework-WebChat 快速构建网站机器人测试环境。并在您自己的服务器中生成用于机器人客户端身份验证的令牌。然后您可以使用生成的令牌和 conversationId 来请求 bot 和这个 bot 客户端网站之间的所有活动。