class Tourmaline::Stage(T)
inherits Reference
#
FSM (Finite-state machine) like functionality for Tourmaline in the form of a Stage. Stage allows you to create conversations/wizards which maintain their own state for a particular user and/or chat.
For an example of a stage bot, check out examples/stage_bot.cr
Constructors#
.new(client : Tourmaline::Client, *, context : T, chat_id = nil, user_id = nil, **handler_options)
#
(client : Tourmaline::Client, *, context : T, chat_id = nil, user_id = nil, **handler_options)
Create a new Stage instance
Class methods#
Methods#
#await_response(&block : Context -> )
#
(&block : Context -> )
Allows you to await a response to a step, yielding the awaited update to the block.
#chat_id : Int::Primitive?
#
: Int::Primitive?
The chat id that this stage applies to If nil, this stage will be usable across all chats
#chat_id=(chat_id : Int::Primitive?)
#
(chat_id : Int::Primitive?)
The chat id that this stage applies to If nil, this stage will be usable across all chats
#chat_id? : Int::Primitive | Nil?
#
: Int::Primitive | Nil?
The chat id that this stage applies to If nil, this stage will be usable across all chats
#on(step, proc : Client -> , initial = false)
#
(step, proc : Client -> , initial = false)
Add an event handler for the given event name using the supplied proc
#on(step, initial = false, &block : Client -> )
#
(step, initial = false, &block : Client -> )
Add an event handler for the given step name using the supplied block
#start
#
Start the current Stage, setting the given initial step as the current step and adding an event handler to the client.
#update_history : Array(Update)
#
: Array(Update)
Maintains a history of updates that match the given chat_id and/or user_id.
#user_id : Int::Primitive?
#
: Int::Primitive?
The user id that this stage applies to If nil, this stage will be usable across all users
#user_id=(user_id : Int::Primitive?)
#
(user_id : Int::Primitive?)
The user id that this stage applies to If nil, this stage will be usable across all users
#user_id? : Int::Primitive | Nil?
#
: Int::Primitive | Nil?
The user id that this stage applies to If nil, this stage will be usable across all users