我在Chatbot中发送消息时遇到问题。我采取了以下步骤来创建Chatbot。
当我输入并发送消息(使用Web客户端)时,我在浏览器控制台上出现以下错误(代码错误502)。
POST https://directline.botframework.com/v3/directline/conversations/7IqYgcAzBp4EObQvFzK2fF/activities 502(Bad Gateway)
Directline和Web聊天频道日志将错误消息显示为
将此消息发送到您的机器人时出错:HTTP状态代码禁止
以下是请求标头详细信息。
下面是Bot config(.bot)文件的详细信息。注意,如果这是问题,应用程序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"
}
我尝试在不同的订阅上重新创建所有这些但我得到相同的错误。我有另一个机器人启动并运行,如果我在同一个Web客户端使用该机器人的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
}
请注意从bot文件AppId和AppPassword创建的凭据提供程序。这个appid和apppassword可以从App Settings中检索,例如:
options.CredentialProvider = new SimpleCredentialProvider(Configuration[MicrosoftAppCredentials.MicrosoftAppIdKey],
Configuration[MicrosoftAppCredentials.MicrosoftAppPasswordKey]);
注意:您的端点也应该是正确的:
"endpoint": "https://<my_app_name>.azurewebsites.net/api/messages",