user3740951
user3740951

Reputation: 1239

Questions about saving bot state

I read through this https://learn.microsoft.com/en-us/azure/bot-service/dotnet/bot-builder-dotnet-state about saving state data. I have some questions regarding the same:- Lets take a bot exposed through the browser channel as an example here:-

  1. What is the lifetime of the data stored? For instance when the bot saves data using context.ConversationData.SetValue(..) Is the data purged when the session is over(when the user refreshes the page)?

  2. The From object from Activity has Id and Name. Are these generated by the channel each time a chat session begins? For instance, if I was chatting with bot then refresh the web page, now will my Id and Name have changed?

  3. Same question about conversation. If I refresh the page and begin the conversation again, do I get a new conversation ID?
  4. I read in some blog that if you use dialogs, the dialog stack state is automatically saved in whichever storage you have configured. Is this correct? If so, why? Say I refresh the page, will I be able to retrieve the state of the dialog stack and resume the conversation from there?

If you are giving code samples, request you to give C# samples if possible

Thanks very much in advance!

Upvotes: 1

Views: 1415

Answers (2)

Sandip
Sandip

Reputation: 262

Hi, I hope below answer will find useful to you :

1.

What is the lifetime of the data stored? For instance when the bot saves data using context.ConversationData.SetValue(..) Is the data purged when the session is over(when the user refreshes the page)?

ANS:->

As per the guidelines by Bot Framework, State API is in the state of depreciation. you will have to use your own state management service to maintain the state of your Bot. Ref: https://learn.microsoft.com/en-us/azure/bot-service/dotnet/bot-builder-dotnet-state

So assuming you are using Table Storage or SQL Database for storing your bot in this case the data will persist as long as your storage account and database available.

2.

The From object from Activity has Id and Name. Are these generated by the channel each time a chat session begins? For instance, if I was chatting with bot then refresh the web page, now will my Id and Name have changed?

ANS:->

This depends on how you initialize the chat. for instance, if you are using

  • Web chat : It will be empty id.
  • Skype : It will be skype id and user name
  • DirectLine : you can define your own id and name as per your need.

3.

Same question about the conversation. If I refresh the page and begin the conversation again, do I get a new conversation ID?

ANS:->

Yes. Every time you refresh your webpage you will be assigned new conversationId but in case of DirectLine you can use the previous conversation id to maintain the history of your conversation. you can store the conversation id in local storage or in browser's cookies and read whenever you feel to load the chat history. If you don't need history to be preserved then I suggest let webchannel handle its own ids.

4.

I read in some blog that if you use dialogs, the dialog stack state is automatically saved in whichever storage you have configured. Is this correct?

ANS:-> Yes.

5.

If so, why? Say I refresh the page, will I be able to retrieve the state of the dialog stack and resume the conversation from there?

ANS:->

As hinted earlier, you will need to migrate your bot to use DirectLine API instead of webchat channel. As webchat doesn't support history so DirectLine.

Please refer the guidelines provided by Microsoft and Samples provided on GitHub. https://learn.microsoft.com/en-us/azure/bot-service/rest-api/bot-framework-rest-direct-line-3-0-concepts

Upvotes: 2

Nicolas R
Nicolas R

Reputation: 14619

Quick answers:

  1. As far as I know, there is no purge. And you can check the implementations of Azure DocumentDbBotDataStore or TableBotDataStore here. Based on my implementations, I saw there is a Timestamp column in the stored data so you could do cleanup based in that.

  2. Generation of Id and Name fields (for From, but also for Recipient given the message origin / destination): yes they depend on the channel. I made a detailed answer about on SO: Bot Framework User Identification

  3. Yes in the webchat's case

  4. Yes, the dialog stack state is saved so that you can continue your conversation. "Say I refresh the page, will I be able to retrieve the state of the dialog stack and resume the conversation from there?": if you have the same details (channelId + conversationId, userId) you should yes. The exception is the webchat / directLine where you have to implement the fact that you keep the same IDs. For other channels like Slack, Facebook Messenger etc, these items remains the same and the dialog can continue where it stops on the previous messages exchange

Upvotes: 1

Related Questions