Capture WhatsApp activity
Use messaging webhooks to log inbound and outbound WhatsApp messages in real time, track delivery status, and build conversation threads in your system.
Overview
This guide shows you how to capture WhatsApp activity from an Aircall line into your own system. By the end, your integration logs every inbound and outbound message, keeps delivery status current, and reconstructs full conversation threads.
Aircall pushes this activity to you through webhooks. There is no REST endpoint for fetching message history, so webhooks are the only way to get WhatsApp data out of Aircall: once you register one, Aircall sends your server a POST request each time a message is sent, received, or has its delivery status updated. Your system becomes the record — start listening before the messages you care about are exchanged.
⚠️ Before continuing, make sure you've read WhatsApp overview.
This guide covers lines in Native mode. Numbers configured for Proxy mode deliver inbound messages and status updates to the
callbackUrlset in the number configuration instead — messaging webhooks do not fire for those lines. See Send WhatsApp messages (Skipping-inbox).
Prerequisites
- An Aircall account that meets the WhatsApp messaging requirements
- API credentials — an API ID and token (Basic Auth), or an OAuth access token
- A publicly accessible HTTPS endpoint to receive webhook events
Register a webhook for messaging events
Register a webhook with the POST /v1/webhooks endpoint, subscribing to the three message events.
const createWebhook = async (accessToken) => {
const res = await fetch('https://api.aircall.io/v1/webhooks', {
method: 'POST',
headers: {
'Authorization': `Bearer ${accessToken}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
custom_name: 'YOUR_APP_NAME',
url: 'https://your-app.example.com/aircall/webhook',
events: ['message.received', 'message.sent', 'message.status_updated']
})
});
if (!res.ok) {
console.error('Failed to create webhook:', await res.text());
throw new Error(`Webhook creation failed: ${res.status}`);
}
const { webhook } = await res.json();
// Store webhook.token against your user record
return webhook.token;
};Save the webhook token. Each event payload carries a token field matching the webhook that produced it. Compare it against the token you stored to identify which Aircall account an event belongs to, and to ignore requests that don't match. See Build event-driven integrations with webhooks to learn more.
Receive and process events
Set up a POST endpoint that accepts webhook payloads. Respond with 200 immediately and run processing asynchronously so Aircall doesn't time out waiting. Because the subscription also delivers SMS and MMS events, filter on the channel field before handling.
import express from 'express';
const app = express();
app.use(express.json());
app.post('/aircall/webhook', (req, res) => {
res.sendStatus(200);
const { event, token, data } = req.body;
if (token !== process.env.AIRCALL_WEBHOOK_TOKEN) return;
// SMS and MMS events arrive on the same subscription.
// We only want to process WhatsApp events here, so we check the channel.
if (data.channel !== 'whatsapp') return;
processWhatsAppEvent(event, data).catch(console.error);
});
const processWhatsAppEvent = async (event, message) => {
switch (event) {
case 'message.received':
case 'message.sent':
await upsertMessage(message);
break;
case 'message.status_updated':
await updateMessageStatus(message.id, message.status);
break;
}
};
app.listen(3000);Working with WhatsApp events
Inbound messages
A message.received event fires when a customer messages your line. The payload carries everything you need to store the message and link it to a person: the text in body, the sender in external_number, and the channel to identify if the message is from WhatsApp or SMS. When the customer sends an attachment, the file arrives in media_details, described below.
Message media
When a customer sends an attachment, the message.received payload carries a media_details array. The body field holds the caption when the customer adds one.
Each entry has three fields:
file_name— the name of the file Aircall stored, for exampleb0c1d2e3-4f56-4789-a012-3456789abcde.jpegfile_type— the MIME type, for exampleimage/jpegpresigned_url— a signed link to the file on Aircall media storage
The array is absent when the message carries no media. It is not null, and it is not empty. Treat a missing media_details as no attachment.
Download the file when the event arrives.
presigned_urlis created when the message reaches Aircall and expires at midnight UTC of the next day. The window can be as short as a few minutes, so a download retried against a stored URL fails. Download the file, store it in your own system, and keep the stored copy rather than the link.
const storeMedia = async (message) => {
for (const media of message.media_details ?? []) {
const res = await fetch(media.presigned_url);
if (!res.ok) {
console.error(`Download failed for ${message.id}/${media.file_name}: ${res.status}`);
continue;
}
await storage.put(`${message.id}/${media.file_name}`, res.body, {
contentType: media.file_type
});
}
};Aircall accepts these attachment types on a native WhatsApp line: jpeg, jpg, png, aac, amr, mp3, m4a, ogg, mp4, 3gp, txt, xls, xlsx, doc, docx, ppt, pptx, pdf, vcf. Aircall drops an attachment of any other type from media_details, and the message still arrives. WhatsApp sends stickers as WebP. WebP is not in this list, so a sticker is dropped from media_details.
Aircall applies no size limit to inbound media. Meta's limits apply: images up to 5 MB, documents including PDF up to 100 MB, and audio and video up to 16 MB.
Username conversations. When the customer is addressed by WhatsApp username instead of a phone number, the event is
whatsapp_username_message.received. It carries the samemedia_detailsarray.
Outbound messages
Outbound messages arrive through message.sent event, with the sending agent in user. When the message is a template (type is template), the payload also carries template_content — the template's name, category, language, and resolved components. The body already holds the final text the customer received, so store it directly rather than reconstructing it from the template.
const upsertMessage = async (message, direction) => {
await db.messages.upsert({
id: message.id,
direction, // 'inbound' or 'outbound', from the event
type: message.type, // 'text' or 'template'
body: message.body,
externalNumber: message.external_number, // the customer
lineId: message.number.id,
agentId: message.user?.id ?? null, // present on outbound messages
templateName: message.template_content?.name ?? null,
createdAt: message.created_at
});
};Message direction. Neither
message.receivednormessage.sentincludes adirectionfield. The event name is the only signal —message.receivedis inbound,message.sentis outbound — so the handler passes 'inbound' or 'outbound' intoupsertMessagerather than reading it from message.
The 24-hour service window. Inbound payloads include
whatsapp_service_window_closing_time— the point after which WhatsApp's 24-hour customer service window closes. Store it if your integration needs to know whether it can send a free-form reply or must fall back to a template.
Delivery tracking
After an outbound message leaves your line, message.status_updated events report its progress — for example, a status of read.
The payload is lean: it carries the message id, status, channel, number, and external_number, but no body. Because it references the same id as the original message.sent, update the row you already stored to keep one record per message with its latest delivery state.
const updateMessageStatus = async (id, status) => {
await db.messages.update(id, { status });
};Updated 3 days ago