在 Azure 上部署后 ChatBot 不工作 - 内部服务器错误
ChatBot not working after Deploying on Azure - Internal server error
我已经使用 LUIS 和 QnA Maker 部署了一个聊天机器人。当我在 Emulator 上 运行 它在本地完美运行。它在聊天开始时加载自适应卡片,我从 LUIS 得到正确回复。
然而,当我在 Azure 上部署机器人并在 Web 聊天中对其进行测试时,出现以下错误:
There was an error sending this message to your bot: HTTP status code InternalServerError
这是我的 web.config 的样子:
<configuration>
<appSettings>
<!-- update these with your BotId, Microsoft App Id and your Microsoft App Password-->
<add key="BotId" value="BotLuis" />
<add key="MicrosoftAppId" value="9f9564ef-d627-450f-b943-98b7338c0f31" />
<add key="MicrosoftAppPassword" value="myapp-password" />
</appSettings>
我从我在 Azure 上创建的网络机器人的应用程序设置中获取 AppID 和 AppPassword 的值。我知道它们是正确的,因为我使用这些值使用模拟器在本地进行设置。
我将代码从 github 部署到 Azure。我的机器人在 azure 网络聊天中加载得很好(自适应卡片显示),但之后我给它的任何输入,无论是交互式卡片还是聊天命令,我都会收到上述错误。
应用程序洞察显示以下异常:
POST to BotLuis failed: POST to the bot's endpoint failed with HTTP status 500
Problem Id:System.Exception at Microsoft.Bot.ChannelConnector.BotAPI+d__31.MoveNext
当我与机器人交互时,开发者工具控制台显示:
https://webchat.botframework.com/v3/directline/conversations/3NgflndFbpzCRDtnMdZpjf-g/activities 502 (Bad Gateway)
如果您将以上 link 粘贴到浏览器中,您将得到以下内容:
{
"error": {
"code": "BadArgument",
"message": "Missing token or secret"
}
}
此时我迷路了。我能理解这个问题,但我不知道如何前进。我应该在我的代码中的某个地方添加我的机器人的消息传递端点吗?
A link 到 github 代码的回购:here
Bot State Service retired 2018 年 3 月 31 日。
因此,当您 运行 它在 Azure 上时,您的示例缺少状态存储,而它会在本地工作。
要让您的示例正常工作,只需将以下几行添加到您的 Global.asax.cs
文件中。
protected void Application_Start()
{
RegisterBotDependencies();
GlobalConfiguration.Configure(WebApiConfig.Register);
var store = new InMemoryDataStore();
Conversation.UpdateContainer(
builder =>
{
builder.Register(c => store)
.Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
.AsSelf()
.SingleInstance();
builder.Register(c => new CachingBotDataStore(store,
CachingBotDataStoreConsistencyPolicy
.ETagBasedConsistency))
.As<IBotDataStore<BotData>>()
.AsSelf()
.InstancePerLifetimeScope();
});
}
请注意,此示例使用 InMemory 存储,因此不适合生产使用。按照博客 post,您可以轻松切换到 Azure Table 存储或 CosmosDB。
我已经克隆了你的存储库,添加了这些代码行并将其部署到 Azure 上的新机器人实例。微信测试成功。
总结
摘自上述博客post.
We’ve been encouraging bot developers using the Bot Framework to use their own custom state service for a while. The default Bot Framework State service was intended for prototyping purposes only, and not designed to accommodate production bots. The state service will be deprecated on March 31, 2018 and will no longer be supported. Bot developers moving forward will be able to prototype their bots using temporary local memory storage as described in this article. Creating your own custom state service for your bot provides multiple benefits including improved latency and direct control over your bot’s conversation state and contextual user conversation state information, and we’ve provided multiple resources to guide you to do so. We appreciate the feedback we’ve been receiving from the bot developer community, which has helped us a lot in improving the Bot Framework as a whole. We also hope that we can continue helping you – the bot developer community, create better and better bot experiences for your users.
我已经使用 LUIS 和 QnA Maker 部署了一个聊天机器人。当我在 Emulator 上 运行 它在本地完美运行。它在聊天开始时加载自适应卡片,我从 LUIS 得到正确回复。
然而,当我在 Azure 上部署机器人并在 Web 聊天中对其进行测试时,出现以下错误:
There was an error sending this message to your bot: HTTP status code InternalServerError
这是我的 web.config 的样子:
<configuration>
<appSettings>
<!-- update these with your BotId, Microsoft App Id and your Microsoft App Password-->
<add key="BotId" value="BotLuis" />
<add key="MicrosoftAppId" value="9f9564ef-d627-450f-b943-98b7338c0f31" />
<add key="MicrosoftAppPassword" value="myapp-password" />
</appSettings>
我从我在 Azure 上创建的网络机器人的应用程序设置中获取 AppID 和 AppPassword 的值。我知道它们是正确的,因为我使用这些值使用模拟器在本地进行设置。
我将代码从 github 部署到 Azure。我的机器人在 azure 网络聊天中加载得很好(自适应卡片显示),但之后我给它的任何输入,无论是交互式卡片还是聊天命令,我都会收到上述错误。
应用程序洞察显示以下异常:
POST to BotLuis failed: POST to the bot's endpoint failed with HTTP status 500 Problem Id:System.Exception at Microsoft.Bot.ChannelConnector.BotAPI+d__31.MoveNext
当我与机器人交互时,开发者工具控制台显示:
https://webchat.botframework.com/v3/directline/conversations/3NgflndFbpzCRDtnMdZpjf-g/activities 502 (Bad Gateway)
如果您将以上 link 粘贴到浏览器中,您将得到以下内容:
{
"error": {
"code": "BadArgument",
"message": "Missing token or secret"
}
}
此时我迷路了。我能理解这个问题,但我不知道如何前进。我应该在我的代码中的某个地方添加我的机器人的消息传递端点吗?
A link 到 github 代码的回购:here
Bot State Service retired 2018 年 3 月 31 日。 因此,当您 运行 它在 Azure 上时,您的示例缺少状态存储,而它会在本地工作。
要让您的示例正常工作,只需将以下几行添加到您的 Global.asax.cs
文件中。
protected void Application_Start()
{
RegisterBotDependencies();
GlobalConfiguration.Configure(WebApiConfig.Register);
var store = new InMemoryDataStore();
Conversation.UpdateContainer(
builder =>
{
builder.Register(c => store)
.Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
.AsSelf()
.SingleInstance();
builder.Register(c => new CachingBotDataStore(store,
CachingBotDataStoreConsistencyPolicy
.ETagBasedConsistency))
.As<IBotDataStore<BotData>>()
.AsSelf()
.InstancePerLifetimeScope();
});
}
请注意,此示例使用 InMemory 存储,因此不适合生产使用。按照博客 post,您可以轻松切换到 Azure Table 存储或 CosmosDB。
我已经克隆了你的存储库,添加了这些代码行并将其部署到 Azure 上的新机器人实例。微信测试成功。
总结
摘自上述博客post.
We’ve been encouraging bot developers using the Bot Framework to use their own custom state service for a while. The default Bot Framework State service was intended for prototyping purposes only, and not designed to accommodate production bots. The state service will be deprecated on March 31, 2018 and will no longer be supported. Bot developers moving forward will be able to prototype their bots using temporary local memory storage as described in this article. Creating your own custom state service for your bot provides multiple benefits including improved latency and direct control over your bot’s conversation state and contextual user conversation state information, and we’ve provided multiple resources to guide you to do so. We appreciate the feedback we’ve been receiving from the bot developer community, which has helped us a lot in improving the Bot Framework as a whole. We also hope that we can continue helping you – the bot developer community, create better and better bot experiences for your users.