DOCUMENTATION / EVENTS & WEBHOOKS
Stay in the loop.
Choose cursor-based polling or signed HTTPS webhooks for your bot’s event stream.
Polling with the SDK
bot.start() fetches the application and its team, then polls for updates. It processes events in order and acknowledges successful handlers. Listen for error to report failures. Only one active polling consumer should run for an application. Delivery is at least once; persist business operation IDs and use message nonces for idempotent work.
For crash-safe polling, provide loadCursor and saveCursor backed by your own durable store. Events expire after 24 hours, and only currently granted events are returned. Uninstalling or reducing a channel grant stops subsequent reads and delivery.
Events
ReadMessages is required for message events, ReadMembers for member/role events, and UseCommands for interactions. The SDK ignores messages authored by the same bot by default. Deleted message events contain an ID and deletion marker; queued copies are redacted.
| SDK event | Data |
|---|---|
| ready | Application identity |
| messageCreate / messageUpdate / messageDelete | message |
| memberJoin / memberLeave / memberUpdate | member |
| roleUpdate | member |
| communityCreate / communityDelete | Installation grant or community ID |
| interactionCreate | Interaction instance |
| giveawayEnd | Giveaway ID and winners |
| event | Raw BotEvent envelope |
| rateLimit / error | Retry delay or error |
Signed webhook delivery
Webhook mode requires the backend’s RELAY_BOT_WEBHOOK_SIGNING_KEY and cron job. The console reports whether signing is configured. Fetch the Ed25519 public key at /api/relay-bots/public-key. Verify X-Relay-Timestamp and X-Relay-Signature over timestamp + "." + the exact raw body. The SDK accepts a five-minute clock window. Deduplicate event IDs in durable storage to prevent replay.
Relay pins validated public DNS addresses for each delivery, requires HTTPS, rejects private addresses and redirects, limits responses to 64 KB, and times out after five seconds. Failed deliveries retry up to eight attempts with backoff within the 24-hour retention window. A successful delivery updates bot presence. Polling and webhooks are mutually exclusive.
import { verifyWebhookEvent } from '@relaychat/sdk';
// Preserve the exact raw request body before JSON parsing.
const event = verifyWebhookEvent(publicKey, request.headers, rawBody);
// Verify, persist the event ID, enqueue work, then return HTTP 2xx.
relay