Guide

Webhooks vs polling

Two transports deliver updates to your bot. Polling is simpler; webhooks scale better. Start with polling, move to webhooks for production.

Polling

Call getUpdates in a loop with timeout: 50. The call hangs until an update arrives or 50 seconds pass. Confirm each batch by passing offset = last update_id + 1 on the next call; anything below the offset is never returned again.

polling loop (Python)
import requests

BASE = "https://api.sprintelex.com"
H = {"Authorization": "Bearer <bot-token>"}
offset = 0
while True:
    r = requests.post(f"{BASE}/getUpdates",
                      headers=H,
                      json={"offset": offset, "timeout": 50}).json()
    for u in r["result"]["updates"]:
        handle(u)  # your code here
        offset = u["update_id"] + 1
One poller per bot environment. Two pollers with the same token will split updates between them and both will miss messages. Never run polling and a webhook at the same time either: setting a webhook pauses polling delivery.

Webhooks

Give us an HTTPS URL and we POST every update to it as JSON. Set one with setWebhook:

curl
curl https://api.sprintelex.com/setWebhook \
  -H "Authorization: Bearer <bot-token>" \
  -H "Content-Type: application/json" \
  -d '{"url": "https://example.com/sprintex-webhook", "secret_token": "<random-string>"}'

Verifying deliveries

Every delivery carries two headers when you set a secret_token:

X-Sprintelex-Bot-Secret: <your secret_token, verbatim>
X-Sprintelex-Signature: sha256=<hex HMAC-SHA256(request body, secret_token)>

Check the signature on every request and reject anything that fails. Your endpoint must be HTTPS; plain HTTP is refused.

Retries

If your endpoint errors or times out, we retry with quadratic backoff (attempt² minutes between tries) for up to 24 hours, then the update is dead-lettered and dropped. A persistently failing endpoint gets disabled automatically, and the dashboard shows you the delivery log with status codes. Answer 200 fast and do slow work asynchronously.

Webhook URLs are re-resolved at delivery time. If your domain ever resolves to a private or internal address, deliveries pause and the webhook is disabled until you set a safe URL. This is SSRF protection; use a public host.

Which to choose

PollingWebhooks
SetupNone, works behind NATPublic HTTPS endpoint
LatencyUp to ~50s worst caseNear-instant
Best forDevelopment, prototypesProduction bots