Functions

delete-webhook

fn (request: DeleteWebhookRequest): Bool
fn (request: DeleteWebhookRequest, opts: Map): Bool

deleteWebhook - Remove the webhook integration. Set drop_pending_updates: true to discard any pending updates.

Example

::updates ::telegram::updates

::updates/delete-webhook(::updates/DeleteWebhookRequest({drop_pending_updates: true}))

get-updates

fn (request: GetUpdatesRequest): Vec<Map>
fn (request: GetUpdatesRequest, opts: Map): Vec<Map>

getUpdates - Receive incoming updates via long polling. Use offset to acknowledge processed updates (set to last update_id + 1). timeout (in seconds) enables long polling (recommended: 30). limit (1-100) controls batch size.

Example

::updates ::telegram::updates

response ::updates/get-updates(::updates/GetUpdatesRequest({
  timeout: 30,
  limit: 10
}))
// => [{update_id: 123, message: {chat: {id: ...}, text: "hello"}}, ...]

get-webhook-info

fn (): Map
fn (opts: Map): Map

getWebhookInfo - Get current webhook status. Returns the webhook URL, pending update count, last error, and allowed update types.

Example

::updates ::telegram::updates

response ::updates/get-webhook-info()
response.url                    // => "https://myapp.hot.dev/telegram/webhook"
response.pending_update_count   // => 0
response.last_error_date        // => null (no errors)

set-webhook

fn (request: SetWebhookRequest): Bool
fn (request: SetWebhookRequest, opts: Map): Bool

setWebhook - Register a URL to receive incoming updates via webhook. Telegram will POST JSON updates to this URL.

For a self-signed certificate, pass its public key as certificate: ::telegram::api/input-file(pem-bytes, "cert.pem") (uploaded as multipart). Set secret_token (1-256 characters: A-Z, a-z, 0-9, _, -) to receive it in the X-Telegram-Bot-Api-Secret-Token header for verification. allowed_updates filters which update types are delivered (e.g. ["message", "callback_query"]).

Example

::updates ::telegram::updates

::updates/set-webhook(::updates/SetWebhookRequest({
  url: "https://myapp.hot.dev/telegram/webhook",
  secret_token: "my-secret-token",
  allowed_updates: ["message", "callback_query", "inline_query"]
}))

verify-request

fn (request: Map): Bool
fn (request: Map, secret: Str): Bool

Verify a Telegram webhook request using the secret token. Returns true if the X-Telegram-Bot-Api-Secret-Token header matches the expected secret.

Unlike Slack/Discord which use HMAC signatures, Telegram uses a simple shared secret comparison. Set secret_token when calling setWebhook, then verify incoming requests with this function.

Uses the telegram.webhook.secret context variable by default, or accepts an explicit secret as a second argument.

Example

check fn (request: ::hot::http/HttpRequest): Bool {
  // Using context variable (1-arity)
  a ::telegram::updates/verify-request(request)

  // With explicit secret (2-arity)
  b ::telegram::updates/verify-request(request, "my-secret-token")
  and(a, b)
}
Context Vars: telegram.webhook.secret

Types

DeleteWebhookRequest

DeleteWebhookRequest type {
    drop_pending_updates: Bool?
}

GetUpdatesRequest

GetUpdatesRequest type {
    offset: Int?,
    limit: Int?,
    timeout: Int?,
    allowed_updates: Vec<Str>?
}

SetWebhookRequest

SetWebhookRequest type {
    url: Str,
    certificate: ::telegram::api/InputFile?,
    ip_address: Str?,
    max_connections: Int?,
    allowed_updates: Vec<Str>?,
    drop_pending_updates: Bool?,
    secret_token: Str?
}