Skip to content

TDAmeritrade/botbuilder-storage-postgres

Repository files navigation

[Github All Releases]FOSSA Status () License: MIT Twitter FOSSA Status

State Storage for Bot Framework using Postgres

This project provides a Postgres storage mechanism for Bot Framework-JS SDK V4.

It allows you to store bot state in Postgres, so that you can scale out your bot, and be more resilient to bot server failures.

For more information about the botbuilder community, please visit the botbuilder community project.

Requirements

  • NodeJS 10.x is a requirement to install dependencies, build and run tests.
  • Postgres database.

Installation

npm install botbuilder-storage-postgres

Sample Usage

const postgresStorage = new PostgresStorage({
  uri : process.env.POSTGRES_URI
});

const conversationState = new ConversationState(postgresStorage);

Where POSTGRES_URI is set in .env or your secrets store of choice according to LibPQ Connection String standards. E.g.

postgresql://[user[:password]@][netloc][:port][,...][/dbname][?param1=value1&...]

NOTE Make sure to encode special characters in the password. More details on percent encoding

Methods

The conversationState declared above would have three methods attached:

  • read. Signature: async read(stateKeys: string[]): Promise<StoreItems>
  • write. Signature: async write(changes: StoreItems): Promise<void>
  • delete. Signature: async delete(keys: string[]): Promise<void>

For information about the types expected and returned with each method, please check out the source and read the Microsoft Storage Interface documentation.

Configuration Options

Field Description Value
uri The Postgres connection URI Required
collection The name you'd like given to the table the bot will reference. Optional
logging Whether or not you want logging of transactions enabled. Optional

⚠ Caution: you should not store postgres URI in code! Get the uri from a configuration such as environment variable or a secrets store in your environment. It may contain sensitive password in the clear and should never be stored in code!

See Postgres Connection URI format in the official documentation to learn more about the connection uri parameter value.


*

  • botbuilder-storage-postgres
  • Copyright 2019 TD Ameritrade. Released under the terms of the MIT license.