Quick start
In six steps: send a WhatsApp template from your own code, hear the customer's reply the moment it arrives, and answer it automatically.
You need#
- A CAT Engage business that is approved, with WhatsApp connected.
- At least one approved WhatsApp template (Settings → Templates).
- A server that can receive HTTPS requests. For testing, a tunnel to your computer works.
Steps#
Create a key
In Integrations → API keys, create a key with
messages:send,contacts:readandwebhooks:manage. Save it asCAT_ENGAGE_API_KEYon your server.Check it
cURLcurl https://app.catengage360.com/api/v1/me \ -H "Authorization: Bearer cat_live_your_key_here"You should see your business name,
"status": "active"and the three scopes.Send a template
Use your own number first, so you see what the customer sees.
GET /templateslists your approved templates and how many values each needs.cURLcurl -X POST https://app.catengage360.com/api/v1/messages \ -H "Authorization: Bearer cat_live_your_key_here" \ -H "Content-Type: application/json" \ -d '{ "to": "+919876543210", "type": "template", "template": { "name": "order_update", "params": [ "A-1042" ] } }'Register a webhook
Tell us where to send new messages. Save the secret from the answer as CAT_WEBHOOK_SECRET; it is shown only once.
cURLcurl -X POST https://app.catengage360.com/api/v1/webhooks \ -H "Authorization: Bearer cat_live_your_key_here" \ -H "Content-Type: application/json" \ -d '{ "url": "https://example.com/cat-webhooks", "events": [ "message.received" ] }'Receive and answer
This small Node.js server checks the signature, answers at once, looks up who wrote and sends a reply. The reply is free text, which works because the customer just wrote to you.
Node.jsimport crypto from 'node:crypto'; import express from 'express'; const API = 'https://app.catengage360.com/api/v1'; const KEY = process.env.CAT_ENGAGE_API_KEY; const SECRET = process.env.CAT_WEBHOOK_SECRET; const auth = { Authorization: 'Bearer ' + KEY, 'Content-Type': 'application/json' }; const app = express(); app.post('/cat-webhooks', express.raw({ type: 'application/json' }), async (req, res) => { const raw = req.body.toString('utf8'); if (!verify(req.get('X-Cat-Signature') ?? '', raw)) return res.sendStatus(401); res.sendStatus(200); // answer within 10 seconds, then work const event = JSON.parse(raw); if (event.event !== 'message.received') return; // Who wrote? Look the contact up, then reply on WhatsApp. const contact = await fetch(`${API}/contacts/${event.data.contact_id}`, { headers: auth }).then((r) => r.json()); await fetch(`${API}/messages`, { method: 'POST', headers: auth, body: JSON.stringify({ to: contact.data.phone, text: 'Thanks! We got your message and will reply shortly.' }), }); }); function verify(header, raw) { const p = Object.fromEntries(header.split(',').map((kv) => [kv.slice(0, kv.indexOf('=')).trim(), kv.slice(kv.indexOf('=') + 1).trim()])); const t = Number(p.t); if (!Number.isFinite(t) || !p.v1 || Math.abs(Date.now() / 1000 - t) > 300) return false; const expected = crypto.createHmac('sha256', SECRET).update(`${t}.${raw}`).digest('hex'); return expected.length === p.v1.length && crypto.timingSafeEqual(Buffer.from(expected), Buffer.from(p.v1.toLowerCase())); } app.listen(3000);Try it
Reply to the template from your phone. Your server gets the webhook and your phone gets the answer, and the whole conversation is in the CAT Engage inbox for your team.
Not getting webhooks?