How to automate WhatsApp reports for clients with AI
Each client's monthly report eats hours of agency time and tends to go out late. The API lets you build a small pipeline: a script collects verifiable numbers from each instance, an AI writes the summary in client-friendly language and the result goes to their WhatsApp or to the portal. This guide shows the pipeline with real calls from the documented API and ready-made prompts. Golden rule: the AI writes, the numbers come from the API, never from the model's imagination. ZapZap is an unofficial API.
Published on · 4 min read
The design: data from the API, text from the AI
Three steps. First, the script calls the API and gathers facts: the state of each instance, scheduled and completed campaigns with their counters, conversations with unread messages. Second, those facts go into a prompt that asks for a short summary, without adding any number. Third, the text goes to human review and then to the client.
The critical point is the separation. Language models get math wrong and invent context. If every number in the report comes from the script and the AI only writes it up, the worst error becomes a badly worded sentence, not a nonexistent sale in the report.
Collecting the data with the API
The script below lists the account's instances, and for each one reads the campaigns (GET sender/listfolders, which returns status and counters like log_total, log_delivered, log_read and log_failed) and the conversations with unread messages (POST chat/find, which returns chats with jid, name and unreadCount). Keep the key and secret in environment variables.
The exact fields of GET /instances are in the reference; the example uses id and name and should be adjusted to what your account's response returns. Sales results and ad lead results come from the portal and the Performance tab, or from your own system, not from this script.
Collect facts per instance (Node.js 18+)
const BASE = "https://api.zapzapapi.com/api/v1";
const headers = {
"Content-Type": "application/json",
"x-api-key": process.env.ZAPZAP_API_KEY,
"x-api-secret": process.env.ZAPZAP_API_SECRET,
};
async function call(path, init = {}) {
const r = await fetch(BASE + path, { headers, ...init });
if (!r.ok) throw new Error(path + " -> HTTP " + r.status);
return r.json();
}
const instances = await call("/instances"); // array of instances
const facts = [];
for (const inst of instances) {
const folders = await call("/" + inst.id + "/sender/listfolders"); // campaigns with counters
const chats = await call("/" + inst.id + "/chat/find", {
method: "POST",
body: JSON.stringify({ limit: 50, sort: "-wa_lastMsgTimestamp" }),
});
const unread = (chats.chats || []).filter((c) => c.unreadCount > 0).length;
facts.push({
instance: inst.name,
campaigns: folders.map((f) => ({ status: f.status, total: f.log_total, delivered: f.log_delivered, read: f.log_read, failed: f.log_failed })),
chats_with_unread: unread,
});
await new Promise((res) => setTimeout(res, 1500)); // pause between instances
}
console.log(JSON.stringify(facts, null, 2));The prompt that writes without inventing
Give the AI only the script's facts and a strict instruction. A prompt template that works: "You write the monthly WhatsApp summary for an agency client. Use only the JSON data below. Do not calculate percentages that are not in the data, do not cite numbers that are not in the JSON and, if a data point is missing, say it was not measured. Tone: clear, friendly, in English, for a non-technical reader. Structure: what happened, what deserves attention, suggested next step. Maximum 150 words."
Always ask for "suggested next step" instead of "conclusion": the report becomes a conversation about action. And review before sending: the report carries the agency's brand.
Delivering to the client
Two outputs. Through the client's WhatsApp, with POST /{instanceId}/send/text (see sending a message with curl), during business hours and only to those who asked to receive the report. Or through the client portal, which already shows leads, sales and performance under their brand, and the report becomes a text complement.
If the report is sent from the client's support number, treat it as an ordinary message: no advertising inside it and no agency or ZapZap branding the client did not ask for.
Privacy and limits
AI summaries of real conversations involve personal data. Do not send conversation content to a model without a legal basis and without a contract with the client; prefer aggregate counters, as in the example. The LGPD applies to the agency as processor, and the contract should say what is processed and where.
To build the pipeline with a coding agent, see build with AI: Claude Code, OpenAPI and MCP and the page on AI agents.
Quick summary
- The report's numbers come from the API; the AI only writes.
- GET sender/listfolders returns campaign status and counters; POST chat/find returns chats with unreadCount.
- The prompt forbids any number outside the JSON and says to state what was not measured.
- Review before sending and deliver through send/text or the client portal.
- Prefer aggregate data over conversation content, for privacy.
Keep reading
Also read
Frequently asked questions
Can the AI calculate the report's numbers?
It is not recommended. Calculate in the script and give the AI only the result. Language models can get math wrong and invent context.
Which endpoints does the script use?
GET /instances, GET /{instanceId}/sender/listfolders and POST /{instanceId}/chat/find, all in the API reference. Sending to the client uses POST /{instanceId}/send/text.
Can I send client conversations to an AI model?
Only with a legal basis and a clear contract with the client. Prefer aggregated, anonymized data.
Do I need a developer?
For the pipeline, it helps. A coding agent with the OpenAPI spec and llms.txt builds the first version, and a person reviews it.
Does the report replace the client portal?
No. The portal shows leads, sales and performance under the client's brand at any time, and the text report is a complement.
Build the first client's report
Create the account, generate the API key and run the guide's script. R$15 per active number per month, no per-message fee. Verify your phone and you get a welcome credit, subject to the current campaign.
