1. Register a webhook
- Issue a key with webhooks:manage and the event-specific read scope.
- Use the admin console or POST /api/developer/v1/webhooks.
- Provide a public HTTPS endpoint on port 443; private network addresses are blocked.
- Choose message.created (requires messages:read) or room.presence (requires rooms:read).
- Copy the one-time signing secret into your server secret manager.
# Requires webhooks:manage + messages:read on the key.
# Returns a signing secret ONCE; store it in your server secret manager.
curl -X POST 'https://chat.egytag.com/api/developer/v1/webhooks' \
-H "Authorization: Bearer $CHAT_LIVE_API_KEY" \
-H 'Content-Type: application/json' \
-d '{"url":"https://hooks.example.com/chat-live","events":["message.created"]}'2. Payload and signature
Each POST contains JSON fields id, event, occurredAt and data. Headers: X-ChatLive-Timestamp (Unix seconds), X-ChatLive-Signature (sha256=...), X-ChatLive-Event and X-ChatLive-Delivery. Compute HMAC-SHA256 over the exact timestamp, a dot and the raw HTTP request body.
- message.created includes room, message ID, nickname, kind, body and created timestamp with a messages:read scope.
- room.presence contains only the room slug and online count, not account identifiers.
- Integration-authored messages include integration=true.
3. Verify the signature in Node.js
Verify signatures before processing. Reject timestamps outside five minutes, use timingSafeEqual and deduplicate delivery id for at-least-once delivery.
import crypto from 'node:crypto';
import express from 'express';
const app = express();
// Install once: npm install express
// Keep raw bytes: parsing then stringifying invalidates signatures.
app.post('/chat-live', express.raw({ type: 'application/json' }), (req, res) => {
const seconds = Number(req.get('X-ChatLive-Timestamp'));
const signature = req.get('X-ChatLive-Signature') || '';
if (!Number.isInteger(seconds) || Math.abs(Date.now()/1000-seconds)>300) {
return res.sendStatus(401);
}
const payload = Buffer.concat([Buffer.from(String(seconds)+'.'),req.body]);
const expected = 'sha256='+crypto.createHmac('sha256',
process.env.CHAT_LIVE_WEBHOOK_SECRET).update(payload).digest('hex');
const a = Buffer.from(signature), b = Buffer.from(expected);
if (a.length !== b.length || !crypto.timingSafeEqual(a,b)) {
return res.sendStatus(401);
}
const event = JSON.parse(req.body.toString('utf8'));
// Deduplicate event.id before processing it in your queue.
console.log(event.event, event.id);
res.sendStatus(204);
});
app.listen(3000);4. Retries and status
HTTP 2xx marks success. Failures retry up to five attempts with increasing backoff. Delivery logs are retained seven days and message idempotency records 30 days; a Super Admin may replay a failed delivery in the console. Respond 2xx quickly and do heavy work in your own queue.
5. Security
Never trust an unverified payload. The sender blocks private IP destinations, checks DNS before each delivery, pins the validated IP, and does not follow redirects. Keep the webhook secret outside source control.