tahsintahsin
tahsintahsin

Reputation: 1054

How to keep conversation data in MS Bot framework

I am working with Microsoft bot development framework, using its node.js sdk. I have been looking for a way to save all the messages of a conversation. I set persistConversationData to true, and tried to access the conversationData using session.conversationData. However, it is empty.

1- Is there a builtin method to access all the messages within a conversation?

2- If persistConversationData is not for that, can anyone please explain its usage.

Thank you so much.

Upvotes: 3

Views: 2967

Answers (1)

thegaram
thegaram

Reputation: 777

By default, messages will not be persisted by the Microsoft Bot Framework. For stateful operations, you can use the Bot State API the following ways:

  • Set userData. The persisted data will be available to the same user across different conversations.
  • Set conversationData. The persisted data will be available to all the users within the same conversation.
  • Set privateConversationData. The persisted data will be available to the given user in the given conversation.
  • Set dialogData for storing temporary information in between the steps of a waterfall.

According to the documentation, conversationData is disabled by default. If you want to use it, you have to set persistConversationData to true.

tl;dr You have to take care of persistence for yourself. E.g.

// ...

var bot = new builder.UniversalBot(connector, { persistConversationData: true });

bot.dialog('/', function (session) {
    let messages = session.conversationData || [];
    messages.push(session.message);
    session.conversationData = messages;
});

Upvotes: 6

Related Questions