class Tourmaline::Stage(T)
- Tourmaline::Stage(T)
- Reference
- Object
Overview
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
Defined in:
tourmaline/extra/stage.crConstructors
Class Method Summary
-
.enter(client, **options)
Create a new Stage instance and start it immediately
Instance Method Summary
-
#active? : Bool
True if this Stage is currently active
-
#await_response(&block : Context -> )
Allows you to await a response to a step, yielding the awaited update to the block.
-
#chat_id : Int::Primitive | Nil
The chat id that this stage applies to If nil, this stage will be usable across all chats
-
#chat_id=(chat_id : Int::Primitive | Nil)
The chat id that this stage applies to If nil, this stage will be usable across all chats
-
#chat_id? : Int::Primitive | Nil | Nil
The chat id that this stage applies to If nil, this stage will be usable across all chats
- #client : Client
-
#context : T
The context for this stage
-
#context=(context : T)
The context for this stage
-
#current_step : String | Nil
The key for the currently active step
-
#exit
Stop the current Stage and remove the event handler from the client.
-
#initial_step : String | Nil
The key to use for the initial step
-
#on(step, initial = false, &block : Client -> )
Add an event handler for the given step name using the supplied block
-
#on(step, proc : Client -> , initial = false)
Add an event handler for the given event name using the supplied proc
-
#on_exit(&block : T -> )
Add a handler that's called when this Stage is exited
-
#on_start(&block : -> )
Add a handler that's called when this Stage is started
-
#start
Start the current Stage, setting the given initial step as the current step and adding an event handler to the client.
-
#steps
A hash containing the steps in this stage
-
#transition(event)
Set the current step to the given value
-
#update_history : Array(Update)
Maintains a history of updates that match the given chat_id and/or user_id.
-
#user_id : Int::Primitive | Nil
The user id that this stage applies to If nil, this stage will be usable across all users
-
#user_id=(user_id : Int::Primitive | Nil)
The user id that this stage applies to If nil, this stage will be usable across all users
-
#user_id? : Int::Primitive | Nil | Nil
The user id that this stage applies to If nil, this stage will be usable across all users
Macro Summary
Constructor Detail
Create a new Stage instance
Class Method Detail
Instance Method Detail
Allows you to await a response to a step, yielding the awaited update to the block.
The chat id that this stage applies to If nil, this stage will be usable across all chats
The chat id that this stage applies to If nil, this stage will be usable across all chats
The chat id that this stage applies to If nil, this stage will be usable across all chats
Add an event handler for the given step name using the supplied block
Add an event handler for the given event name using the supplied proc
Start the current Stage, setting the given initial step as the current step and adding an event handler to the client.
Maintains a history of updates that match the given chat_id and/or user_id.
The user id that this stage applies to If nil, this stage will be usable across all users
The user id that this stage applies to If nil, this stage will be usable across all users
The user id that this stage applies to If nil, this stage will be usable across all users