microsoft / botframework-sdk

Bot Framework provides the most comprehensive experience for building conversation applications.
MIT License
7.5k stars 2.44k forks source link

There was an error sending this message to your bot: HTTP status code Unauthorized #4486

Closed Jatin-Chandarana closed 6 years ago

Jatin-Chandarana commented 6 years ago

Bot Info

Issue Description

I am new to Bot framework, we want to host bot to our servers and register direct line channel to communicate it. So i have created new bot application, when i tested from bot framework emulator, it's working as expected, now i want to test same from Web Chat, i have deploy bot on local iis and using ngrok i have generated https url and submit it as endpoint as mentioned below screen.

ngrokforwarding

now i go to azure and click on Test in Web chat, but it display me can't send retry message,when i go to log, it display "There was an error sending this message to your bot: HTTP status code Unauthorized" as mentioned below screen shot.

testinwebchat

Code Example

[BotAuthentication] public class MessagesController : ApiController { ///

/// POST: api/Messages /// Receive a message from a user and reply to it /// public async Task Post([FromBody]Activity activity) {

        ConnectorClient connector = new ConnectorClient(new Uri(activity.ServiceUrl));

        if (activity.Type == ActivityTypes.Message)
        {
            // calculate something for us to return
            int length = (activity.Text ?? string.Empty).Length;

            // return our reply to the user
            //Activity reply = activity.CreateReply($"You sent {activity.Text} which was {length} characters");
            Activity reply = activity.CreateReply($"You sent {activity.Text} which was {length} characters");
            await connector.Conversations.ReplyToActivityAsync(reply);
            //return reply;
        }
        else
        {
            HandleSystemMessage(activity);
        }
        var response = Request.CreateResponse(HttpStatusCode.OK);
        return response;
    }

    private Activity HandleSystemMessage(Activity message)
    {
        if (message.Type == ActivityTypes.DeleteUserData)
        {
            // Implement user deletion here
            // If we handle user deletion, return a real message
        }
        else if (message.Type == ActivityTypes.ConversationUpdate)
        {
            // Handle conversation state changes, like members being added and removed
            // Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info
            // Not available in all channels
            IConversationUpdateActivity update = message;
            var client = new ConnectorClient(new Uri(message.ServiceUrl), new MicrosoftAppCredentials());
            if (update.MembersAdded != null && update.MembersAdded.Any())
            {
                foreach (var newMember in update.MembersAdded)
                {
                    if (newMember.Id != message.Recipient.Id)
                    {
                        var reply = message.CreateReply();
                        reply.Text = $"Welcome {newMember.Name}!";
                        client.Conversations.ReplyToActivityAsync(reply);
                    }
                }
            }
        }
        else if (message.Type == ActivityTypes.ContactRelationUpdate)
        {
            // Handle add/remove from contact lists
            // Activity.From + Activity.Action represent what happened
        }
        else if (message.Type == ActivityTypes.Typing)
        {
            // Handle knowing tha the user is typing
        }
        else if (message.Type == ActivityTypes.Ping)
        {
        }

        return null;
    }
}

Bot Id : DirectLineTest MicrosoftAppId : 4b8906ea-74f3-464d-a231-b60687f43738

Expected Behavior

Actual Results

EricDahlvang commented 6 years ago

Is the MicrosoftAppId and MicrosoftAppPassword in the web.config file?

    <add key="MicrosoftAppId" value="YourAppId" />
    <add key="MicrosoftAppPassword" value="YourAppPassword" />
Jatin-Chandarana commented 6 years ago

I already pass MicrosoftAppId and MicrosoftApppassword.

appid

Jatin-Chandarana commented 6 years ago

Hi guys any update of my issue. i'm struck up whole day.

prorokane commented 6 years ago

Microsoft.Bot.Connector 3.15.0 Same error appears periodically after few hours of inactivity. Next messages will be processed without issues.

carltierney commented 6 years ago

