createConversation
Takes a conversation builder function, and turns it into middleware that can be installed on your bot. This middleware registers the conversation on the context object. Downstream handlers can then enter the conversation using ctx
.
When an update reaches this middleware and the given conversation is currently active, then it will receive the update and process it. This advances the conversation.
If the conversation is marked as parallel, downstream middleware will be called if this conversation decides to skip the update.
You can pass a second parameter of type string to this function in order to give a different identifier to the conversation. By default, the name of the function is used.
bot.use(createConversation(example, "new-name"))
Optionally, instead of passing an identifier string as a second argument, you can pass an options object. It lets you configure the conversation. For example, this is how you can mark a conversation as parallel.
bot.use(createConversation(example, {
id: "new-name",
parallel: true,
}))
Note that this function 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 the given conversation. These two custom context types can never be identical because the outside middleware must have Conversation
Type Parameters
OC
OC extends Context
C
C extends Context
Parameters
builder
builder: ConversationBuilder<OC, C>
A conversation builder function
options
options?: string | ConversationConfig<C>
A different name for the conversation, or an options object