Reputation: 53
Currently I have implemented Bots using Azure Cosmos DB. I manage state data (userstate, conversationstate) with the state accessors.
A sample of how I use it:
// Use AutosaveStateMiddleware
adapter.use(new AutoSaveStateMiddleware(conversationState));
adapter.use(new AutoSaveStateMiddleware(userState));
// Read State from DB
const conversationData = await this.conversationDataAccessor.get(turnContext, {});
const user = await this.userDataAccessor.get(turnContext, {});
// Manipulate state
conversationData.roundCounter = 1;
userData.name = "John Doe";
// Save to cache
await this.userDataAccessor.set(turnContext, user);
await this.conversationDataAccessor.set(turnContext, conversationData);
// Save changes to DB (persistent)
await this.conversationState.saveChanges(turnContext);
await this.userState.saveChanges(turnContext);
I consider switching to a table storage solution, since it is much cheaper than Cosmos DB.
Unfortunately, I only found a tutorial for BotFramework v3.
Is there a way to use a table storage in a similar fashion? If so, how?
Thank you!
Upvotes: 0
Views: 814
Reputation: 53
Some additional hints for setting up the DB:
The syntax from the article didn't work for me. I used this instead:
const { BlobStorage } = require('botbuilder-azure');
// Add Blobstorage
const memoryStorage = new BlobStorage({
containerName: 'CONTAINERNAME',
storageAccountOrConnectionString: 'CONNECTIONSTRING',
})
You can find the info under "keys" in your storage resource on Azure.
Upvotes: 1