We are experiencing the same issue, Twilio SMS channel, it appears to be related to the bot registration. We are over 100 bot channel registrations to a single chat bot api server. The chat bot api server throws an unauthorized exception that results in a message to the end user that is not trappable. If I could at least get the exception caught without the message going to the end user I could probably handle it more gracefully.

EricDahlvang commented 6 years ago

@carltierney The sdk provides a DefaultIfExceptionDialog . You can do something similar, to log exception details:

public static class ExceptionLogging
{
    public static IDialog<T> LogIfException<T, E>(this IDialog<T> antecedent) where E : Exception
    {
        return new LogIfExceptionDialog<T, E>(antecedent);
    }
    public static IDialog<T> LogIfException<T>(this IDialog<T> antecedent)
    {
        return new LogIfExceptionDialog<T, Exception>(antecedent);
    }
}

[Serializable]
public class LogIfExceptionDialog<T, E> : IDialog<T> where E : Exception
{
    public readonly IDialog<T> Antecedent;
    public LogIfExceptionDialog(IDialog<T> antecedent)
    {
        SetField.NotNull(out this.Antecedent, nameof(antecedent), antecedent);
    }
    async Task IDialog<T>.StartAsync(IDialogContext context)
    {
        context.Call<T>(this.Antecedent, ResumeAsync);
    }
    private async Task ResumeAsync(IDialogContext context, IAwaitable<T> result)
    {
        try
        {
           context.Done(await result);
        }
        catch (E exception)
        {
            //log exception (with stack trace)                 
            context.Done(default(T));
        }
    }
}

Then in your message controller:

await Conversation.SendAsync(activity, () => new RootDialog().LogIfExceptionDialog())) 
prorok-kane commented 6 years ago

Does this hide exceptions from users?

EricDahlvang commented 6 years ago

@prorok-kane Yes, this will swallow exceptions and the users will not see "Sorry, my bot code is having an issue."

prorokane commented 6 years ago

"Sorry, my bot code is having an issue." still appears. The main problem is that I can not influence on this issue.

2018-05-02 19:32:05.6935|ERROR|LunchCrewBot.Controllers.MessagesController|Microsoft.Bot.Connector.ErrorResponseException: Operation returned an invalid status code 'Unauthorized'
   at Microsoft.Bot.Connector.BotState.<GetConversationDataWithHttpMessagesAsync>d__8.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Bot.Connector.BotStateExtensions.<GetConversationDataAsync>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Bot.Builder.Dialogs.Internals.ConnectorStore.<Microsoft-Bot-Builder-Dialogs-Internals-IBotDataStore<Microsoft-Bot-Connector-BotData>-LoadAsync>d__2.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\ConnectorEx\BotData.cs:line 203
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Bot.Builder.Dialogs.Internals.CachingBotDataStore.<LoadFromInnerAndCache>d__11.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\ConnectorEx\BotData.cs:line 372
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Bot.Builder.Dialogs.Internals.CachingBotDataStore.<Microsoft-Bot-Builder-Dialogs-Internals-IBotDataStore<Microsoft-Bot-Connector-BotData>-LoadAsync>d__9.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\ConnectorEx\BotData.cs:line 320
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Bot.Builder.Dialogs.Internals.BotDataBase`1.<LoadData>d__16.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\ConnectorEx\BotData.cs:line 554
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Bot.Builder.Dialogs.Internals.BotDataBase`1.<LoadAsync>d__8.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\ConnectorEx\BotData.cs:line 515
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Bot.Builder.Dialogs.Internals.DialogTaskManagerBotDataLoader.<LoadAsync>d__11.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\ConnectorEx\BotData.cs:line 474
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Bot.Builder.Dialogs.Internals.PersistentDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__3.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Dialogs\DialogTask.cs:line 478
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Bot.Builder.Dialogs.Internals.ExceptionTranslationDialogTask.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__2.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Dialogs\DialogTask.cs:line 403
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Bot.Builder.Dialogs.Internals.SerializeByConversation.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__4.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\ConnectorEx\PostToBot.cs:line 129
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Bot.Builder.Dialogs.Internals.PostUnhandledExceptionToUser.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__5.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\ConnectorEx\PostToBot.cs:line 156
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.Bot.Builder.Dialogs.Internals.PostUnhandledExceptionToUser.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__5.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\ConnectorEx\PostToBot.cs:line 169
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Bot.Builder.Dialogs.Internals.LogPostToBot.<Microsoft-Bot-Builder-Dialogs-Internals-IPostToBot-PostAsync>d__3.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\ConnectorEx\IActivityLogger.cs:line 109
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Bot.Builder.Dialogs.Conversation.<SendAsync>d__11.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder.Autofac\Dialogs\Conversation.cs:line 182
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.Bot.Builder.Dialogs.Conversation.<SendAsync>d__6.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder.Autofac\Dialogs\Conversation.cs:line 108
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at LunchCrewBot.Controllers.MessagesController.<Post>d__1.MoveNext() in D:\a\1\s\Lunch Crew Bot\Controllers\MessagesController.cs:line 37
prorokane commented 6 years ago

