0
votes

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.

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: enter image description here

  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)

Any suggestions to resolve or determining why I am getting a 'BadRequest' would be appreciated.

2

2 Answers

0
votes

This is typically because the MicrosoftAppId/MicrosoftAppPassword configured in your App Service configuration, or within your code (depending on how you have it configured). Please make sure they are configured there and then try again.

My guess is that it does not have to do with your role. Additionally, I don't see the role '' as standard. I do see a Limited Administrator but not a Limited Contributor:

https://docs.microsoft.com/en-us/azure/active-directory/users-groups-roles/directory-assign-admin-roles

0
votes

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
    ……..

    }

So I changed my code from

var reply = new Activity();

to

var reply = turnContext.Activity.AsMessageActivity();

and the error is gone.

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