telega/polling

Long polling implementation for Telegram Bot API.

This module provides an alternative to webhooks for receiving updates. The polling system uses a worker actor that continuously fetches updates from Telegram and dispatches them to the bot’s message handlers.

Types

Opaque type representing a running poller instance

pub opaque type Poller

Status of the poller

pub type PollerStatus {
  Starting
  Running
  Stopped
  Failed(String)
}

Constructors

  • Starting
  • Running
  • Stopped
  • Failed(String)

Messages for the polling worker actor

pub type PollingMessage {
  StartPolling(offset: option.Option(Int))
  StopPolling
  PollNext(offset: Int)
  InjectUpdates(updates: List(types.Update), offset: Int)
  SetSelf(subject: process.Subject(PollingMessage))
  HandleError(error: error.TelegaError, offset: Int)
}

Constructors

Values

pub fn calculate_new_offset(
  updates: List(types.Update),
  current_offset: Int,
) -> Int

Calculate the next offset based on received updates

pub fn get_config_info(
  poller: Poller,
) -> #(Int, Int, List(String), Int)

Get the polling configuration metadata

pub fn get_status(poller: Poller) -> PollerStatus

Get the current status of the poller

pub fn is_running(poller: Poller) -> Bool

Check if poller is running

pub fn start_polling(
  telega: telega.Telega(session, error),
  timeout timeout: Int,
  limit limit: Int,
  allowed_updates allowed_updates: List(String),
  poll_interval poll_interval: Int,
) -> Result(Poller, error.TelegaError)

Start polling with a Telega bot instance

pub fn start_polling_default(
  telega: telega.Telega(session, error),
) -> Result(Poller, error.TelegaError)

Start polling with default configuration

pub fn start_polling_with_offset(
  telega: telega.Telega(session, error),
  offset: Int,
  timeout timeout: Int,
  limit limit: Int,
  allowed_updates allowed_updates: List(String),
  poll_interval poll_interval: Int,
) -> Result(Poller, error.TelegaError)

Start polling with a custom offset

pub fn stop(poller: Poller) -> Nil

Stop polling

pub fn wait_finish(poller: Poller) -> Nil

Wait for the poller to finish This function blocks indefinitely until the polling worker stops

Search Document