Dipumon
Dipumon

Reputation: 149

Bot Framework state management using rest service

In the documentation for state management, it is mentioned that we can use rest service for state management, instead of overriding the IBotDataStore.

Can someone provide the method to do the same.

I have a database, which is not directly accessible from the bot code.So, I am planning to build a webservice for the database and store the state inside the db.

Upvotes: 1

Views: 105

Answers (1)

Nicolas R
Nicolas R

Reputation: 14619

From my understanding of the framework, the main point is to create a class that implement IBotDataStore<BotData>, and then register your class like they do for TableBotDataStore or SqlBotDataStore.

The IBotDataStore<BotData> interface is defined in BotBuilder's GitHub project, here.

With this interface, you will have to implement a few methods:

  • Task<T> LoadAsync(IAddress key, BotStoreType botStoreType, CancellationToken cancellationToken) in order to get your data

  • Task SaveAsync(IAddress key, BotStoreType botStoreType, T data, CancellationToken cancellationToken); in order to save your data

  • Task<bool> FlushAsync(IAddress key, CancellationToken cancellationToken); in order to flush your data

It's inside those methods that your REST API calls will take place.

You can have a look to how it is made for Azure storages in BotBuilder-Azure GitHub's project, for example for TableBotDataStore, here

Upvotes: 2

Related Questions