ConversationOptions
Optional configuration options for the conversations plugin.
Note that this configuration object takes two different types of custom context types. The first type parameter should corresopnd with the context type of the outside middleware tree. It is used to connect to external storages.
The second type parameter should correspond with the custom context type used inside all conversations. It is used if you define a list of default plugins to be installed in every conversation you use. If the list of plugins differs between conversations, you may want to use different context types for them. In that case, you should use a context type for only those plugins that are shared between all conversations, or avoid a list of default plugins entirely.
Properties
storage
storage?: ConversationStorage<OC, ConversationData>;
Defines how to persist and version conversation data in between replays. Most likely, you will want to use this option, as your data is lost otherwise.
Data can be stored based on a context object, or based on a key derived from the context object. See Conversation
Defaults to an in-memory implementation of the storage. This means that all conversations will be left when your process terminates.
Defaults to storing data per chat based on ctx
.
plugins
plugins?: Middleware<C>[];
List of default plugins to install for all conversations.
Each conversation will have these plugins installed first. In addition, each conversation will have the plugins installed that you specify explicitly when using enter
Methods
onEnter
onEnter(id: string, ctx: OC): unknown | Promise<unknown>;
Called when a conversation is entered via ctx
.
onExit
onExit(id: string, ctx: OC): unknown | Promise<unknown>;
Called when a conversation is left via ctx
or conversation
.
Note that this callback is not called when a conversation exists normally by returning or by throwing an error. If you wish to execute logic at the end of a conversation, you can simply call the callback directly.