Bot loses the context after a timeout
Bot Info
- SDK Platform: .NET
- SDK Version: 3.13.1
- Active Channels: Skype For Business
- Deployment Environment: Azure App Service
Issue Description
Actually I have a bot in test environment with S4B like Channel, but when the QA team start their test, one of them left the conversation (don't write for 10 or 15 minutes) and restart the conversation the bot don't response.
PD: The state service will no have support after 31th march so I changed this approach to this -> https://blog.botframework.com/2017/07/26/saving-state-sql-dotnet/
Reproduction Steps
- Start the conversation
- Interact with the bot
- Don't write for 10 or 15 minutes
- Restart to write
- The bot don't response
Expected Behavior
I suppose that the bot response the questions and continue with the context and dialog
Actual Results
This imagen show the error, I answer the bot question with Yes and the bot don't continue with the dialog. (The time elapsed between the answers was 10 minutes)

The next imagen show you the rigth way before the Yes answer

I believe this is because SfB "randomly" starts new conversations. Some information about this can be found here: https://techcommunity.microsoft.com/t5/Skype-for-Business-IT-Pro/Multiple-chats-sessions-with-same-contact-in-S4B-window/td-p/40170 Since dialog state is keyed on conversation id, and the conversation id changes, then the state is not retrieved after the new conversation is started.
I will escalate this to someone on the Skype for Business Bots team.
Hey @JuanEstebanYC
I spoke with one of the engineers who wrote the BotBuilder v3 .net sdk. He pointed out that you can override saving dialog state, so it is persisted in UserData instead. Currently, this line is what registers the data bag used for dialog state: https://github.com/Microsoft/BotBuilder/blob/master/CSharp/Library/Microsoft.Bot.Builder.Autofac/Dialogs/DialogModule.cs#L296
If you override this with your own registration, you can change it to the .UserData bag instead:
Conversation.UpdateContainer(
builder =>
{
builder.Register(c =>
{
var cc = c.Resolve<IComponentContext>();
Func<IBotDataBag> make = () =>
{
return cc.Resolve<IBotData>().UserData;
};
return make;
})
.As<Func<IBotDataBag>>()
.InstancePerLifetimeScope();
});
Please try this, and let me know if it solves the problem.
Hi Eric,
I'm actually having a similar issue in Web and Skype channel. Here's the error that occurs:
| Event time | 3/15/2018 8:08:56 AM |
|---|---|
| Message | POST to FosterCareAssistant failed: POST to the bot's endpoint failed with HTTP status 500 POST to the bot's endpoint failed with HTTP status 500 |
| Exception type | System.Exception |
| Failed method | Microsoft.Bot.ChannelConnector.BotAPI+ |
{ "message": "An error has occurred.", "exceptionMessage": "Operation returned an invalid status code 'Unauthorized'", "exceptionType": "Microsoft.Bot.Connector.ErrorResponseException", "stackTrace": " at Microsoft.Bot.Connector.Conversations.
@chixcancode Please open a new issue https://github.com/Microsoft/BotBuilder/issues/new
@JuanEstebanYC Did the solution provided above work for you?
Hi,
I downgraded to v 3.13.1 on Saturday night. Have not seen issue re-occur since.
@chixcancode Thanks for the update, but this is a different issue.
@EricDahlvang Thanks you for the answer, if you need to close that topic please do it, because the project are stoped and I don't have access to the code until the project restart.
hi, Is this issue still open. Because I am also facing the same issue with skype for business channel.
@subhamawasthi Have you tried the fix suggested:
Conversation.UpdateContainer(
builder =>
{
builder.Register(c =>
{
var cc = c.Resolve<IComponentContext>();
Func<IBotDataBag> make = () =>
{
return cc.Resolve<IBotData>().UserData;
};
return make;
})
.As<Func<IBotDataBag>>()
.InstancePerLifetimeScope();
});
Does that resolve the issue for you?
@EricDahlvang I am having the same issue and the above fix did not work for me.
I am not entirely sure how this would work too. If the conversation Id is changed how it will resume with the same context and dialog stack?
@waqas-zia-confiz as pointed out here: https://github.com/Microsoft/BotBuilder/issues/4315#issuecomment-373217490 <-- this change will store the dialog stack in the UserData bag instead of PrivateConversationData
Have you tried this method?
@EricDahlvang
Yes, I have tried this method. On Skype for Business, the conversation still times out after 10 minutes.
@waqas-zia-confiz Can you share your bot's code?
@EricDahlvang
Conversation.UpdateContainer(
builder =>
{
account.CreateCloudTableClient().GetTableReference(tableName).CreateIfNotExists();
builder.RegisterModule(new Helpers.TableLoggerModule(account, tableName));
var store = new TableBotDataStore(connectionString);
builder.Register(c => store)
.Keyed<IBotDataStore<BotData>>(AzureModule.Key_DataStore)
.AsSelf()
.SingleInstance();
builder.Register(c =>
{
var cc = c.Resolve<IComponentContext>();
Func<IBotDataBag> make = () =>
{
return cc.Resolve<IBotData>().UserData;
};
return make;
})
.As<Func<IBotDataBag>>()
.InstancePerLifetimeScope();
});
Here is my code.
@EricDahlvang Is there any update on this?
@waqas-zia-confiz Sorry, no update at this time. I will look into this some more, and get back to you.
I am also having the same situation. My bot is proactively pings the user on skype for business and the bot prompts one question with options but the user responded around 15 minutes later so the bot went off context and started the whole conversation. I checked the log there i can clearly see that the conversation id is different for first message and the user reply(After 15 minutes).