聊天 BoT 异常:OnTurnAsync 异常 - 操作返回了无效的状态代码“BadRequest" [英] Chat BoT Exception: OnTurnAsync exception-- Operation returned an invalid status code 'BadRequest'

查看:26
本文介绍了聊天 BoT 异常:OnTurnAsync 异常 - 操作返回了无效的状态代码“BadRequest"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

仅在我将机器人部署到 azure 网络应用程序并尝试在 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 角色.我分配的角色显示为有限贡献者".我能够创建任何资源并将我的聊天机器人部署到 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.

推荐答案

这个错误的根本原因是

The root cause of this error was

protected override async Task OnMessageActivityAsync(ITurnContext<IMessageActivity> turnContext, CancellationToken cancellationToken)
            {
    var reply = new Activity(); //this line caused the error
    ……..

    }

所以我改变了我的代码

var 回复 = new Activity();

var reply = turnContext.Activity.AsMessageActivity();

错误消失了.

我仍然不知道为什么 onTurnAsync 会抛出异常,而实际问题出在 OnMessageActivityAsync

I still don't know why the exception was throwing from onTurnAsync while the actual issue was in OnMessageActivityAsync

这篇关于聊天 BoT 异常:OnTurnAsync 异常 - 操作返回了无效的状态代码“BadRequest"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