Updates implementation for testing purposes.
This GenServer implements the updates interface for test environments. Instead of
fetching updates from Telegram, it provides push_update/2 to inject updates
directly into the bot's dispatcher.
The actual synchrony of handler execution depends on the bot's handler_mode:
:sync(default when usingExGram.Test.start_bot/3) - the handler runs inline within the dispatcher's process;push_update/2blocks until it completes.:async(production default) - the handler is spawned;push_update/2returns before the handler runs.
Configured with config :ex_gram, updates: ExGram.Updates.Test.
See the Testing guide for more details.
Summary
Functions
Returns a specification to start this module under a supervisor.
Callback implementation for GenServer.init/1.
Push an update through the bot's ExGram.Dispatcher pipeline.
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Callback implementation for GenServer.init/1.
Push an update through the bot's ExGram.Dispatcher pipeline.
The update is delivered via GenServer.call/2, so the dispatcher always receives it
synchronously. Whether this call blocks until the handler finishes depends on the
bot's handler_mode:
:sync(default fromExGram.Test.start_bot/3) - the handler runs inline inside the dispatcher'shandle_call, so this function returns only after the full pipeline has executed and all API calls have been made.:async- the handler is spawned in a separate process; this function returns as soon as the dispatcher has enqueued the update.
Process isolation is handled automatically by ExGram.Test.start_bot/3, which allows
the Dispatcher and Updates worker to use the test's stubs from startup. No manual
allow/2 call is needed before calling this function.
Parameters
bot_name- The bot's registered name (atom), which is also the Dispatcher's nameupdate- AnExGram.Model.Update.t/0struct
Example
update = %ExGram.Model.Update{
update_id: 1,
message: %ExGram.Model.Message{...}
}
# With handler_mode: :sync (default), the handler has completed when this returns
ExGram.Updates.Test.push_update(:my_bot, update)