Skip to content

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

  1. One key per message. Use the webhook event's id as the Idempotency-Key. The same event can then never produce two messages.
  2. 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.
  3. A new key only when WhatSync says nothing was sent and the key is used up. That is new_people_limit and daily_limit_reached, after waiting for Retry-After.
  4. outcome_unknown means look it up. Call get_send_status with error.intent_id until the status settles. If it stays unknown, a person checks the chat.
  5. Everything else that is not a 200 goes to a person. sending_off, whatsapp_not_connected, from_number_required and tool_error do not fix themselves.

The full list of answers and what each one means is in Running WhatsApp unattended.

n8n: the safe send sub-workflow

  • n8n: safe send (sub-workflow)

    Import and publish this first. Every workflow that sends uses it.

    Download JSON

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:

Input
{
  "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"
}
InputWhat to put there
toolsend_message for a person, send_group_message for a group. Any send tool works.
bodyThe tool's JSON body, without the key. See send_message and send_group_message.
idempotencyKeyOne 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.

Output
{
  "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
}
outcomeokWhat happenedWhat to do
senttrueWhatsApp accepted the message. On a personal number this is the final answer.Nothing.
deliveredtrueBusiness API only: Meta confirmed it reached the phone.Nothing.
not_sentfalseNothing 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.
undeliveredfalseBusiness API only: accepted, then Meta reported a delivery failure. delivery_errors has the reason.A person looks. Do not resend blindly.
unknownfalseWhatSync could not learn whether WhatsApp took the message.A person checks the chat. Never resend automatically.

What it does inside

NodeWhat it does
SettingswhatsyncUrl, maxTries (5) and maxChecks (6). The only node you may want to edit.
SendPOST /api/v1/tools/{tool} with the Idempotency-Key header and a 30-second timeout. A timeout does not stop the workflow.
DecideReads the answer and picks: finished, send again, or look the send up.
Wait before sending againWaits for Retry-After (rate limit) or 5, 15, 30, 60 seconds (no answer), then goes back to Send with the same key.
Get send statusget_send_status for a message, get_operation for a group or file send.
Decide from statusOn a Business number it looks again after 2, 4, 8, 15, 30 and 60 seconds until Meta reports delivered, read or failed.
ResultThe 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:

Execute Sub-workflow inputs
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.

If node condition
{{ $json.ok }}   is false
Alert text (HTTP Request body for a Slack incoming webhook)
{{ 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

  • Make: reply safely to incoming messages (blueprint)

    Custom webhook, HTTP module, Router, Sleep and the Break error handler.

    Download JSON

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 routeFilterModules
Sent from a Business numberstatusCode = 200 and data.channel = businessSleep 10 s, get_send_status, alert if delivery_status = failed
Too fast: waitstatusCode = 429 and data.error.code = rate_limitedSleep data.error.retry_after seconds, the same HTTP request again with the same key
Uncertain: look it upstatusCode = 409 and data.error.code = outcome_unknownSleep 15 s, get_send_status with data.error.intent_id, alert if status is not accepted
Refused: tell a personanything else that is not 200Alert 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):

1. Send
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."}'
Answer: accepted
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:

Answer: still sending, or uncertain
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:

2. Look it up
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:

Answer: too fast
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