class Tourmaline::Stage(T)

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:

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(client : Client, *, context : T, chat_id = nil, user_id = nil, group = nil, history = true, **handler_options) #

Create a new Stage instance


Class Method Detail

def self.enter(*args, **options) #

Create a new Stage instance and start it immediately


Instance Method Detail

def active? : Bool #

True if this Stage is currently active


def await_response(&block : Update -> ) #

Allows you to await a response to a step, yielding the awaited update to the block.


def chat_id : Int::Primitive? #

The chat id that this stage applies to If nil, this stage will be usable across all chats


def chat_id=(chat_id : Int::Primitive?) #

The chat id that this stage applies to If nil, this stage will be usable across all chats


def chat_id? : Int::Primitive | Nil? #

The chat id that this stage applies to If nil, this stage will be usable across all chats


def client : Client #

The client instance this stage is attached to


def context : T #

The context for this stage


def context=(context : T) #

The context for this stage


def current_step : String? #

The key for the currently active step


def exit #

Stop the current Stage and remove the event handler from the client.


def history? : Bool #

True if update history is being recorded


def initial_step : String? #

The key to use for the initial step


def on(step, initial = false, &block : Client -> ) #

Add an event handler for the given step name using the supplied block


def on(step, proc : Client -> , initial = false) #

Add an event handler for the given event name using the supplied proc


def on_exit(&block : T -> ) #

Add a handler that's called when this Stage is exited


def on_start(&block : -> ) #

Add a handler that's called when this Stage is started


def start #

Start the current Stage, setting the given initial step as the current step and adding an event handler to the client.


def steps #

A hash containing the steps in this stage


def transition(event) #

Set the current step to the given value


def update_history : Array(Update) #

Maintains a history of updates that match the given chat_id and/or user_id. The first update will be the one that initiated this Stage.


def user_id : Int::Primitive? #

The user id that this stage applies to If nil, this stage will be usable across all users


def user_id=(user_id : Int::Primitive?) #

The user id that this stage applies to If nil, this stage will be usable across all users


def user_id? : Int::Primitive | Nil? #

The user id that this stage applies to If nil, this stage will be usable across all users