Use cases

WhatsApp support auto-reply with business hours

HelloHop posts each inbound WhatsApp message to your webhook. Your receiver saves it to an inbox for a person, checks business hours in your time zone, and sends one automatic reply per chat per day: a short acknowledgment while open, an opening-hours note while closed. When a person owns the chat, it stays silent.

Facts (as of October 2026, API v1)

  • HelloHop posts a signed message event for each inbound message. The payload has chat_jid, type, text, from_me and is_group.
  • The delivery id, X-HelloHop-Delivery, equals the id in the event body. Deliveries are retried, so save the id before you answer.
  • Your receiver must answer 2xx within 10 seconds by default. Do the send after you answer.
  • The unified POST /v1/sessions/{channel}/messages route 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

  1. Subscribe to messages. PUT your HTTPS URL and a secret of at least 24 characters to /v1/sessions/{channel}/webhooks with the event message. PUT replaces the whole receiver list, so include any receivers you keep.
  2. Verify and queue. Check the signature on the raw body, insert the message into your inbox under the event id, then answer 200.
  3. Check hours and handoff. Compute open or closed in your own time zone. Stay silent when a person handles the chat.
  4. Reply once per receipt day. Save the chat and receipt day in the reply key, claim it, save the text and send with that Idempotency-Key.

The job: nobody left waiting in silence

People who write at night should hear when you will answer. People who write in the day should know someone has it. Every message still goes to a person: the automatic reply only sets expectations. For an AI answer instead, see the chatbot guide.

Subscribe to inbound messages

curl
API=https://api.hellohop.app/v1

curl -s -X PUT "$API/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 receiver (Node.js)

Implement the durable table helpers above the sample, including saved reply bodies, and create the inbox columns shown. Before the 200, the inbox saves pending dispatch work and its original per-chat, per-day reply key. Duplicate event ids change nothing, even after midnight. The key and hours use the original receipt time, including during recovery. The included timer dispatches unfinished inbox rows; a failure before creating the reply row leaves recoverable work. Retry outcomes keep that work pending with the same key and text. Abandoned send claims become unknown and are never automatically resent. The webhook and the timer can run at the same time. A worker that loses the claim reads stateOf(key), which you also provide: while the reply is pending or claimed it leaves the inbox row alone, so the winner settles it and a retry outcome runs again. The two reply texts are examples, and CLOSED_TEXT spells out the hours, so change it together with HOURS. Holidays and your help desk handoff flag are yours to supply.

Node.js: hours check and reply
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
}
// Your events table: unique key, payload, state, claimed_at (Unix ms), message_id, next_attempt (Unix ms, default 0). Helpers:
//   saveEvent(key, payload)  insert a pending row once; a repeat changes nothing
//   claimSend(key)           atomic pending -> claimed, only when next_attempt <= now; sets claimed_at; true for one caller only
//   finish(key, expected, state, id, nextAttempt) UPDATE only WHERE state = expected; save the message id
//     retry returns to pending and saves nextAttempt (the helper's retryAt); all other outcomes stop automatic sends
//   skipPending(key)         UPDATE pending -> skipped only; never overwrites a claim or an outcome
//   saveBody(key, text) / savedBody(key)  keep the exact text, so a retry sends the same body
// Your timer calls recoverAbandonedClaims first, then re-runs pending rows. Never re-send unknown rows.
// db.run(sql, params) executes SQL in your database; claimed_at is Unix milliseconds.
async function recoverAbandonedClaims() {
  await db.run("UPDATE events SET state = 'unknown' WHERE state = 'claimed' AND (claimed_at IS NULL OR claimed_at < ?)",
    [Date.now() - 5 * 60 * 1000]);
}
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));
}
// Also yours: humanOwns(chatJid), true while a person handles that chat (your help desk sets it).
// And stateOf(key), the current state of a reply row in the events table.
// inbox table: event_id (unique), chat_jid, type, text, received_at, reply_key, dispatch_state. A person reads it when the office opens.
const HOURS = { tz: 'Asia/Bangkok', days: [1, 2, 3, 4, 5], open: 9, close: 18 }; // Monday to Friday, 09:00 to 18:00
function isOpen(now = new Date()) {
  const p = Object.fromEntries(new Intl.DateTimeFormat('en-US', { timeZone: HOURS.tz, weekday: 'short', hour: 'numeric', hourCycle: 'h23' })
    .formatToParts(now).map((x) => [x.type, x.value]));
  const day = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'].indexOf(p.weekday);
  return HOURS.days.includes(day) && Number(p.hour) >= HOURS.open && Number(p.hour) < HOURS.close;
}
const dayKey = (now = new Date()) => new Intl.DateTimeFormat('en-CA', { timeZone: HOURS.tz }).format(now); // YYYY-MM-DD
const OPEN_TEXT = 'Thanks, your message reached us. A person will reply here soon.';
const CLOSED_TEXT = 'Thanks, your message reached us. We are closed now and open Monday to Friday, 09:00 to 18:00 Bangkok time. We will reply then.';

