Safe send: one message, exactly once
A reusable way to send a WhatsApp message from n8n, Make or your own code, and know for sure whether it went, even after a timeout.
The problem it solves
A workflow that runs with nobody watching will sooner or later lose an answer: a timeout, a restart, a network blip. Did the message go or not? Send again and the customer may get it twice. Do nothing and they may get nothing.
WhatSync gives you what you need to always know: an idempotency key that makes a repeat safe, a send status you can look up, and error codes that say plainly whether anything was sent. Safe send wires those together once, so every workflow can just call it.
The five rules
- One key per message. Use the webhook event's
idas theIdempotency-Key. The same event can then never produce two messages. - No answer? Send the same request again with the same key. WhatSync answers with the first send's result instead of sending twice. Never use a new key when you do not know what happened.
- A new key only when WhatSync says nothing was sent and the key is used up. That is
new_people_limitanddaily_limit_reached, after waiting forRetry-After. outcome_unknownmeans look it up. Callget_send_statuswitherror.intent_iduntil the status settles. If it staysunknown, a person checks the chat.- Everything else that is not a 200 goes to a person.
sending_off,whatsapp_not_connected,from_number_requiredandtool_errordo not fix themselves.
The full list of answers and what each one means is in Running WhatsApp unattended.
n8n: the safe send sub-workflow
- Download JSON
n8n: safe send (sub-workflow)
Import and publish this first. Every workflow that sends uses it.
Import it, pick your WhatSync API key credential in the two HTTP nodes (Send and Get send status), and publish it. n8n 2 will not publish a workflow that calls an unpublished sub-workflow, so publish this one first. New to importing? See WhatsApp workflows in n8n.
Other workflows call it with an Execute Sub-workflow node and three inputs:
{
"tool": "send_message",
"body": {
"channel": "qr",
"conversationId": "15550000001@s.whatsapp.net",
"text": "You are booked: 4 people on Saturday 28 November at 20:00."
},
"idempotencyKey": "evt_01M8EVPGWXX9JMQJZCFC2VRQYM"
}| Input | What to put there |
|---|---|
tool | send_message for a person, send_group_message for a group. Any send tool works. |
body | The tool's JSON body, without the key. See send_message and send_group_message. |
idempotencyKey | One stable value per message, 8 to 128 characters: letters, digits, dot, colon, underscore, hyphen. The webhook event id fits. |
It always answers with one item. It never throws, so one failed send cannot stop your workflow.
{
"outcome": "sent",
"ok": true,
"needs_human": false,
"retry_later": false,
"code": "accepted",
"message": "",
"http_status": 200,
"retry_after": null,
"intent_id": "4eb79793-bb82-597f-a553-a80a4dc86b50",
"operation_id": null,
"status": "accepted",
"delivery_status": null,
"delivery_errors": [],
"channel": "qr",
"idempotency_key": "evt_01M8EVPGWXX9JMQJZCFC2VRQYM",
"tries": 1
}| outcome | ok | What happened | What to do |
|---|---|---|---|
sent | true | WhatsApp accepted the message. On a personal number this is the final answer. | Nothing. |
delivered | true | Business API only: Meta confirmed it reached the phone. | Nothing. |
not_sent | false | Nothing was sent. code and message say why. | retry_later true: send again later with a new key. needs_human true: a person has to act. |
undelivered | false | Business API only: accepted, then Meta reported a delivery failure. delivery_errors has the reason. | A person looks. Do not resend blindly. |
unknown | false | WhatSync could not learn whether WhatsApp took the message. | A person checks the chat. Never resend automatically. |
What it does inside
| Node | What it does |
|---|---|
| Settings | whatsyncUrl, maxTries (5) and maxChecks (6). The only node you may want to edit. |
| Send | POST /api/v1/tools/{tool} with the Idempotency-Key header and a 30-second timeout. A timeout does not stop the workflow. |
| Decide | Reads the answer and picks: finished, send again, or look the send up. |
| Wait before sending again | Waits for Retry-After (rate limit) or 5, 15, 30, 60 seconds (no answer), then goes back to Send with the same key. |
| Get send status | get_send_status for a message, get_operation for a group or file send. |
| Decide from status | On a Business number it looks again after 2, 4, 8, 15, 30 and 60 seconds until Meta reports delivered, read or failed. |
| Result | The one item described above. |
To try it alone: open the workflow, put your own number in Test input, and click Execute workflow on the Try it by hand trigger.
Calling it from your workflow
Add an Execute Sub-workflow node, choose WhatSync: safe send from the list, and fill the three inputs. This example replies in the chat a webhook event came from:
tool send_message
body {{ { "channel": $json.data.message.channel, "conversationId": $json.data.message.conversation_id, "text": "Thanks, we got your message." } }}
idempotencyKey {{ $json.id }}After it, add an If node and an alert for a person. The alert can be Slack, email, Telegram or anything else that someone reads.
{{ $json.ok }} is false{{ JSON.stringify({ text: "A WhatsApp reply did NOT go out (" + $json.outcome + ", " + $json.code + "). " + $json.message }) }}When outcome is unknown, say so in the alert: the message may have gone, so the person should read the chat before sending anything by hand.
Make: the same pattern
- Download JSON
Make: reply safely to incoming messages (blueprint)
Custom webhook, HTTP module, Router, Sleep and the Break error handler.
Make has no sub-workflows, so the pattern is one HTTP module followed by a Router. Map the webhook's id into the Idempotency-Key header and leave Evaluate all states as errors switched off, so the Router can read the status code. The full walk-through is in WhatsApp scenarios in Make.
| Router route | Filter | Modules |
|---|---|---|
| Sent from a Business number | statusCode = 200 and data.channel = business | Sleep 10 s, get_send_status, alert if delivery_status = failed |
| Too fast: wait | statusCode = 429 and data.error.code = rate_limited | Sleep data.error.retry_after seconds, the same HTTP request again with the same key |
| Uncertain: look it up | statusCode = 409 and data.error.code = outcome_unknown | Sleep 15 s, get_send_status with data.error.intent_id, alert if status is not accepted |
| Refused: tell a person | anything else that is not 200 | Alert with data.error.code |
A network timeout raises an error in Make whatever the setting. Attach the Break error handler to the HTTP module with automatic completion on: Make then runs the module again with the same input, which means the same key.
The same steps with curl
Useful when you write your own code. Send with a key and a timeout a little longer than WhatSync's own wait for WhatsApp (20 seconds):
curl -X POST https://whatsync.app/api/v1/tools/send_message \
-H "Authorization: Bearer $WHATSYNC_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: evt_01M8EVPGWXX9JMQJZCFC2VRQYM" \
--max-time 30 \
-d '{"channel":"qr","conversationId":"15550000001@s.whatsapp.net","text":"You are booked: 4 people on Saturday 28 November at 20:00."}'HTTP/1.1 200 OK
{
"intent_id": "4eb79793-bb82-597f-a553-a80a4dc86b50",
"status": "accepted",
"recipient_phone": "15550000001",
"channel": "qr",
"provider_message_id": "3EB04B830865AF11D1C64E",
"delivery_status": null,
"delivery_status_at": null,
"delivery_errors": [],
"next_action": null,
"error": null,
"note": "WhatsApp accepted the message. Personal numbers send no delivery receipts, so this is the final answer; do not resend."
}No answer within 30 seconds? Run exactly the same command again. You get one of three answers: the 200 above (it went, once), a new send (the first request never arrived), or this:
HTTP/1.1 409 Conflict
{
"error": {
"code": "outcome_unknown",
"message": "The action may have been accepted. Inspect get_operation or get_send_status; do not retry with a new key.",
"intent_id": "5633a358-91a2-5701-a22e-e485b35b9eb8"
}
}Then look the send up with the intent_id from the error, and again a few seconds later, until status is accepted or failed:
curl -X POST https://whatsync.app/api/v1/tools/get_send_status \
-H "Authorization: Bearer $WHATSYNC_API_KEY" \
-H "Content-Type: application/json" \
-d '{"intentId":"5633a358-91a2-5701-a22e-e485b35b9eb8"}'A 429 rate_limited means nothing was sent. Wait for Retry-After seconds and send the same request with the same key:
HTTP/1.1 429 Too Many Requests
Retry-After: 48
{
"error": {
"code": "rate_limited",
"message": "This number already tried to send 5 messages in the last minute, so WhatSync held this one back and sent nothing. WhatsApp flags numbers that send many messages in a quick burst. It can go in about 48 seconds.",
"retry_after": 48
}
}How this was tested
The n8n sub-workflow was run on n8n 2.49 against the WhatSync API code with a stand-in for the phone connection and for Meta. Each of these ended the way the table above says, with exactly one message leaving the number or none:
- a normal send, and the same event delivered twice
- n8n timing out before any answer or intent id came back
- the phone connection hanging or failing mid-send
- seven sends in one minute against the limit of five
- two new people in a row, and a number linked under 24 hours ago
- sending switched off, a number that is not on WhatsApp, and the same text twice within the hour
- group sends, including a refused repeat and an uncertain one
- Business API: delivered, free text outside the 24-hour window, a template, a delivery failure reported later, and no receipt at all