MemoryStorage class

Memory based storage provider for a bot.

Remarks

This provider is most useful for simulating production storage when running locally against the emulator or as part of a unit test. It has the following characteristics:

  • Starts off completely empty when the bot is run.
  • Anything written to the store will be forgotten when the process exits.
  • Objects that are read and written to the store are cloned to properly simulate network based storage providers.
  • Cloned objects are serialized using JSON.stringify() to catch any possible serialization related issues that might occur when using a network based storage provider.
const { MemoryStorage } = require('botbuilder');

const storage = new MemoryStorage();

Constructors

MemoryStorage([key: string]: string)

Creates a new MemoryStorage instance.

Methods

delete(string[])

Deletes storage items from storage.

read(string[])

Reads storage items from storage.

write(StoreItems)

Writes storage items to storage.

Constructor Details

MemoryStorage([key: string]: string)

Creates a new MemoryStorage instance.

new MemoryStorage(memory?: [key: string]: string)

Parameters

memory

[key: string]: string

(Optional) memory to use for storing items. By default it will create an empty JSON object {}.

Method Details

delete(string[])

Deletes storage items from storage.

function delete(keys: string[]): Promise<void>

Parameters

keys

string[]

Keys of the StoreItems objects to delete.

Returns

Promise<void>

A promise representing the async operation.

read(string[])

Reads storage items from storage.

function read(keys: string[]): Promise<StoreItems>

Parameters

keys

string[]

Keys of the StoreItems objects to read.

Returns

Promise<StoreItems>

The read items.

write(StoreItems)

Writes storage items to storage.

function write(changes: StoreItems): Promise<void>

Parameters

changes
StoreItems

The StoreItems to write, indexed by key.

Returns

Promise<void>

A promise representing the async operation.