Nadia.Polling (nadia v1.3.0)

View Source

Supervised long polling runtime for Nadia bots.

Add it to a supervision tree with a handler module:

children = [
  {Nadia.Polling,
   client: Nadia.Client.from_config(:support),
   handler: MyApp.SupportBot,
   allowed_updates: ["message", "callback_query"],
   timeout: 30}
]

The runtime calls Nadia.get_updates/2, dispatches updates sequentially through Nadia.Dispatcher, and advances the offset only after each update is handled successfully. Handler {:error, reason} returns and exceptions are treated as failed dispatches: polling backs off and retries from the failed update without dispatching later updates in the batch.

Summary

Functions

Starts a polling process.

Types

handler()

@type handler() :: module() | [Nadia.Dispatcher.route()]

option()

@type option() ::
  {:allowed_updates, [binary()] | binary()}
  | {:api, module() | {module(), term()}}
  | {:backoff_ms, non_neg_integer()}
  | {:bot, atom()}
  | {:bot_username, binary()}
  | {:client, Nadia.Client.t() | atom() | nil}
  | {:handler, handler()}
  | {:limit, pos_integer()}
  | {:log_errors, boolean()}
  | {:max_backoff_ms, non_neg_integer()}
  | {:offset, integer()}
  | {:poll_interval_ms, non_neg_integer()}
  | {:timeout, non_neg_integer()}

Functions

start_link(opts)

@spec start_link([option()]) :: GenServer.on_start()

Starts a polling process.

:handler is required and may be a module implementing Nadia.Handler or an ordered route list accepted by Nadia.Dispatcher.