Named GenServer process that receives updates, applies middlewares for the bot,
and calls the bot's ExGram.Handler.handle/2 callback.
This module is started automatically by the bot's supervisor and shouldn't be interacted with directly in most cases.
Handler Mode
The handler_mode option controls how the handler is executed after an update
arrives:
:async(default in production) - the handler is spawned in a separate process. The dispatcher returns immediately after receiving the update, and the handler runs concurrently.:sync- the handler runs inline inside the dispatcher'shandle_call. The caller blocks until the full pipeline (middlewares + handler + API calls) has completed.ExGram.Test.start_bot/3defaults to:syncso thatExGram.Test.push_update/2is fully synchronous in tests.
The handler_mode can be set as a bot startup option:
# In production (default)
MyApp.Bot.start_link(handler_mode: :async)
# In tests via ExGram.Test.start_bot/3 (default)
ExGram.Test.start_bot(context, MyApp.Bot)
# equivalent to:
ExGram.Test.start_bot(context, MyApp.Bot, handler_mode: :sync)
Summary
Functions
Returns a specification to start this module under a supervisor.
Types
@type custom_key() :: any()
@type parsed_message() :: {:command, key :: String.t() | custom_key(), ExGram.Model.Message.t()} | {:text, String.t(), ExGram.Model.Message.t()} | {:regex, key :: custom_key(), ExGram.Model.Message.t()} | {:location, ExGram.Model.Location.t()} | {:message, ExGram.Model.Message.t()} | {:callback_query, ExGram.Model.CallbackQuery.t()} | {:inline_query, ExGram.Model.InlineQuery.t()} | {:edited_message, ExGram.Model.Message.t()} | {:pinned_message, ExGram.Model.Message.t()} | {:update, ExGram.Model.Update.t()}
@type t() :: %ExGram.Dispatcher{ bot_info: ExGram.Model.User.t() | nil, bot_inits: [{module(), keyword()}], bot_module: module() | nil, commands: %{required(String.t()) => map()}, dispatcher_name: atom(), error_handler: {module(), atom()}, extra_info: map(), handler: {module(), atom()}, handler_mode: :sync | :async, init_opts: init_opts(), middlewares: [ExGram.Bot.middleware()], name: atom(), regex: [Regex.t()] }
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
@spec new(Enumerable.t()) :: t()
@spec start_link(t()) :: GenServer.on_start()