conversations
Middleware for the conversations plugin.
This is the main thing you have to install in order to use this plugin. It performs various setup tasks for each context object, and it reads and writes to the data storage if provided. This middleware has to be installed before you can install create
with your conversation builder function.
You can pass an options object to the plugin. The most important option is called storage
. It can be used to persist conversations durably in any storage backend of your choice. That way, the conversations can survive restarts of your server.
conversations({
storage: {
type: "key",
version: 0, // change the version when you change your code
adapter: new FileAdapter("/home/bot/data"),
},
});
A list of known storage adapters can be found here.
It is advisable to version your data when you persist it. Every time you change your conversation function, you can increment the version. That way, the conversations plugin can make sure to avoid any data corruption caused by mismatches between state and implementation.
Note that the plugin takes two different type parameters. The first type parameter should corresopnd with the context type of the outside middleware tree. The second type parameter should correspond with the custom context type used inside all conversations. If you may want to use different context types for different conversations, you can simply use Context
here, and adjust the type for each conversation individually.
Be sure to read the documentation about the conversations plugin to learn more about how to use it.
Type Parameters
OC
OC extends Context
C
C extends Context
Parameters
options
options: ConversationOptions<OC, C>
Optional options for the conversations plugin