Store and Restore bot conversation using Microsoft bot framework C# sdk

Duncan J 1 Reputation point
2023-01-10T18:46:59.367+00:00

I'm building an application with Xamarin and I used syncfusion (https://www.syncfusion.com/blogs/post/how-to-connect-azure-bot-service-to-xamarin-forms-chat-control.aspx) to connect to enable the app connect with the bot built with the Microsoft bot framework and hosted in Azure. Whenever a user logout or quit the app, when they log back in, I want the user to able to continue the conversation from where they stopped. Is that possible? if yes how can I achieve that?. Thanks

Azure AI Bot Service
Azure AI Bot Service
An Azure service that provides an integrated environment for bot development.
742 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Sayali-MSFT 2,266 Reputation points Microsoft Vendor
    2023-01-13T08:08:31.9533333+00:00

    @Duncan J-A bot is inherently stateless. However, your bot may need to track the context of a conversation so that it can manage its behavior and remember answers to previous questions. The state and storage features of the Bot Framework SDK allow you to add state to your bot. Bots use state management and storage objects to manage and persist state. The state manager provides an abstraction layer that lets you access state properties using property accessors, independent of the type of underlying storage.
    A bots state is information it remembers in order to respond appropriately to incoming messages. The Bot Builder SDK provides classes for storing and retrieving state data as an object associated with a user or a conversation.

    So if you want to store the bot conversation then you need to implement state management in bot flow.

    User state is available in any turn that the bot is conversing with that user on that channel, regardless of the conversation.

    Conversation state is available in any turn in a specific conversation, regardless of user (i.e. group conversations)

    Reference-

    1. Save user and conversation data
    2. Managing state
    3. Sample link

    Thank you,
    Sayali


  2. Duncan J 1 Reputation point
    2023-01-14T15:23:02.0066667+00:00

    Ok thank you for your response. How do I retrieve the conversation, such that they can continue the conversation from where the user stopped?

    0 comments No comments

  3. Sayali-MSFT 2,266 Reputation points Microsoft Vendor
    2023-01-23T10:53:12.3766667+00:00

    @Duncan J-To continue conversation you can use the below method.
    ContinueConversationAsync Method

      async (t1, c1) =>
                        {
                            conversationReference = t1.Activity.GetConversationReference();
                            await ((CloudAdapter)turnContext.Adapter).ContinueConversationAsync(
                                _appId,
                                conversationReference,
                                async (t2, c2) =>
                                {
                                    await t2.SendActivityAsync(proactiveMessage, c2);
                                },
                                cancellationToken);
                        },
    

    Reference Document-ContinueConversation method
    Sample Link-https://github.com/OfficeDev/Microsoft-Teams-Samples/blob/main/samples/bot-conversation/csharp/Bots/TeamsConversationBot.cs#L198

    0 comments No comments