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 eventData
readyApplication identity
messageCreate / messageUpdate / messageDeletemessage
memberJoin / memberLeave / memberUpdatemember
roleUpdatemember
communityCreate / communityDeleteInstallation grant or community ID
interactionCreateInteraction instance
giveawayEndGiveaway ID and winners
eventRaw BotEvent envelope
rateLimit / errorRetry 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.

JavaScript
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.