createConversation<CTX extends Context> function
Middleware<CTX>
createConversation<CTX extends Context>(
- String name,
- ConversationFunction<
CTX> conversationFn
Creates a middleware that registers a conversation function.
This should be used after installing the ConversationPlugin.
Example:
bot.use(createConversation('greeting', greetingConversation));
Implementation
Middleware<CTX> createConversation<CTX extends Context>(
String name,
ConversationFunction<CTX> conversationFn,
) {
return (ctx, next) async {
// Register the conversation function with the plugin instance
final plugin = ConversationPlugin.getInstance<CTX>();
if (plugin != null) {
plugin.registerConversation(name, conversationFn);
} else {
throw TeleverseException(
'ConversationPlugin not installed',
description:
'Install ConversationPlugin before registering conversations',
type: TeleverseExceptionType.invalidParameter,
);
}
await next();
};
}