telega_httpc

httpc adapter for the Telega Telegram Bot Library.

Provides a TelegramClient that uses gleam_httpc as the HTTP backend.

import telega
import telega_httpc

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

Values

pub const default_timeout_ms: Int

How long a single HTTP call may take, in milliseconds.

It has to outlast a long poll: Telega asks getUpdates to hold the connection open for 30 seconds by default, and httpc’s own 30-second default races that — the response and the timeout arrive together. 60 seconds leaves the poll room to answer.

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

The httpc 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 timeout in milliseconds.

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

The httpc 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 timeout in milliseconds.

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

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

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

pub fn new_with_default_limits(
  token token: String,
) -> Result(client.TelegramClient, error.TelegaError)

Create an httpc client that paces itself by Telegram’s documented limits: 30 requests per second overall, 1 per second to any one private chat and 20 per minute to any one group. See client.new_with_default_limits.

pub fn new_with_queue(
  token token: String,
) -> Result(client.TelegramClient, error.TelegaError)

Create a new Telegram client with httpc and default request queue.

The older name for new_with_default_limits; the two are the same call.

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

new with an explicit per-call HTTP timeout (milliseconds).

Raise it above default_timeout_ms if you long-poll with a a polling.PollingSettings(timeout:) longer than ~55 seconds; lower it only for bots that never poll.

Search Document