async function autoReply(row) {
  const { chat_jid: chatJid, reply_key: key } = row; // never recompute the day on recovery
  if (await humanOwns(chatJid)) return true; // a person is on this chat: stay silent
  await saveEvent(key, JSON.stringify({ chat: chatJid }));
  if (!(await claimSend(key))) {
    // Another worker holds the claim, or the reply is final. Only the winner finalizes a row that is pending or claimed.
    const state = await stateOf(key);
    return state !== 'pending' && state !== 'claimed';
  }
  let text = await savedBody(key);
  if (!text) {
    text = isOpen(new Date(row.received_at)) ? OPEN_TEXT : CLOSED_TEXT;
    await saveBody(key, text); // a retry sends this exact text
  }
  const result = await sendWhatsApp(key, { type: 'text', to: chatJid, text });
  const outcome = classify(result);
  await finish(key, 'claimed', outcome, result.id);
  return outcome !== 'retry';
}

async function dispatchInbox() {
  await recoverAbandonedClaims();
  const rows = await db.all("SELECT * FROM inbox WHERE dispatch_state = 'pending' ORDER BY received_at LIMIT 200", []);
  for (const row of rows) {
    if (await autoReply(row)) await db.run("UPDATE inbox SET dispatch_state = 'done' WHERE event_id = ?", [row.event_id]);
  }
}
setInterval(() => dispatchInbox().catch(console.error), 60 * 1000);

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'));
  const m = event.payload;
  if (event.type !== 'message' || m.from_me || m.is_group) return res.sendStatus(200);
  let inserted;
  try {
    const receivedAt = Date.now();
    // Queue the message for a person first. The event id makes a repeated delivery a no-op.
    inserted = await db.run("INSERT INTO inbox (event_id, chat_jid, type, text, received_at, reply_key, dispatch_state) VALUES (?, ?, ?, ?, ?, ?, 'pending') ON CONFLICT(event_id) DO NOTHING",
      [event.id, m.chat_jid, m.type, m.text ?? null, receivedAt, `support-${m.chat_jid}-${dayKey(new Date(receivedAt))}`]);
  } catch {
    return res.sendStatus(500); // the webhook is delivered again
  }
  res.sendStatus(200);
  if (inserted.changes === 1) dispatchInbox().catch(console.error); // the timer also recovers unfinished work
});

app.listen(3007);

What the handler does with each send result

Send resultWhat your handler does
200 server_ackWhatsApp acknowledged the send. Mark it sent and save id; this is not a delivery receipt.
202 queuedPersisted 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_unresolvedRefused 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 responsePossibly 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_conflictThe same key was used for a different message. Fix how you build the key. The first message is unchanged.
Any other 409Mark it failed. Fix the channel before scheduling another attempt.
Other 4xxThe 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.

Who may be messaged

This flow answers people who wrote to you first. It ignores group messages and messages your own number sent.

Questions

How do I know whether I am open?
Compute it in your business time zone, not the server's. The sample reads the weekday and hour in a named IANA zone with the platform Intl API.
How do I stop it replying on every message?
The saved reply key contains the chat and receipt day, so a burst gets one automatic reply. Recovery keeps that key even on a later day.
How does a person take over?
Your help desk sets a flag for the chat. While it is set the receiver still saves messages to the inbox and sends no automatic reply.
What if the send times out?
Treat it as possibly delivered, record it as unknown and look at the chat before sending anything again.

Free sandbox, forever. Upgrade when you're ready.

Start free

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.

WhatsApp Support Auto-Reply with Business Hours | HelloHop