telega_hackney

hackney adapter for the Telega Telegram Bot Library.

Provides a TelegramClient that uses gleam_hackney as the HTTP backend.

import telega
import telega_hackney

pub fn main() {
  let client = telega_hackney.new("BOT_TOKEN")
  let assert Ok(_bot) =
    telega.new(client)
    |> telega.router(router)
    |> telega.start()
}

Values

pub const default_connect_timeout_ms: Int

How long hackney may wait to establish the connection, in milliseconds.

pub const default_timeout_ms: Int

How long hackney may wait for the response body, in milliseconds.

hackney’s own default is 5 seconds, which is shorter than the 30-second long poll Telega opens by default: every empty getUpdates ended in a timeout, the poller retried, and the bot quietly degraded to polling every 5 seconds. 60 seconds leaves the poll room to answer.

pub fn fetch_adapter(
  req: request.Request(String),
) -> Result(response.Response(String), error.TelegaError)

The hackney fetch adapter for JSON API requests.

Exposed so you can use it with client.set_fetch_client if needed.

pub fn fetch_adapter_with_timeout(
  timeout_ms timeout_ms: Int,
) -> fn(request.Request(String)) -> Result(
  response.Response(String),
  error.TelegaError,
)

fetch_adapter with an explicit response timeout in milliseconds.

pub fn fetch_bits_adapter(
  req: request.Request(BitArray),
) -> Result(response.Response(BitArray), error.TelegaError)

The hackney fetch adapter for binary file downloads.

Exposed so you can use it with client.set_fetch_bits_client if needed.

pub fn fetch_bits_adapter_with_timeout(
  timeout_ms timeout_ms: Int,
) -> fn(request.Request(BitArray)) -> Result(
  response.Response(BitArray),
  error.TelegaError,
)

fetch_bits_adapter with an explicit response timeout in milliseconds.

pub fn new(token token: String) -> client.TelegramClient

Create a new Telegram client using hackney as the HTTP backend.

This sets up both FetchClient (for JSON API calls) and FetchBitsClient (for binary file downloads).

pub fn new_with_timeout(
  token token: String,
  timeout_ms timeout_ms: Int,
) -> client.TelegramClient

new with an explicit response timeout (milliseconds).

Raise it above default_timeout_ms if you long-poll with a a polling.PollingSettings(timeout:) longer than ~55 seconds.

Search Document