Webhooks
Mesachat uses webhooks to receive messages from external platforms.
Telegram Webhooks
Endpoint
POST /webhooks/telegram/:botId
How It Works
- When a Telegram integration is created, Mesachat registers the webhook URL with Telegram's Bot API
- Telegram sends message updates to this URL
- Mesachat processes the message through the bot's configured agents
Security
Webhooks can be secured with a secret token:
- Set
webhookSecretTokenin integration settings - Telegram includes this token in the
X-Telegram-Bot-Api-Secret-Tokenheader - Mesachat validates the token before processing
Webhook Registration
Mesachat handles webhook registration automatically:
- On integration create — Registers webhook with Telegram
- On integration update — Updates webhook if URL changed
- On integration delete — Removes webhook from Telegram
- Deduplication — Calls
getWebhookInfo()beforesetWebhook()to avoid repeated registrations - Rate limiting — Exponential backoff for Telegram 429 responses
Clerk Webhooks
Endpoint
POST /api/webhooks/clerk
Purpose
Syncs user data from Clerk to Mesachat's database:
| Event | Action |
|---|---|
user.created | Creates Mesachat user |
user.updated | Updates Mesachat user |
user.deleted | Removes Mesachat user |
organization.* | Syncs tenant data |
organizationMembership.* | Syncs memberships |
Setup
- In Clerk Dashboard → Webhooks → Add Endpoint
- URL:
https://your-domain/api/webhooks/clerk - Events: Select all user and organization events
- Copy signing secret to
CLERK_WEBHOOK_SECRETenv var
Custom Webhooks
Coming Soon
Custom webhook endpoints for programmatic integrations are planned for a future release.