首页 > 解决方案 > 为 BotFramework v4 使用 TableStorage

问题描述

目前我已经使用 Azure Cosmos DB 实现了 Bots。我使用状态访问器管理状态数据(用户状态、对话状态)。

我如何使用它的示例:

// 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);

我考虑改用表存储解决方案,因为它比 Cosmos DB 便宜得多。

不幸的是,我只找到了BotFramework v3 的教程

有没有办法以类似的方式使用表存储?如果是这样,怎么做?

谢谢!

标签: node.jsdatabaseazurebotframeworkazure-table-storage

解决方案


设置数据库的一些额外提示:

文章中的语法对我不起作用。我改用这个:

const { BlobStorage } = require('botbuilder-azure');

// Add Blobstorage
const memoryStorage = new BlobStorage({
   containerName: 'CONTAINERNAME',
   storageAccountOrConnectionString: 'CONNECTIONSTRING',
})

您可以在 Azure 上的存储资源中的“密钥”下找到信息。


推荐阅读