Webhooks
Webhooks
Okaymate sends an HTTPS request to your server the moment a visitor writes in your customer chat for the first time, sends a message or gets an answer, signed so you know it comes from us.
Set up an endpoint
Add an endpoint in the app on the API page, or with Create a webhook endpoint. Give it a public HTTPS URL and the event types you want, and keep the secret it returns to verify signatures.
- HTTPS only, on port 443 or 8443, no credentials in the URL, and only public addresses.
- Up to 10 endpoints per business.
- A disabled endpoint gets no events until you turn it back on.
- Send a test event to check your server before real events arrive.
curl -X POST https://okaymate.ai/api/v1/webhook_endpoints \
-H "Authorization: Bearer $OKAYMATE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"url": "https://example.com/webhooks/okaymate",
"events": ["lead.created", "message.received"],
"description": "Helpdesk sync"
}'Event types
Every event has the same envelope. Its data depends on its type.
| Type | Sent when |
|---|---|
lead.created | A visitor writes in the customer chat for the first time. It comes just before that message's message.received. |
message.received | A visitor sends a message in the customer chat. |
message.sent | Okaymate or the team answers a visitor. |
The event object
- idstringUnique identifier for the event,
evt_and 24 characters. Also in theOkaymate-Event-Idheader. - objectstringAlways
event. - typestringThe event type.
lead.createdmessage.receivedmessage.sent - created_atstringWhen the event happened, ISO 8601.
- businessstringThe ID of the business it happened on.
- testboolean
trueon a test event only, left out on the others. - dataobjectThe event's content, which depends on its type.
lead.created
A visitor writes in the customer chat for the first time. It comes just before that message's message.received.
Data
- leadobject
{
"id": "evt_8kQ2vXr4LmT9wPz1Hc6YbN3d",
"object": "event",
"type": "lead.created",
"created_at": "2026-11-24T09:12:44.000Z",
"business": "Bk7Qm2xWpL",
"data": {
"lead": {
"object": "lead",
"id": "k3v9q2m7x4w8n1p6",
"name": "Emma"
}
}
}{
"id": "evt_8kQ2vXr4LmT9wPz1Hc6YbN3d",
"object": "event",
"type": "message.received",
"created_at": "2026-11-24T09:12:44.000Z",
"business": "Bk7Qm2xWpL",
"data": {
"lead": {
"object": "lead",
"id": "k3v9q2m7x4w8n1p6",
"name": "Emma"
},
"message": {
"object": "message",
"id": "a8f3k2m9q1",
"lead": "k3v9q2m7x4w8n1p6",
"direction": "in",
"author": "Emma",
"text": "Hi, do you have a class for beginners on Saturday morning?",
"files": [],
"created_at": "2026-11-24T09:12:44.000Z"
}
}
}{
"id": "evt_8kQ2vXr4LmT9wPz1Hc6YbN3d",
"object": "event",
"type": "message.sent",
"created_at": "2026-11-24T09:12:51.000Z",
"business": "Bk7Qm2xWpL",
"data": {
"lead": {
"object": "lead",
"id": "k3v9q2m7x4w8n1p6",
"name": "Emma"
},
"message": {
"object": "message",
"id": "b2n7x4w8p5",
"lead": "k3v9q2m7x4w8n1p6",
"direction": "out",
"author": "Lumen Studio",
"text": "Yes, Beginners Flow runs every Saturday at 10am. Want me to save you a spot?",
"files": [],
"created_at": "2026-11-24T09:12:51.000Z"
}
}
}Delivery
Okaymate sends each event as a JSON POST and waits 10 seconds for your answer. Any 2xx counts as delivered. A redirect, any other status, a timeout or a connection error counts as a failure, and the event is retried.
| Header | Value |
|---|---|
Okaymate-Signature | The timestamp and the signature, t=1764000000,v1=5f2b... |
Okaymate-Event-Id | The event's id, to skip events you already handled. |
Okaymate-Event-Type | The event's type. |
User-Agent | Okaymate-Webhooks/1.0 |
POST /webhooks/okaymate HTTP/1.1
Content-Type: application/json
User-Agent: Okaymate-Webhooks/1.0
Okaymate-Event-Id: evt_8kQ2vXr4LmT9wPz1Hc6YbN3d
Okaymate-Event-Type: message.received
Okaymate-Signature: t=1763975564,v1=58ca5e964b92d617c979d3f067cdc2035a1a1a9d3f848d7d927c2db09b8e9baaVerify signatures
Anyone can send a request to your URL. Check that each one comes from Okaymate before you trust it.
- Read the raw body as bytes, before any JSON parsing. Parsing and writing it again changes the bytes.
- Split the
Okaymate-Signatureheader on commas.tis a Unix time in seconds,v1the signature. - Compute the HMAC SHA256 of
t, a dot and the raw body, keyed with the endpoint's whole secret,whsec_included, and write it in hex. - Compare it to
v1in constant time. - Refuse a
tmore than 5 minutes away from your clock, so an old request cannot be replayed. Each retry is signed with a fresht.
Answer 400 when the check fails. Keep the secret in an environment variable like OKAYMATE_WEBHOOK_SECRET.
const crypto = require("crypto");
const express = require("express");
// rawBody: the request body exactly as received, before any JSON parsing.
function verifyOkaymateSignature(rawBody, header, secret, toleranceSeconds = 300) {
if (typeof header !== "string") return false;
let timestamp = null;
const signatures = [];
for (const part of header.split(",")) {
const [key, value] = part.split("=", 2).map((s) => (s || "").trim());
if (key === "t") timestamp = value;
if (key === "v1" && value) signatures.push(value);
}
if (!/^\d+$/.test(timestamp || "") || signatures.length === 0) return false;
if (Math.abs(Date.now() / 1000 - Number(timestamp)) > toleranceSeconds) return false;
const expected = crypto.createHmac("sha256", secret).update(`${timestamp}.`).update(rawBody).digest();
return signatures.some((signature) => {
const given = Buffer.from(signature, "hex");
return given.length === expected.length && crypto.timingSafeEqual(given, expected);
});
}
const app = express();
// The body must stay raw on this route.
app.post("/webhooks/okaymate", express.raw({ type: "application/json" }), (req, res) => {
const ok = verifyOkaymateSignature(
req.body,
req.get("Okaymate-Signature"),
process.env.OKAYMATE_WEBHOOK_SECRET,
);
if (!ok) return res.status(400).send("Invalid signature");
const event = JSON.parse(req.body.toString("utf8"));
// Already handled? Skip it, retries send the same event.id again.
if (event.type === "lead.created") {
// event.data.lead is the new visitor
} else if (event.type === "message.received") {
// event.data.lead and event.data.message, the visitor's
} else if (event.type === "message.sent") {
// event.data.lead and event.data.message, the answer
}
res.sendStatus(200);
});
app.listen(3000);Retries
When a delivery fails, Okaymate tries again 5 times, each time after a longer wait. After the 6th attempt, about 9 hours after the first, the delivery is marked failed.
| Attempt | Sent |
|---|---|
| 1 | Right away |
| 2 | 1 minute after the previous failure |
| 3 | 5 minutes after the previous failure |
| 4 | 30 minutes after the previous failure |
| 5 | 2 hours after the previous failure |
| 6 | 6 hours after the previous failure |
A test event is sent once and never retried. An endpoint disabled or deleted meanwhile gets no more attempts.
Best practices
- Answer 2xx within 10 seconds, then do the work in a queue.
- Delivery is at least once. Use the event
id, also inOkaymate-Event-Id, to skip an event you already handled. - Events can arrive out of order. Compare
created_at, or fetch the lead again for its latest state. - Verify every signature and refuse old timestamps.
- Skip the events with
testset totruein your real work, they come from a test.