1

I am trying to create a bot in the same style as the proactive bot from the examples. I have a bot up and running that is successfully able to continue to send messages to other channels locally, but when I deploy it to azure all ContinueConversationAsync calls give a 401 which is weird as I can have a normal conversation with the bot, as long as I do not try to communicate with other conversations.

The error is:

Microsoft.Bot.Connector.Authentication.MicrosoftAppCredentials+OAuthException: Unauthorized 

I have the bot up and running correctly while testing locally.

Only when I deploy the setup to azure, do I get this error.

So it's an authentication problem, but I have trouble debugging it, as direct communication using ngrok+emulator or the webchat successfully works until I try to send to one of the other channels.

Conversation continue function

        private static BotCallbackHandler CreateCallback(string message, CancellationToken cancellationToken)
        {
            return async (turnContext, token) =>
            {
                // Send the user a proactive confirmation message.
                await turnContext.SendActivityAsync(
                    $"{message}",
                    cancellationToken: cancellationToken);
            };
        }

Code that continues conversation.

                    conv = turnContext.Adapter.ContinueConversationAsync(
                        AppId,
                        conversation,
                        CreateCallback(requestMessage.Message, cancellationToken),
                        cancellationToken);

Conversations are retrieved from storage using a blob storage or memory storage, and default serializer.

I would expect the robot to continue old saved conversations, but instead I get 401 errors.

Full stack trace

Microsoft.Bot.Connector.Authentication.MicrosoftAppCredentials+OAuthException: Unauthorized —> System.Net.Http.HttpRequestException: Response status code does not indicate success: 401 (Unauthorized).
at System.Net.Http.HttpResponseMessage.EnsureSuccessStatusCode()
at Microsoft.Bot.Connector.Authentication.MicrosoftAppCredentials.<RefreshTokenAsync>d__36.MoveNext()
— End of inner exception stack trace —
at Microsoft.Bot.Connector.Authentication.MicrosoftAppCredentials.<RefreshTokenAsync>d__36.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Connector.Authentication.MicrosoftAppCredentials.<GetTokenAsync>d__30.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Connector.Authentication.MicrosoftAppCredentials.<ProcessHttpRequestAsync>d__29.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Connector.Conversations.<ReplyToActivityWithHttpMessagesAsync>d__10.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Connector.ConversationsExtensions.<ReplyToActivityAsync>d__17.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.BotFrameworkAdapter.<SendActivitiesAsync>d__15.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
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 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.TurnContext.<SendActivityAsync>d__21.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.TurnContext.<SendActivityAsync>d__20.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at LBPSkypeBot.LbpSkypeBot.<>c__DisplayClass9_0.<<CreateCallback>b__0>d.MoveNext() in D:\Kode\Robo2\Shared\SkypeBot\SkypeBot\LbpSkypeBot.cs:line 165
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.MiddlewareSet.<ReceiveActivityWithStatusAsync>d__3.MoveNext()
— End of stack trace from previous location where exception was thrown —
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.Bot.Builder.BotAdapter.<RunPipelineAsync>d__13.MoveNext()
Kyle Delaney
  • 11,616
  • 6
  • 39
  • 66
C. Mollgaard
  • 91
  • 1
  • 5
  • Can you please update your question with the full details of the exception (i.e. full stack trace)? – Drew Marsh Jan 21 '19 at 18:52
  • If the bot works when running locally and doesn't work when published, that tends to indicate a state storage issue. You say you're using "blob storage or memory storage." Can you provide more details about that? – Kyle Delaney Jan 21 '19 at 22:48
  • I have verified that the bot can succesfully access the conversation from both a local setup and a published setup. – C. Mollgaard Jan 22 '19 at 06:56
  • Thank you for updating with the details of the exception. What channel are you trying to communicate over? Is it Teams by chance? – Drew Marsh Jan 22 '19 at 17:29
  • I am trying several actually. The webchat, skype and using Ngrok+emulator. All have this problem – C. Mollgaard Jan 23 '19 at 06:36
  • It's interesting that the stack trace doesn't include `ContinueConversationAsync`. I do see middleware mentioned, so any information you could give us about middleware would be helpful. And I'd still like more information about how you're handling state. Depending on how far you're willing to go, sometimes the best thing you can do is set up a basic bot and see if that works, and then keep changing things about your basic bot to make it more like your other bot until you find the thing that breaks it. – Kyle Delaney Jan 31 '19 at 23:42
  • Are you still working on this? – Kyle Delaney Feb 06 '19 at 20:34

0 Answers0