Just in case. I think this important. My problem reproduces only in Telegram Group chat.

EricDahlvang commented 6 years ago

Another way to catch the message being sent to the user is to override the PostUnhandledExceptionToUser autofac registration:

Conversation.UpdateContainer(
    builder =>
    {
        builder
            .RegisterType<CustomPostUnhandledExceptionToUser>()
            .Keyed<IPostToBot>(typeof(PostUnhandledExceptionToUser));

    });

    public sealed class CustomPostUnhandledExceptionToUser : IPostToBot
    {
        private readonly IPostToBot inner;
        private readonly IBotToUser botToUser;
        private readonly ResourceManager resources;
        private readonly TraceListener trace;

        public PostUnhandledExceptionToUser(IPostToBot inner, IBotToUser botToUser, ResourceManager resources, TraceListener trace)
        {
            SetField.NotNull(out this.inner, nameof(inner), inner);
            SetField.NotNull(out this.botToUser, nameof(botToUser), botToUser);
            SetField.NotNull(out this.resources, nameof(resources), resources);
            SetField.NotNull(out this.trace, nameof(trace), trace);
        }

        async Task IPostToBot.PostAsync(IActivity activity, CancellationToken token)
        {
            try
            {
                await this.inner.PostAsync(activity, token);
            }
            catch
            {
                try
                {
                    //or, comment this line to not send a message to the user
                    await this.botToUser.PostAsync("Custom message to user");
                }
                catch (Exception inner)
                {
                    this.trace.WriteLine(inner);
                }

                throw;
            }
        }
    }

It is also possible to disable the autofac registration, as is done in the Disable unit tests:

Conversation.Disable(typeof(PostUnhandledExceptionToUser), builder); https://github.com/Microsoft/BotBuilder/blob/31048a2173313c81a2db47efce6a8a869b4ec284/CSharp/Tests/Microsoft.Bot.Builder.Tests/DisableTests.cs#L90

prorokane commented 6 years ago

Anything new on this issue?

EricDahlvang commented 6 years ago

@prorokane Not at this time. It appears there is some issue with the default state client. However, this is being deprecated and all bots should either use the InMemoryDataStore, Azure Extensions, or something custom (it seems bots who are not using the default state service do not experience this issue).

JasonSowers commented 6 years ago

@prorokane @carltierney and anyone else experiencing this issue If you are experiencing 401 errors in 3.15.2.2 Can you please post in this issue I created #4733 With the following details:

  1. Frequency - How often is this happening? Every message? Randomly and how often ex. 1 out of 10 messages
  2. What channels is this happening on, is it working on any channels?
  3. Stack trace
  4. Deployment where is this happening - Local testing? Azure? Both?

if not locally

  1. Type of bot Functions bot? Web App bot?
  2. Is there any relevant info in app insights?
  3. Timestamp and conversation ID when this occurs?
