问题描述
仅当我将漫游器部署到azure Web应用并尝试在azure门户网络聊天中进行测试后,我才收到此错误.但是我的机器人正在从本地计算机上的机器人模拟器中按预期工作.
I am getting this error only after I deployed my bot to azure web app and tried to Test in azure portal Web Chat. But my bot is working as expected from bot emulator on my local machine.
我不确定这是否是由于分配给我的天蓝色角色.我分配的角色显示为有限贡献者".我能够创建任何资源并将聊天机器人部署到azure.所以不确定是否与我的有限贡献者"角色有关.
I am not sure if this is due to the azure role assigned to me.My assigned role is showing as "Limited Contributor". I am able to create any resource and deploy my chat bot to azure.So not sure if this has anything to do with my "Limited Contributor" role.
这是引发异常的代码行(用红色标记):
Here is the line of code(marked in red) where it is throwing exception:
Exception OnTurnAsync exception inner ex.Message:
Operation returned an invalid status code 'BadRequest' ex:
Microsoft.Bot.Schema.ErrorResponseException: Operation returned an invalid status code 'BadRequest'
at Microsoft.Bot.Connector.Conversations.ReplyToActivityWithHttpMessagesAsync(String conversationId, String activityId, Activity activity, Dictionary`2 customHeaders, CancellationToken cancellationToken)
at Microsoft.Bot.Connector.ConversationsExtensions.ReplyToActivityAsync(IConversations operations, String conversationId, String activityId, Activity activity, CancellationToken cancellationToken)
at Microsoft.Bot.Builder.BotFrameworkAdapter.SendActivitiesAsync(ITurnContext turnContext, Activity[] activities, CancellationToken cancellationToken)
at Microsoft.Bot.Builder.TurnContext.<>c__DisplayClass22_0.<<SendActivitiesAsync>g__SendActivitiesThroughAdapter|1>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.Bot.Builder.TurnContext.SendActivityAsync(IActivity activity, CancellationToken cancellationToken)
at AbcChatBot.Bots.AbcsBot.OnMessageActivityAsync(ITurnContext`1 turnContext, CancellationToken cancellationToken)
任何解决或确定为什么我收到"BadRequest"的建议将不胜感激.
Any suggestions to resolve or determining why I am getting a 'BadRequest' would be appreciated.
推荐答案
此错误的根本原因是
protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
{
var reply = new Activity(); //this line caused the error
……..
}
所以我从
var reply = new Activity();
到
var reply = turnContext.Activity.AsMessageActivity();
错误消失了.
我仍然不知道为什么实际问题出在 OnMessageActivityAsync
I still don't know why the exception was throwing from onTurnAsync while the actual issue was in OnMessageActivityAsync
这篇关于聊天BoT异常:OnTurnAsync异常-操作返回了无效的状态码"BadRequest"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!