Outbound webhook

HTTPS JSON delivery contract with HMAC for integrators.

Destination Webhook in the Telegram bot: after the alert is rendered, the bot POSTs JSON to your HTTPS URL with an HMAC signature.

Public HTML copy (same file): PUBLIC_BASE_URL/webhook (fallback: this file on GitHub). The wizard setup step links here.

Source of truth for signing/payload shape: `outbound_webhook.py`.
Product plan (Max thin bot): `todo-max-messenger-bot.md`.

Runnable sample: `examples/outbound_webhook_receiver.py`.


Setup in the bot

  1. Create / edit an alert → Webhook.
  2. Paste a public https://… URL (no localhost / private IP).
  3. Bot generates a secret, sends a test POST, then shows the secret once — store it on your side.
  4. Live alerts use the same URL + secret.

Pin and delete-previous are not available for this destination.


Request

MethodPOST
URLyour HTTPS endpoint (port 443)
BodyUTF-8 JSON (compact: no extra spaces)
Content-Typeapplication/json; charset=utf-8
SignatureX-Bot-Signature: sha256=<hex> — HMAC-SHA256 of the raw body with your secret
Delivery idX-Bot-Delivery-Id: <uuid> (same as delivery_id in JSON)
User-Agenttwitch-telegram-bot-webhook/1

Success: respond `2xx` within ~20s. Anything else is a delivery failure (bot may retry once on 429; pauses destination on 401/403/404/410).

Signature

X-Bot-Signature = "sha256=" + hex(HMAC_SHA256(secret, raw_body_bytes))

Verify with a constant-time compare. Reject if the header is missing or wrong.

Idempotency

Treat delivery_id (header and/or JSON field) as unique. If you already accepted that id, return 200 again without re-sending to users.


Payload (schema_version: 1)

{
  "schema_version": 1,
  "delivery_id": "550e8400-e29b-41d4-a716-446655440000",
  "subscription_id": 42,
  "owner_id": 123456789,
  "alert_type": "live",
  "twitch_login": "marfapr",
  "twitch_user_id": "12345",
  "stream_id": "5123456789",
  "text": "<b>marfapr</b> is live — Just Chatting",
  "text_format": "html",
  "photo_url": "https://static-cdn.jtvnw.net/…",
  "buttons": [
    { "text": "Open", "url": "https://twitch.tv/marfapr" }
  ],
  "sent_at": "2026-11-10T15:00:00+00:00",
  "meta": {
    "vod_offset_seconds": null,
    "is_scheduled_repeat": false
  }
}
FieldNotes
alert_typee.g. live, end, category, upcoming, test (setup probe)
text_formatplain \html \markdown — matches how the Telegram template was rendered
photo_urloptional public image URL only (no multipart upload)
buttonslink buttons only (no callbacks)
meta.testtrue on the connectivity probe before save

Verify (Python)

import hashlib
import hmac
import json

SIGNATURE_HEADER = "X-Bot-Signature"
DELIVERY_ID_HEADER = "X-Bot-Delivery-Id"

def verify(raw_body: bytes, secret: str, signature_header: str) -> bool:
    expected = "sha256=" + hmac.new(
        secret.encode("utf-8"), raw_body, hashlib.sha256
    ).hexdigest()
    return hmac.compare_digest(expected, (signature_header or "").strip())

# In your handler:
# raw = request.get_data()          # raw bytes, not re-serialized JSON
# sig = request.headers.get(SIGNATURE_HEADER)
# if not verify(raw, WEBHOOK_SECRET, sig):
#     return "", 401
# payload = json.loads(raw)
# delivery_id = payload["delivery_id"]  # or DELIVERY_ID_HEADER
# if already_seen(delivery_id):
#     return "", 200
# process(payload); mark_seen(delivery_id)
# return "", 200

Or run the sample receiver:

export WEBHOOK_SECRET='paste-secret-from-bot'
python examples/outbound_webhook_receiver.py
# listens on http://127.0.0.1:8787/hooks/alerts — use a public HTTPS tunnel for real tests

Not in this contract

  • Raw Twitch EventSub / Helix events (alerts are already rendered)
  • Callback / “manage in bot” buttons
  • Discord Incoming Webhook format (dest_type=discord is separate)