Postia API
IT
Console

Webhook

Postia chiama il tuo endpoint HTTPS quando succede qualcosa. Aggiungi gli endpoint nella console o con l'API; lo scope è webhooks:manage.

Eventi

EventoInviato quando
post.publishedUn post è stato pubblicato su un canale. Un evento per canale.
post.failedNon è stato possibile inviare un post a un canale.
channel.disconnectedUn canale ha perso l'accesso e deve essere ricollegato.
pingHai richiesto una consegna di prova.

Un endpoint creato con una chiave API riceve gli eventi sui post e sui canali del suo proprietario. Un endpoint creato da un'app OAuth riceve gli eventi sugli utenti che hanno autorizzato l'app, per gli eventi il cui scope è stato concesso.

{
  "id": "evt_0a1b2c3d4e5f60718293a4b5",
  "type": "post.published",
  "created_at": "2026-12-24T09:00:03Z",
  "data": {
    "post_id": "0191c1a4-8e2b-7c3d-9a10-5b7c2f1d3e44",
    "channel_id": "0191c1a4-1111-7c3d-9a10-5b7c2f1d3e44",
    "status": "published",
    "url": "https://t.me/example/42"
  }
}

Consegna

Verifica la firma

Postia-Signature ha la forma t=<unix seconds>,v1=<hex>. Il valore v1 è l'HMAC-SHA256 di <t>.<raw body>, con chiave il secret whsec_... dell'endpoint. Usa i byte grezzi, confronta in tempo costante e rifiuta un timestamp che si discosta di oltre 5 minuti dal tuo orologio. Il secret viene mostrato una sola volta, quando l'endpoint viene creato o il suo secret viene ruotato.

import { createHmac, timingSafeEqual } from "node:crypto";

// rawBody is the Buffer you received, before any JSON parsing.
export function verify(rawBody, header, secret) {
  const parts = Object.fromEntries(header.split(",").map((p) => p.split("=")));
  if (Math.abs(Date.now() / 1000 - Number(parts.t)) > 300) return false;
  const expected = createHmac("sha256", secret)
    .update(`${parts.t}.`).update(rawBody).digest("hex");
  const a = Buffer.from(expected), b = Buffer.from(parts.v1 || "");
  return a.length === b.length && timingSafeEqual(a, b);
}
import hashlib, hmac, time

def verify(raw_body: bytes, header: str, secret: str) -> bool:
    parts = dict(p.split("=", 1) for p in header.split(","))
    if abs(time.time() - int(parts["t"])) > 300:
        return False
    signed = parts["t"].encode() + b"." + raw_body
    expected = hmac.new(secret.encode(), signed, hashlib.sha256).hexdigest()
    return hmac.compare_digest(expected, parts.get("v1", ""))