Receive webhooks

Send Platica events to your system: new messages, open cases or approved templates. Register your receiver URL and choose the events it needs.

A webhook sends a JSON POST to your server when something happens in Platica. Every delivery is signed with HMAC-SHA256 so you can check it.

Before you start

You need your Platica API key in PLATIC_API_KEY and a webhook receiver with a public HTTPS URL. For local development, you can use a tunnel.

To configure it from the platform, see Send events by webhook.

  1. Choose the events

    List the events you can subscribe to. There are 29, in 9 categories: conversations, messages, comments, contacts (clients in the API), ads, WhatsApp Flows, cases, WhatsApp templates and AI providers. (List events)

    import { Platic } from "platic-sdk";
    
    const platic = new Platic({ apiKey: process.env.PLATIC_API_KEY! });
    
    const { events } = await platic.webhooks.events();
    console.log(events);

    All events include id, event, workspaceId, timestamp, source, resourceType, resourceId, changes and data. See Payloads for the content of data for each event.

  2. Create the webhook

    Give it a name, your URL, the events and a signing secret. In the same call Platica stores the credentials as secrets, checks that your URL answers and, if it does, turns the webhook on. (Create a webhook)

    const webhook = await platic.webhooks.create({
      name: "CRM",
      url: "https://acme.com/webhooks/platica",
      events: ["message.created", "case.created"],
      secret: process.env.PLATIC_WEBHOOK_SECRET,
    });
    console.log(webhook.status, webhook.nextStep);

    Save the response's id in WEBHOOK_ID and keep the secret on your server. It accepts up to 255 characters and is stored as a workspace secret; reads don't return its value. The url must be public HTTPS.

    You can include up to 10 headers in every delivery. Headers with credentials are also stored as secrets. If you change the URL to another domain, authorize those credentials again.

    If the URL doesn't pass the check, the webhook is saved anyway, inactive (status: "draft"), and the response is still 201: see the next step.

  3. Test it and reactivate it

    If your server wasn't ready, fix it and verify again. Platica sends a HEAD request to your URL (it waits up to 15 seconds) and, if it passes, leaves the webhook active. It doesn't send any event. Don't create the webhook again. (Test a webhook)

    const checked = await platic.webhooks.test(webhook.id);
    console.log(checked.status, checked.nextStep);

    A status below 500 passes, also 404 or 405, because many servers only accept POST. A 5xx or no answer doesn't.

Handle deliveries

  • Verify X-Webhook-Signature using the secret and original body bytes before processing the event. See Delivery and signatures.
  • Store each event's id and skip events already processed. You may receive the same event more than once.
  • Respond with 2xx promptly, then do the slow work.

The SDK example includes a complete server.

Check it worked

Use Get the webhook to check that status is enabled and active is true. Trigger an event you subscribed to: for example, send a message with Talk to your agent. Find the event on your server and check lastDeliveryStatus in Platica.

A delivery fails if your server responds with 5xx, takes more than 15 seconds or cannot be reached. A 4xx response counts as delivered.

By default, the webhook pauses after 5 consecutive failures. Configure autoPause by count, { "mode": "failures", "failures": 5 } (5 to 1000), or time, { "mode": "time", "hours": 24 } (1 to 168). Owners and admins receive a notice. Fix the server and call Test a webhook to reactivate it.

Next steps