Developer docs
Integrate WHAASS into your CRM or helpdesk
Log WhatsApp conversations on your CRM contacts or helpdesk tickets, and reply from there, with webhooks and four API calls.
This guide connects one WHAASS account to a CRM or helpdesk in both directions. Customer messages appear on the right contact or ticket, and agents reply without leaving your tool. It takes a webhook handler and four endpoints.
Tip: Building this for several clients, as an agency or SaaS? Each client account gets its own API key and webhook. Read WhatsApp API for agencies and SaaS for how to set up the Meta side.
The data you map
| WHAASS | Your CRM or helpdesk |
|---|---|
Chat id |
An external ID on the contact or ticket. It's the key for everything else. |
Chat phone |
Contact phone, in international format |
Chat name |
Contact name, if you don't have one yet |
Message id (WhatsApp wamid) |
An external ID on the activity or comment, so duplicates are skipped |
Message direction |
inbound = from the customer, outbound = from your business |
1. Backfill existing conversations
Page through chats, then each chat's messages. Store each chat's id on the matching contact (match on phone).
const API = "https://waas-api.hitoritech.com/api/v1/external";
const headers = { "x-api-key": process.env.WHAASS_KEY };
for (let page = 1; ; page++) {
const { data: chats, pagination } = await fetch(`${API}/chats?page=${page}&limit=100`, { headers }).then(r => r.json());
for (const chat of chats) {
const contact = await crm.upsertContactByPhone(chat.phone, { name: chat.name, whaassChatId: chat.id });
const { data: messages } = await fetch(`${API}/chats/${chat.id}/messages?limit=100`, { headers }).then(r => r.json());
for (const m of messages) await crm.logActivity(contact, m.id, m.direction, m.content, m.timestamp);
}
if (page * pagination.limit >= pagination.total) break;
}
Mind the rate limit: 600 requests per 15 minutes per key. For a large account, run the backfill slowly or overnight.
2. Receive new messages as they arrive
Register a webhook and handle two events:
message.received: find the contact bychatId(or create one fromfromandname), log the message, and open or update a ticket.message.status: mark the logged outbound message asdeliveredorread, matched onid.
Skip any X-Whaass-Event-Id you've already handled, because retries can send the same event twice.
3. Reply from your tool
When an agent replies on a contact or ticket, send it through WHAASS:
await fetch(`${API}/messages/text`, {
method: "POST",
headers: { ...headers, "Content-Type": "application/json" },
body: JSON.stringify({ phone: contact.phone, text: reply }),
});
If the customer's last message was more than 24 hours ago, free text fails with Meta error 131047. Offer the agent a template instead, from List templates, and send it with Send a template message.
4. Keep unread counts in step
When an agent opens the conversation in your tool, call Mark chat as read so the WHAASS inbox doesn't show it as unread to the rest of the team.
Working alongside the WHAASS chatbot and inbox
Your integration and WHAASS see the same conversation. Replies sent from the WHAASS inbox come back to you as outbound messages when you list a chat's messages, so log them too. If a WHAASS chatbot answers first, decide where a human takes over. Bot-to-human handoff on WhatsApp covers the options.
Checklist before going live
- Chat
idstored on every contact, and lookups use it rather than the phone - Webhook signature checked on the raw body, with events older than 5 minutes rejected
- Duplicate events skipped by
X-Whaass-Event-Id - A template fallback when the 24-hour window has closed
- API key kept on the server, one key per integration