kevinport commented 6 years ago
  1. Every 2-5 hours, the first message
  2. Webchat, Facebook
  3. at Microsoft.Bot.Connector.Conversations.d9.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Connector.ConversationsExtensions.d9.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.AlwaysSendDirect_BotToUser.d4.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\ConnectorEx\BotToUser.cs:line 124\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.InputHintQueue.d4.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\ConnectorEx\BotToUser.cs:line 184\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.AutoInputHint_BotToUser.d3.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\ConnectorEx\BotToUser.cs:line 146\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.MapToChannelData_BotToUser.d3.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\ConnectorEx\BotToUser.cs:line 295\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.LogBotToUser.d4.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\ConnectorEx\IActivityLogger.cs:line 131\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.DialogContext.d12.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Dialogs\DialogContext.cs:line 87\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Extensions.d14.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Dialogs\IDialogContext.cs:line 150\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Sample.SimpleEchoBot.EchoDialog.d2.MoveNext() in C:\SW\dotnet\projects\arcofel Messenger\ArcofelMessengerBot-src\Dialogs\EchoDialog.cs:line 38\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.ThunkResume`1.d5.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Dialogs\DialogTask.cs:line 164\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Internals.Fibers.Wait2.<Microsoft-Bot-Builder-Internals-Fibers-IWait<C>-PollAsync>d__19.MoveNext() in D:\\a\\1\\s\\CSharp\\Library\\Microsoft.Bot.Builder\\Fibers\\Wait.cs:line 0\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Internals.Fibers.Frame1.<Microsoft-Bot-Builder-Internals-Fibers-IFrameLoop-PollAsync>d9.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Fibers\Fiber.cs:line 0\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Internals.Fibers.Fiber`1.<Microsoft-Bot-Builder-Internals-Fibers-IFiberLoop-PollAsync>d16.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Fibers\Fiber.cs:line 0\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at Microsoft.Bot.Builder.Internals.Fibers.Wait2.Microsoft.Bot.Builder.Internals.Fibers.IAwaiter<T>.GetResult() in D:\\a\\1\\s\\CSharp\\Library\\Microsoft.Bot.Builder\\Fibers\\Wait.cs:line 378\r\n at Microsoft.Bot.Builder.Dialogs.Chain.LoopDialog1.d3.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Dialogs\Chain.cs:line 752\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.ThunkResume`1.d5.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Dialogs\DialogTask.cs:line 164\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Internals.Fibers.Wait2.<Microsoft-Bot-Builder-Internals-Fibers-IWait<C>-PollAsync>d__19.MoveNext() in D:\\a\\1\\s\\CSharp\\Library\\Microsoft.Bot.Builder\\Fibers\\Wait.cs:line 0\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Internals.Fibers.Frame1.<Microsoft-Bot-Builder-Internals-Fibers-IFrameLoop-PollAsync>d9.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Fibers\Fiber.cs:line 0\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Internals.Fibers.Fiber`1.<Microsoft-Bot-Builder-Internals-Fibers-IFiberLoop-PollAsync>d16.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Fibers\Fiber.cs:line 244\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.DialogTask.d23.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Dialogs\DialogTask.cs:line 321\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.ReactiveDialogTask.d3.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Dialogs\DialogTask.cs:line 376\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.ScoringEventLoop`1.d5.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Dialogs\ScoringEventLoop.cs:line 87\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.EventLoopDialogTask.d3.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Dialogs\DialogTask.cs:line 435\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.SetAmbientThreadCulture.d3.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\ConnectorEx\PostToBot.cs:line 103\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.QueueDrainingDialogTask.d4.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Dialogs\DialogTask.cs:line 455\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.PersistentDialogTask.d3.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Dialogs\DialogTask.cs:line 481\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at Microsoft.Bot.Builder.Dialogs.Internals.PersistentDialogTask.d3.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Dialogs\DialogTask.cs:line 485\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.ExceptionTranslationDialogTask.d2.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\Dialogs\DialogTask.cs:line 403\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.Bot.Builder.Dialogs.Internals.SerializeByConversation.d4.MoveNext() in D:\a\1\s\CSharp\Library\Microsoft.Bot.Builder\ConnectorEx\PostToBot.cs:line 129\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at arcofel_UniversalBot.Dialogs.CustomPostUnhandledExceptionToUser.d5.MoveNext() in C:\SW\dotnet\projects\arcofel Messenger\ArcofelMessengerBot-src\Dialogs\CustomPostUnhandledExceptionToUser.cs:line 37
  4. Azure
  5. Web App bot
  6. the same information 401 Unauthorized
  7. { "type": "message", "timestamp": "2018-06-12T15:01:02.7672977+00:00", "localTimestamp": "2018-06-12T15:01:02.7672977+00:00", "serviceUrl": "https://facebook.botframework.com", "channelId": "facebook", "from": { "id": "1898523587053781", "name": "ArcofelMessengerBot" }, "conversation": { "isGroup": false, "id": "1664395866958984-1898523587053781" }, "recipient": { "id": "1664395866958984", "name": "Kevin Port" }, "text": "34: You said HI", "attachments": [], "entities": [], "replyToId": "mid.$cAAbkQRGlcGxqJcjiZ1j9IOZ8ZKBv" }

https://facebook.botframework.com/v3/conversations/1664395866958984-1898523587053781/activities/mid.%24cAAbkQRGlcGxqJcjiZ1j9IOZ8ZKBv

Default Echo bot with CustomPostUnhandledExceptionToUser

EricDahlvang commented 6 years ago

Closing #4486. https://github.com/Microsoft/BotBuilder/issues/4733 will now track the elusive 401s some users are seeing, until the issue is resolved.

JasonSowers commented 6 years ago

We have released a new package 3.15.2.3 that we believe addresses this issue. Please let us know if you are still experiencing this issue after upgrading. in #4733

soso-maitha commented 6 years ago

I have same issue :( I upgraded all my negut packages to the latest stable releases and changed my time to the service time and used ngrok and already app id and password in the web.config and in the emulators but still getting unauthorized error. even in the web chat test in Azure i am getting the same :( In localhost it is working perfectly any suggestions ??

EricDahlvang commented 6 years ago

@soso-maitha This is a closed issue. 401 Unauthorized is being tracked here: https://github.com/Microsoft/BotBuilder/issues/4733 Please comment there if you are experiencing 401s.

CalvinFengDatacom commented 6 years ago

@EricDahlvang Hi Eric, we are still intermittently getting the issue of "There was an error sending this message to your bot: HTTP status code InternalServerError" from Direct Line recent issues of Azure Bot Service. And when we got this issue, in our client side, we got 502 bad gateway.

I would like to know does anyone has the exactly same issue? As I have read many issues within the Bot github, but seems nobody has the same issue with mine.

We are currently using Customized state service, not default. And we have configured the Azure App Service to be "Always On" in order to make it faster. But, we are using the Bot SDK 3.15.2.2.

Can you confirm that does the Bot builder SDK 3.15.2.3 will resolve my issue? Or do you have any idea what matters the issue highly likely? I will try to monitor it accordingly.

EricDahlvang commented 6 years ago

Has this been happening only recently? Is the issue intermittent, or consistent after some time or circumstances? InternalServerError could be any number of things. Have you setup failed request tracing on the app service? Are you logging exceptions in the bot? Do you have application insights installed and configured for the bot and for the bot's web app itself? Are you using a custom state client?

CalvinFengDatacom commented 6 years ago

This is just happened recently and intermittently, not consistent. I have setup the failed request tracing but I can't find the details of the failed. And we are using custom state client. We do have application insight, but same as failed request tracing, there is no details of the error neither. Let me try to log the exception in the bot, see what can I get.