Closed Jatin-Chandarana closed 6 years ago
Is the MicrosoftAppId and MicrosoftAppPassword in the web.config file?
<add key="MicrosoftAppId" value="YourAppId" />
<add key="MicrosoftAppPassword" value="YourAppPassword" />
I already pass MicrosoftAppId and MicrosoftApppassword.
Hi guys any update of my issue. i'm struck up whole day.
Microsoft.Bot.Connector 3.15.0 Same error appears periodically after few hours of inactivity. Next messages will be processed without issues.
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.
@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()))
Does this hide exceptions from users?
@prorok-kane Yes, this will swallow exceptions and the users will not see "Sorry, my bot code is having an issue."
"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
Just in case. I think this important. My problem reproduces only in Telegram Group chat.
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
Anything new on this issue?
@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).
@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:
if not locally
2.<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.Frame
1.<Microsoft-Bot-Builder-Internals-Fibers-IFrameLoop2.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.LoopDialog
1.2.<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.Frame
1.<Microsoft-Bot-Builder-Internals-Fibers-IFrameLoopDefault Echo bot with CustomPostUnhandledExceptionToUser
Closing #4486. https://github.com/Microsoft/BotBuilder/issues/4733 will now track the elusive 401s some users are seeing, until the issue is resolved.
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
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 ??
@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.
@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.
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?
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.
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.
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.
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)
{
Bot Id : DirectLineTest MicrosoftAppId : 4b8906ea-74f3-464d-a231-b60687f43738
Expected Behavior
Actual Results