Sexy.Bot.Poller (Sexy v0.10.2)

Copy Markdown View Source

GenServer that polls Telegram for updates and routes them to Sexy.Bot.Session callbacks.

Started automatically as a child of Sexy.Bot. Each incoming update is dispatched through Sexy.Bot.Dispatcher partitions, so a malformed update or a crashing handler can never kill the polling loop.

Delivery semantics

Updates are confirmed to Telegram on the poll after they were dispatched, and the offset survives poller restarts — so delivery is at-least-once: after a crash in the confirmation window a batch can be dispatched twice. Handlers with side effects (payments!) should be idempotent, e.g. deduplicate by update_id.

Updates of the same chat are processed in order (they land in the same dispatcher partition); different chats run concurrently.

Routing rules

Update typeConditionSession callback
messagetext starts with /handle_command/1
messageotherwisehandle_message/1
callback_querydata starts with /_deletebuilt-in: deletes the message
callback_querydata starts with /_transitbuilt-in: deletes + handle_transit/3
callback_queryotherwisehandle_query/1
messagehas successful_paymenthandle_successful_payment/1
pre_checkout_queryhandle_pre_checkout/1
poll / poll_answerhandle_poll/1
my_chat_memberhandle_chat_member/1

Built-in routes

  • /_delete mid=<id> — deletes message with given id, answers the callback
  • /_transit mid=<id>-cmd=<command>-... — deletes message, answers callback, then calls Session.handle_transit(chat_id, command, query_params)

Callback data is client-controlled: malformed built-in routes (missing mid/cmd) are answered with a no-op instead of raising.

Summary

Functions

apply_chat_member(u)

apply_command(u)

apply_message(u)

apply_poll(u)

apply_pre_checkout(u)

apply_query(u)

apply_successful_payment(u)

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

init(atom)

Callback implementation for GenServer.init/1.

start_link(g)

update()