Directline/Web chat channel error: HTTP status code Forbidden

Directline/Web chat channel error: HTTP status code Forbidden

我在聊天机器人中发送消息时遇到问题。我已按照以下步骤创建聊天机器人。

当我键入并发送消息(使用 Web 客户端)时,我在浏览器控制台上收到以下错误(代码错误 502)。

POST https://directline.botframework.com/v3/directline/conversations/7IqYgcAzBp4EObQvFzK2fF/activities 502 (Bad Gateway)

Directline 和 Web 聊天频道日志将错误消息显示为

There was an error sending this message to your bot: HTTP status code Forbidden

下面是请求header的详细信息。

以下是 Bot 配置 (.bot) 文件的详细信息。请注意,App ID 和密码为空,如果这是问题所在?

{
  "name": "Chatbot",
  "services": [
    {
      "type": "endpoint",
      "name": "development",
      "endpoint": "http://localhost:3978/api/messages",
      "appId": "",
      "appPassword": "",
      "id": "1"
    },
    {
      "type": "endpoint",
      "name": "production",
      "endpoint": "https://<my_app_name>.azurewebsites.net/api/messages",
      "appId": "<YOUR APP ID>",
      "appPassword": "<YOUR APP PASSWORD>",
      "id": "2"
    }
  ],
  "padlock": "",
  "version": "2.0"
}

我在不同的订阅上尝试了 re-creating 所有这些,但我得到了同样的错误。我有另一个启动的 bot 运行,如果我在同一个 Web 客户端中使用该 bot 的 Directline 通道密钥,它工作正常。

我在网上找了一些参考资料,但没有帮助。如果我遗漏了什么,有人可以帮我吗?让我知道是否可以提供更多详细信息。

如果您的机器人正在使用 integration 库,则使用 .bot 文件的启动代码通常包含以下内容(除其他外):

var secretKey = Configuration.GetSection("botFileSecret")?.Value;
var botFilePath = Configuration.GetSection("botFilePath")?.Value;

BotConfiguration botConfig = BotConfiguration.Load(botFilePath, secretKey);

var environment = _isProduction ? "production" : "development";
var service = botConfig.Services.FirstOrDefault(s => s.Type == "endpoint" && s.Name == environment);

services.AddBot<BasicBot>(options =>
{
    options.CredentialProvider = new SimpleCredentialProvider(endpointService.AppId, endpointService.AppPassword);

    //other code
}

注意从机器人文件 AppId 和 AppPassword 创建的凭据提供程序。这个 appid 和 apppassword 可以从应用程序设置中检索,例如:

options.CredentialProvider =  new SimpleCredentialProvider(Configuration[MicrosoftAppCredentials.MicrosoftAppIdKey],
                                                      Configuration[MicrosoftAppCredentials.MicrosoftAppPasswordKey]);

注意:你的端点也应该是正确的:

"endpoint": "https://<my_app_name>.azurewebsites.net/api/messages",