teamsfx-storage-providers
v1.0.4
Published
`PostgresStorage` is a storage provider for the Microsoft Bot Framework that enables bot state persistence using PostgreSQL. This package provides an implementation of `Storage` from `botbuilder`, allowing bots to store and retrieve stateful data efficien
Maintainers
Readme
PostgresStorage for Bot Framework
Overview
PostgresStorage is a storage provider for the Microsoft Bot Framework that enables bot state persistence using PostgreSQL. This package provides an implementation of Storage from botbuilder, allowing bots to store and retrieve stateful data efficiently.
Installation
You can install this package via npm:
npm install teamsfx-storage-providersConfiguration
To use PostgresStorage, you need to provide PostgreSQL connection details in the form of PostgresStorageOptions.
import { PostgresStorage, PostgresStorageOptions } from "teamsfx-storage-providers/dist/connectors/postgresStorage";
const pgConfig: PostgresStorageOptions = {
database: 'postgres',
user: 'yourUser',
password: 'yourPassword',
host: 'your-host-url',
port: 5432,
tableName: 'bot_state',
schemaName: 'bot_schema',
ssl: true
};
const postgresStorage = new PostgresStorage(pgConfig);Usage
You can integrate PostgresStorage into your bot using the BotFrameworkAdapter, for more please refer to Microsoft documentation:
import { BotFrameworkAdapter } from 'botbuilder';
const adapter = new BotFrameworkAdapter({
appId: process.env.MICROSOFT_APP_ID,
appPassword: process.env.MICROSOFT_APP_PASSWORD
});
adapter.useStorage(postgresStorage);Reading from Storage
const keys = ['userState-123'];
const data = await postgresStorage.read(keys);
console.log(data);Writing to Storage
await postgresStorage.write({
'userState-123': { count: 1, eTag: '*' }
});Deleting from Storage
await postgresStorage.delete(['userState-123']);Features
- Supports PostgreSQL as a bot state storage provider
- Implements
botbuilderStorageinterface - Supports optimistic concurrency with eTag validation
- Uses JSONB for efficient document storage
- Automatically initializes the schema and table
Environment Variables
For secure storage, it's recommended to use environment variables and use it in config for database credentials:
export PG_USER='yourUser'
export PG_PASSWORD='yourPassword'
export PG_HOST='your-host.postgres.database.azure.com'
export PG_DATABASE='postgres'License
This package is proprietary and is not open source. Contact the package owner for more details.
