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.
POST/v1/webhook_endpoints
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.

TypeSent when
lead.createdA visitor writes in the customer chat for the first time. It comes just before that message's message.received.
message.receivedA visitor sends a message in the customer chat.
message.sentOkaymate or the team answers a visitor.

The event object

  • idstring
    Unique identifier for the event, evt_ and 24 characters. Also in the Okaymate-Event-Id header.
  • objectstring
    Always event.
  • typestring
    The event type.
    lead.createdmessage.receivedmessage.sent
  • created_atstring
    When the event happened, ISO 8601.
  • businessstring
    The ID of the business it happened on.
  • testboolean
    true on a test event only, left out on the others.
  • dataobject
    The 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

lead.created
{
  "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"
    }
  }
}

message.received

A visitor sends a message in the customer chat.

Data

  • leadobject
    The lead, its object, id and name. Use its id with Retrieve a lead for the rest.
  • messageobject
    The visitor's message, its direction set to in.
message.received
{
  "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"
    }
  }
}

message.sent

Okaymate or the team answers a visitor.

Data

  • leadobject
    The lead, its object, id and name. Use its id with Retrieve a lead for the rest.
  • messageobject
    The answer, a message with its direction set to out.
message.sent
{
  "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.

HeaderValue
Okaymate-SignatureThe timestamp and the signature, t=1764000000,v1=5f2b...
Okaymate-Event-IdThe event's id, to skip events you already handled.
Okaymate-Event-TypeThe event's type.
User-AgentOkaymate-Webhooks/1.0
Request
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=58ca5e964b92d617c979d3f067cdc2035a1a1a9d3f848d7d927c2db09b8e9baa

Verify signatures

Anyone can send a request to your URL. Check that each one comes from Okaymate before you trust it.

  1. Read the raw body as bytes, before any JSON parsing. Parsing and writing it again changes the bytes.
  2. Split the Okaymate-Signature header on commas. t is a Unix time in seconds, v1 the signature.
  3. 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.
  4. Compare it to v1 in constant time.
  5. Refuse a t more than 5 minutes away from your clock, so an old request cannot be replayed. Each retry is signed with a fresh t.

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.

AttemptSent
1Right away
21 minute after the previous failure
35 minutes after the previous failure
430 minutes after the previous failure
52 hours after the previous failure
66 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 in Okaymate-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 test set to true in your real work, they come from a test.