Use cases

Automate WhatsApp groups and communities

To automate a group: create it once with POST /groups, read it, add the members who are not in it yet in batches of up to 50, then send one welcome message to the group id. The group routes take no idempotency key, so your own table records each step and a rerun reads the group first.

Facts (as of October 2026, API v1)

  • The group routes (create, participants, subject, description, settings, invite link) do not take an Idempotency-Key. The send route does, and the welcome message uses it.
  • One participants request changes up to 50 people and answers one result per person: ok, error_<code> or unknown. An unknown result means the change may have applied, so read the group before you retry.
  • A group is addressed by its JID, for example [email protected]. The send route accepts that JID as the to field.
  • group.participants events report join, leave, promote or demote, and carry the group_jid and the participants.
  • A create counts as one group add for the group and one for each person named. The free sandbox channel allows 5 group adds a day, counted in Bangkok time, so test with a small group.
  • 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.
  • Prices: from $20 USD per number per month, billed annually, with a free sandbox and no per-message fees.

Steps

  1. Record the plan. Write the group key, the subject and the member list to your table with each member pending, before any call.
  2. Create the group once. Win an atomic insert-if-absent claim in your table, call POST /groups with the subject (1 to 25 characters), and save the returned jid. If the answer is missing, stop and list your groups before creating again.
  3. Read, then add. GET the group, skip people already in it, and add the rest in batches of up to 50.
  4. Record each result. Save ok, error_<code> or unknown per person.
  5. Welcome once. Send one message to the group jid with an Idempotency-Key built from the group key.

The job: a group that sets itself up

A new cohort, a customer club or an event needs a group with the right people in it and a first message. Done by hand it is the same steps every time. The sample does it from a list of people who agreed to join. Durable claims guard creation and the welcome; run member additions through one worker per group, since their read and add are separate calls. The basic group calls are covered in the group API use case and the create-a-group guide; this page is the orchestration around them.

The setup function (Node.js)

Implement the table helpers. A unique group key and an atomic insert give one worker the right to create. A create with no answer stays creating, because it may have worked. The welcome stores its exact JSON body before claiming and sending; retries read that saved body. Run recoverWelcomes on a timer: abandoned claims become unknown and are never resent automatically, even after the 24-hour idempotency window expires. A person decides what to do with it: list your groups, then record the jid. A definite refusal (any 4xx) clears the plan so you can fix the request and try again. People whose add came back as an error are left alone, and anyone who could not be added because of their privacy settings can be given the invite link instead.

Node.js: create, add, welcome
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
}
// Group routes take no Idempotency-Key, so the table is your guard. Your tables:
//   groups: key (unique), state (creating or ready), jid
//   welcomes: key (unique), state, body (JSON), claimed_at (Unix ms), message_id
//   members: group key, phone, state (pending, added, unknown, failed_<code>)
// SQLite examples: db.run returns { changes }; db.get returns one row. Use durable tables.
//   getGroup(key)  saveGroup(key, state, jid)  deleteGroup(key)  seedMembers(key, phones)  setMember(key, phone, state)
// Phones are stored as digits only. results[].jid echoes what you sent, so compare digits with digits:
const digits = (s) => String(s).replace(/\D/g, '');
//   setMemberByJid(groupJid, phone, state)   pendingMembers(key) -> phones in state pending or unknown
async function claimGroup(key) {
  const r = await db.run("INSERT INTO groups (key, state) VALUES (?, 'creating') ON CONFLICT(key) DO NOTHING", [key]);
  return r.changes === 1;
}
async function claimWelcome(key, body) {
  await db.run("INSERT INTO welcomes (key, state, body) VALUES (?, 'pending', ?) ON CONFLICT(key) DO NOTHING", [key, JSON.stringify(body)]);
  const r = await db.run("UPDATE welcomes SET state = 'claimed', claimed_at = ? WHERE key = ? AND state = 'pending'", [Date.now(), key]);
  if (r.changes !== 1) return null;
  return JSON.parse((await db.get('SELECT body FROM welcomes WHERE key = ?', [key])).body);
}
async function saveWelcome(key, outcome, id) {
  await db.run("UPDATE welcomes SET state = ?, message_id = ? WHERE key = ? AND state = 'claimed'", [outcome === 'retry' ? 'pending' : outcome, id ?? null, key]);
}
async function recoverWelcomes() {
  await db.run("UPDATE welcomes SET state = 'unknown' WHERE state = 'claimed' AND (claimed_at IS NULL OR claimed_at < ?)", [Date.now() - 5 * 60 * 1000]);
}
async function hh(method, path, body) {
  try {
    const res = await fetch(`${API}/sessions/${CHANNEL_ID}${path}`, {
      method,
      headers: { Authorization: `Bearer ${CHANNEL_TOKEN}`, 'Content-Type': 'application/json' },
      body: body && JSON.stringify(body),
      signal: AbortSignal.timeout(30000),
    });
    return { status: res.status, data: await res.json().catch(() => ({})) };
  } catch {
    return { status: 0, data: {} }; // timeout or lost connection: the change may have applied
  }
}

