Use cases
Cash on delivery order confirmation over WhatsApp
When a cash on delivery order arrives, send the buyer a WhatsApp poll with Confirm and Cancel, then read the vote from a HelloHop webhook and update the order. Ship only confirmed orders. Message only buyers who agreed to WhatsApp updates, and let a plain reply of 1 or 2 work as well.
Facts (as of October 2026, API v1)
- A poll goes out with POST
/v1/sessions/{channel}/messagesand type poll. The response carries the message id, and a vote arrives as a message event of type poll_vote with that id in poll.poll_id. - poll.selected holds the chosen options by name. A vote with poll.unresolved above 0, or with poll.unreadable true, is a vote you could not fully read, so send it to a person. A poll_vote counts only for a poll you sent, from the buyer you asked.
- A new webhook receiver gets message events by default. Add message.status to its events list to also get delivery and read receipts.
- The unified POST
/v1/sessions/{channel}/messagesroute accepts an Idempotency-Key of up to 255 characters. Repeating the same key and body within 24 hours returns the first result without another send, with the response header Idempotent-Replayed: true. - A 504 send_unconfirmed, a timeout, a 409 idempotency_uncertain or a 503 with ambiguous true means the message may have gone out. Treat it as possibly delivered and look at the chat before you send it again.
- The free sandbox channel allows 180 messages sent a day and 10 new chats a month, counted in Bangkok time. That is enough to build and test the whole flow before you pay.
- Prices: from $20 USD per number per month, billed annually, with a free sandbox and no per-message fees.
Steps
- Detect a cash on delivery order. Check the field your store uses for the payment method. WooCommerce uses payment_method cod. In Shopify the gateway name is on the order, and it depends on how you set up cash on delivery.
- Send the poll. Call HelloHop with type poll, the question and the options Confirm and Cancel. Save the returned message id next to the order id.
- Receive the vote. Set a webhook receiver for message events. On a poll_vote, look up the order by poll.poll_id and read poll.selected.
- Update the order. Mark the order confirmed or canceled in your shop. Anything you cannot read goes to a person.
The job: ship only orders the buyer will accept
Cash on delivery orders fail when nobody is home or the buyer changed their mind. One question before dispatch, answered with one tap, stops the orders a buyer no longer wants before they ship. A poll gives the buyer two choices to tap. A plain reply of 1 or 2 covers buyers who answer in text.
The flow in your own code
| Step | Where it runs | Call |
|---|---|---|
| Order created | Your shop webhook receiver | POST /v1/sessions/{channel}/messages with type poll |
| Buyer taps Confirm or Cancel | A message event with type poll_vote reaches your receiver | |
| Order updated | Your own code | Your shop or database update |
Ask, then read the answer (Node.js)
The question text is an example. Write your own wording before you use it. The helpers named in the sample, such as saveAsk, saveEvent and answerOrder, are the parts that talk to your own shop and database.
import crypto from 'node:crypto';
import express from 'express';
const API = 'https://api.hellohop.app/v1';
const { CHANNEL_ID, CHANNEL_TOKEN } = process.env;
// One send. Repeating the same key with the same body returns the first result.
async function sendWhatsApp(key, message) {
try {
const res = await fetch(`${API}/sessions/${CHANNEL_ID}/messages`, {
method: 'POST',
headers: {
Authorization: `Bearer ${CHANNEL_TOKEN}`,
'Content-Type': 'application/json',
'Idempotency-Key': key,
},
body: JSON.stringify(message),
signal: AbortSignal.timeout(15000),
});
const data = await res.json().catch(() => ({}));
const result = { status: res.status, code: data.code, ambiguous: data.ambiguous, id: data.id };
if (classify(result) === 'retry') {
// 429 whatsapp_rate_limited carries no Retry-After, so it falls back to 1 second. This helper waits at most 30 seconds;
// a longer Retry-After is not slept through: result.retryAt (Unix ms) says when the row is due, and your sweep or timer retries then.
const h = res.headers.get('Retry-After');
const ms = Math.max(0, (h ? (/^\d+$/.test(h) ? Number(h) * 1000 : Date.parse(h) - Date.now()) : 1000) || 1000);
result.retryAt = Date.now() + ms;
await new Promise((resolve) => setTimeout(resolve, Math.min(30000, ms)));
}
return result;
} catch {
return { status: 0 }; // timeout or lost connection: the message may have gone out
}
}
// One answer per send: sent (server_ack), queued, retry, unknown or failed.
function classify({ status, code, ambiguous }) {
if (status === 200) return 'sent'; // server_ack, not delivered
if (status === 202) return 'queued'; // observe webhooks, do not resend
// Refused before sending: repeat the same key and body later.
const refused = ['upstream_unavailable', 'hopsmart_settings_unavailable', 'operator_unresolved'];
if (status === 429 || (status === 503 && (ambiguous === false || refused.includes(code)))) return 'retry';
// Possibly sent: look at the chat, never resend.
if (status === 0 || status >= 500 || code === 'idempotency_uncertain') return 'unknown';
return 'failed'; // an unlinked channel, idempotency_conflict, a bad request: fix it, do not retry
}
// Part 1: your shop calls this when a COD order is created (from your own webhook receiver
// or an n8n, Make or Zapier step). Send one poll and remember which order and buyer it belongs to.
async function askToConfirm(order) {
if (!(await hasWhatsAppConsent(order))) return; // your own record of who agreed
const sent = await sendWhatsApp(`cod-confirm-${order.id}`, {
type: 'poll',
to: order.phone, // digits with country code, for example 66XXXXXXXXX
question: `Order ${order.number}: please confirm your cash on delivery order`,
options: ['Confirm', 'Cancel'],
});
// Your own table: poll message id -> order id and buyer number, plus the outcome of the send.
// retry: the helper waited at most 30 seconds; schedule the same key AND body at sent.retryAt or later.
// queued: save the id and observe webhooks. unknown: look at the chat first.
await saveAsk(order.id, order.phone, sent.id, classify(sent));
}
// Part 2: the receiver for webhook events of type message.
const app = express();
const { WEBHOOK_SECRET } = process.env;
if (!WEBHOOK_SECRET || WEBHOOK_SECRET.length < 24) throw new Error('Set WEBHOOK_SECRET to the receiver secret (24 characters or more) before you start');
function validSignature(raw, header) {
const expected = crypto.createHmac('sha256', WEBHOOK_SECRET).update(raw).digest('hex');
return typeof header === 'string' && header.length === expected.length &&
crypto.timingSafeEqual(Buffer.from(header), Buffer.from(expected));
}
async function processAnswer(event) {
const m = event.payload;
let orderId = null;
let answer = null;
if (m.type === 'poll_vote') {
const p = m.poll || {};
// A readable vote for exactly one named option, on a poll we sent, from the buyer we asked.
if (p.unreadable || p.unresolved > 0 || p.selected?.length !== 1) return;
const ask = await orderForPoll(p.poll_id); // { orderId, phone } or null
if (!ask || ask.phone !== m.sender_jid.split('@')[0]) return;
orderId = ask.orderId;
answer = { Confirm: 'confirmed', Cancel: 'canceled' }[p.selected[0]];
} else if (m.type === 'text') {
// Only a text reply may fall back to the buyer's one open COD order (null when there are several).
answer = { '1': 'confirmed', '2': 'canceled' }[m.text.trim()];
orderId = await openCodOrderFor(m.sender_jid);
}
if (!orderId || !answer) return; // anything else goes to a person
// One transaction: set the status only while the order is still waiting, and mark the event done.
await answerOrder(orderId, answer, event.id);
}
app.post('/webhooks/whatsapp', express.raw({ type: 'application/json' }), async (req, res) => {
if (!validSignature(req.body, req.get('X-HelloHop-Signature'))) return res.sendStatus(401);
const event = JSON.parse(req.body.toString('utf8'));
if (event.type !== 'message' || event.payload.from_me) return res.sendStatus(200);
try {
await saveEvent(event.id, req.body.toString('utf8')); // durable first; the event id is the unique key
} catch {
return res.sendStatus(500); // the webhook is delivered again
}
res.sendStatus(200);
processAnswer(event).catch(console.error); // a failure leaves the event unfinished for a timer to re-run
});
app.listen(3001);Register the receiver
curl -X PUT "https://api.hellohop.app/v1/sessions/$CHANNEL_ID/webhooks" \
-H "Authorization: Bearer $CHANNEL_TOKEN" \
-H "Content-Type: application/json" \
-d '{"receivers":[{"url":"https://example.com/webhooks/whatsapp","events":["message"],"secret":"REPLACE_WITH_24_PLUS_CHARACTERS"}]}'The poll by hand
API=https://api.hellohop.app/v1
curl -s -X POST "https://api.hellohop.app/v1/sessions/$CHANNEL_ID/messages" \
-H "Authorization: Bearer $CHANNEL_TOKEN" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: cod-confirm-ORDER_ID" \
-d '{"type":"poll","to":"66XXXXXXXXX","question":"Order 1001: please confirm your cash on delivery order","options":["Confirm","Cancel"]}'What the handler does with each send result
| Send result | What your handler does |
|---|---|
| 200 server_ack | WhatsApp acknowledged the send. Mark it sent and save id; this is not a delivery receipt. |
| 202 queued | Persisted in the queue, not delivered. A channel that queues its sends (for example while accepted sends drain) answers every text send this way, with id, status queued, position and expires_at. Mark it queued and save id. Observe the result through webhooks without resending. |
| 429, or 503 with ambiguous false or code upstream_unavailable, hopsmart_settings_unavailable or operator_unresolved | Refused before sending. Honor Retry-After, keep the same key and body, and retry later. The Node helper waits at most 30 seconds before returning retry with a retryAt time, and the pages that keep a due time skip the row until then; the other Node timer pages retry on their next run. The Flask, Python reminder and PHP samples return the time to retry instead of waiting; the Sheets helper saves next_attempt_at and skips the row until then. |
| 504 send_unconfirmed, 409 idempotency_uncertain, 503 with ambiguous true, a timeout or a lost response | Possibly delivered. Mark it unknown and look at the chat before any resend. Never force a resend of an uncertain key with a new key. |
| 409 idempotency_conflict | The same key was used for a different message. Fix how you build the key. The first message is unchanged. |
| Any other 409 | Mark it failed. Fix the channel before scheduling another attempt. |
| Other 4xx | The request is wrong and a retry will not fix it. Log it and move on. |
Subscribe to message and message.status webhooks and verify their signatures. The result of a queued send arrives as a message event: match the saved response id to payload.id. message.status reports delivered or read for each id in payload.ids. A send held by HopSmart™ expires 72 hours after acceptance, and the 202 carries expires_at. If no event arrives, read the job with GET /hopsmart/jobs/{id}. Save event ids to deduplicate. Do not resend queued work while waiting for a result.
Send only to buyers who agreed
Ask for agreement to WhatsApp updates at checkout and store it with the order. Message only buyers who agreed, and keep to one question about their own order. If a buyer replies with anything other than a confirm or cancel answer, hand the chat to a person.
Common mistakes
- Sending the poll again because a response timed out. Check the chat first.
- Applying a vote twice. Save the event id, and change the order and finish the event in one transaction.
- Letting a vote from an unknown poll, or any option other than Confirm or Cancel, change an order. Only a text reply may fall back to the open order.
- Trusting a vote with unresolved above 0. Route it to a person.
- Skipping signature verification on the receiver.
Questions
- How do I know which order a vote belongs to?
- The poll send returns a message id. Save it next to the order id. A vote carries that id in poll.poll_id.
- Can the buyer answer in text instead?
- Yes. A reply arrives as a message event of type text. The sample accepts 1 for confirm and 2 for cancel and sends anything else to a person.
- Will I get the vote twice?
- A retry can redeliver an event. Save the event id in a durable store before you answer 200. Finish the event and update the order in one transaction, and the second delivery changes nothing.
- Does this work with n8n, Make or Zapier?
- Yes. Any tool that can call an HTTPS API can send the poll and receive the webhook. The n8n, Make and Zapier guides show how to connect each tool.
- Can I try it without paying?
- Yes. Every account has one free sandbox channel that allows 180 messages sent a day and 10 new chats a month.
Free sandbox, forever. Upgrade when you're ready.
Start freeKeep going
HelloHop is an independent WhatsApp API for developers: send and receive messages, automate groups and communities, and get signed webhooks. Not affiliated with WhatsApp or Meta. You link your own number.