Reputation: 99
I am using node js and Microsoft Bot builder sdk to write a BOT. Currently, I am saving everything in data bags (conversationData, userData etc) and using CosmosDb to store the state. I followed this article to configure CosmosDB & made changes as per nodejs. https://azure.microsoft.com/en-in/blog/bot-conversation-history-with-azure-cosmos-db/
There are few concerns with this approach,
Ideally, we would like to keep everything.
Is there a better way to save chat history & conversationData, userData databags in MS BOT ?.
Upvotes: 0
Views: 1259
Reputation: 3247
All storage implementations just write getData and saveData, they internally have a key:value store where key is typically userId + conversationId, but you can make it whatever you want as long as you can reliably derive it from the arguments passed to getData
and setData
.
Looking at a sample in redis https://github.com/suttna/botbuilder-redis-storage - https://github.com/suttna/botbuilder-redis-storage/blob/master/src/storage.ts for an example storage implementation that's pretty easy to follow.
You would use a custom implementation like this
// Create new storage with redis client
var storage = new YourStorage()
// this is just here for the sake of initializing a `bot`
var connector = new builder.ChatConnector()
var bot = new builder.UniversalBot(connector)
// Configure bot to use YourStorage
bot.set('storage', storage)
bot.set('persistConversationData', true);
storage
is just an object that implements
public saveData(context: IBotStorageContext, data: IBotStorageData, callback?: (err: Error) => void)
public getData(context: IBotStorageContext, callback: (err: Error, data: IBotStorageData) => void)
I totally just copied those signatures from the linked redis module, but they are the same in the BotBuilder source for the default storage - https://github.com/Microsoft/BotBuilder/blob/5cf71c742f27d89e9dbc4076f850122bd6edac11/Node/calling/src/storage/BotStorage.ts
The samples are in typescript. If you are unfamiliar, ignore the bit right after :
which indicates the type of a thing.
Upvotes: 1