async function setUpGroup(key, subject, phones, welcome) {
  let g = await getGroup(key);
  if (g?.state === 'creating') return 'stop: an earlier create has no answer. List your groups before creating again.';
  if (!g) {
    if (!(await claimGroup(key))) return 'later: another worker claimed this group';
    const res = await hh('POST', '/groups', { subject });
    if (res.status >= 400 && res.status < 500) { await deleteGroup(key); return `refused: ${res.data.code}`; }
    if (res.status !== 201) return `stop: create answered ${res.status}. List your groups before creating again.`;
    await saveGroup(key, 'ready', res.data.jid);
    g = { jid: res.data.jid };
  }
  await seedMembers(key, phones.map(digits));
  // Read the group first and add only people who are not in it yet.
  const read = await hh('GET', `/groups/${g.jid}`);
  if (read.status !== 200) return `later: group read answered ${read.status}`;
  const present = new Set((read.data.participants ?? []).map((p) => digits(p.phone_number || p.jid)));
  const todo = [];
  for (const phone of await pendingMembers(key)) {
    if (present.has(phone)) await setMember(key, phone, 'added'); else todo.push(phone);
  }
  for (let i = 0; i < todo.length; i += 50) {
    const res = await hh('POST', `/groups/${g.jid}/participants`, { action: 'add', participants: todo.slice(i, i + 50) });
    if (res.status !== 200) return `later: add answered ${res.status}; a rerun reads the group first`;
    // error_409 means already in the group, which for an add is a success.
    for (const r of res.data.results) await setMember(key, digits(r.jid), r.status === 'ok' || r.status === 'error_409' ? 'added' : r.status === 'unknown' ? 'unknown' : `failed_${r.status}`);
  }
  await recoverWelcomes(); // also run from a timer; an abandoned claim is unknown, never auto-resent
  const body = await claimWelcome(key, { type: 'text', to: g.jid, text: welcome });
  if (!body) {
    const w = await db.get('SELECT state FROM welcomes WHERE key = ?', [key]);
    return w && (w.state === 'sent' || w.state === 'queued') ? 'done' : `stop: welcome is ${w ? w.state : 'missing'}; inspect it`;
  }
  const result = await sendWhatsApp(`welcome-${key}`, body);
  const outcome = classify(result);
  await saveWelcome(key, outcome, result.id);
  return outcome;
}

// group.participants: action is join, leave, promote or demote. Call this from a receiver that verifies the signature.
async function onGroupEvent(event) {
  const { group_jid, action, participants } = event.payload;
  if (action !== 'join' && action !== 'leave') return;
  for (const jid of participants) await setMemberByJid(group_jid, digits(jid), action === 'join' ? 'added' : 'left');
}

The invite link for people who could not be added

curl
API=https://api.hellohop.app/v1
[email protected]

curl -s "$API/sessions/$CHANNEL_ID/groups/$GROUP_JID/invite-link" \
  -H "Authorization: Bearer $CHANNEL_TOKEN"

What the welcome send does with each 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.

Keeping your member table current

Subscribe the receiver to group.participants as well as message events. The onGroupEvent function in the sample updates your table when someone joins or leaves. Call it from a receiver that verifies the signature, the same way the other receiver samples do.

Communities

To create the group inside a community, add parent_jid to the create body, which counts as one more group add. The community routes are in the community API use case.

Questions

Can I create a WhatsApp group and add people from code?
Yes. POST /v1/sessions/{channel}/groups creates it, and POST /v1/sessions/{channel}/groups/{group}/participants with action add changes up to 50 people per request.
How do I avoid creating the group twice?
The group routes have no idempotency key. Use a unique group key and an atomic insert-if-absent claim before the call; only its winner creates. Save the jid afterward. If a create has no answer, list your groups before trying again.
What does an unknown add result mean?
The change may have applied. Read the group and add only the people who are not in it. The sample does this on every run.
How do I welcome the group?
Send a text with the group jid as the to field and an Idempotency-Key such as welcome plus your group key. Claim and save the exact body durably before sending. An abandoned claim becomes unknown, never an automatic resend.
How do I know who joined?
Subscribe to group.participants. The payload has the group_jid, an action of join, leave, promote or demote, and the participants.

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.

Automate WhatsApp Groups and Communities | HelloHop