Use cases

Send WhatsApp messages from Google Sheets with Apps Script

A Google Apps Script bound to your sheet can read each row that has a phone number, a message and an opt-in, call HelloHop once per row with UrlFetchApp, and write the outcome back to the sheet. A script lock, an idempotency key per row and a state column keep reruns from sending twice.

Facts (as of October 2026, API v1)

  • UrlFetchApp.fetch takes method, contentType, headers, payload, muteHttpExceptions and timeoutSeconds. With muteHttpExceptions set, a 4xx or 5xx comes back as a response instead of an exception.
  • An Apps Script run stops at 6 minutes, so the sample stops sending after 4 minutes and the next trigger run carries on.
  • A time-driven trigger created with everyMinutes accepts 1, 5, 10, 15 or 30.
  • The event object Apps Script passes to doPost carries the query string, the parameters and the body, and no request headers, so a doPost cannot check the X-HelloHop-Signature header. Read delivery receipts with a receiver that can.
  • 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. Set up the sheet. Name a tab Send. Add the columns id, phone, message, opted_in, state, message_id, claimed_at and next_attempt_at. Use a unique id per row and never reuse it.
  2. Store the channel credentials. Add CHANNEL_ID and CHANNEL_TOKEN as script properties. Anyone who can edit the script can read them, so share the sheet carefully.
  3. Paste the script. Add the sample under Extensions, Apps Script. Run sendPending by hand on two test rows first.
  4. Schedule it. Run install once to create a trigger that calls sendPending every 5 minutes.
  5. Read the state column. sent means WhatsApp acknowledged the send. queued means it was accepted for later. unknown means look at the chat before any resend. failed means the row needs a fix.

The job: message the people in a sheet

Many teams already keep a list in a sheet: event guests, class members, customers waiting for a reply. The script turns each ready row into one WhatsApp message and writes the result beside it. Only rows whose opted_in cell says yes are sent, so the column records who agreed to hear from you on WhatsApp. The wording in the message column is yours.

The script

The script claims a row before it sends, uses the row id as the idempotency key and takes a script lock so two runs cannot overlap. A row left claimed by a run that died becomes unknown after 10 minutes, and unknown rows are never resent automatically. A refused send (429, or 503 with ambiguous false) saves next_attempt_at from Retry-After, clears the state and stops the batch. A later trigger skips that row until it is due, then repeats the same key. Do not edit the message of a row after a retry: the same key with a different body answers 409 idempotency_conflict.

Apps Script: send pending rows
// Google Apps Script (V8). Sheet "Send", row 1 = headers. Columns:
// A id (unique, never reused), B phone (digits with country code), C message, D opted_in (yes),
// E state, F message_id, G claimed_at (ms), H next_attempt_at (ms)
// UrlFetchApp: https://developers.google.com/apps-script/reference/url-fetch/url-fetch-app
// Locks: https://developers.google.com/apps-script/reference/lock/lock
// A run stops at 6 minutes: https://developers.google.com/apps-script/guides/services/quotas
const API = 'https://api.hellohop.app/v1';
const COL = { state: 5, messageId: 6, claimedAt: 7, nextAttemptAt: 8 };
const BUDGET_MS = 4 * 60 * 1000; // stop well before the 6 minute limit

// One send. Never throws: it reports what happened.
function sendWhatsApp(key, message) {
  const props = PropertiesService.getScriptProperties(); // set CHANNEL_ID and CHANNEL_TOKEN under Project Settings
  try {
    const res = UrlFetchApp.fetch(API + '/sessions/' + props.getProperty('CHANNEL_ID') + '/messages', {
      method: 'post',
      contentType: 'application/json',
      headers: { Authorization: 'Bearer ' + props.getProperty('CHANNEL_TOKEN'), 'Idempotency-Key': key },
      payload: JSON.stringify(message),
      muteHttpExceptions: true, // a 4xx or 5xx comes back as a response, not an exception
      timeoutSeconds: 30,
    });
    let data = {};
    try { data = JSON.parse(res.getContentText()); } catch (e) {}
    const headers = res.getAllHeaders();
    const retryAfter = headers[Object.keys(headers).find((k) => k.toLowerCase() === 'retry-after')];
    const delay = /^\d+$/.test(String(retryAfter)) ? Number(retryAfter) * 1000 : Date.parse(retryAfter) - Date.now();
    return { status: res.getResponseCode(), code: data.code, ambiguous: data.ambiguous, id: data.id,
      nextAttemptAt: Date.now() + (Number.isFinite(delay) ? Math.max(1000, delay) : 1000) };
  } catch (e) {
    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(r) {
  if (r.status === 200) return 'sent'; // server_ack, not delivered
  if (r.status === 202) return 'queued'; // not delivered yet, do not resend
  const refused = ['upstream_unavailable', 'hopsmart_settings_unavailable', 'operator_unresolved'];
  if (r.status === 429 || (r.status === 503 && (r.ambiguous === false || refused.includes(r.code)))) return 'retry';
  if (r.status === 0 || r.status >= 500 || r.code === 'idempotency_uncertain') return 'unknown'; // look at the chat first
  return 'failed'; // fix it, do not retry
}

function sendPending() {
  const lock = LockService.getScriptLock();
  if (!lock.tryLock(10000)) return; // the previous run is still going
  try {
    const sheet = SpreadsheetApp.getActive().getSheetByName('Send');
    const started = Date.now();
    const rows = sheet.getDataRange().getValues();
    for (let i = 1; i < rows.length; i++) {
      const [id, phone, text, optedIn, state, , claimedAt, nextAttemptAt] = rows[i];
      const row = i + 1;
      if (state === 'claimed' && Date.now() - claimedAt > 10 * 60 * 1000) {
        sheet.getRange(row, COL.state).setValue('unknown'); // a run died mid-send: look at the chat, never resend
        continue;
      }
      if (state !== '' || String(optedIn).toLowerCase() !== 'yes' || Number(nextAttemptAt) > Date.now()) continue;
      if (Date.now() - started > BUDGET_MS) break; // the next trigger run carries on
      sheet.getRange(row, COL.state).setValue('claimed');
      sheet.getRange(row, COL.claimedAt).setValue(Date.now());
      SpreadsheetApp.flush();
      const result = sendWhatsApp('sheet-' + id, { type: 'text', to: String(phone), text: String(text) });
      const outcome = classify(result);
      sheet.getRange(row, COL.nextAttemptAt).setValue(outcome === 'retry' ? result.nextAttemptAt : '');
      SpreadsheetApp.flush(); // save the retry time before making the row eligible again
      sheet.getRange(row, COL.state).setValue(outcome === 'retry' ? '' : outcome);
      sheet.getRange(row, COL.messageId).setValue(result.id || '');
      if (outcome === 'retry') break; // refused before sending: the next run repeats the same key
    }
  } finally {
    lock.releaseLock();
  }
}

// Run once to schedule it: https://developers.google.com/apps-script/reference/script/clock-trigger-builder
function install() {
  ScriptApp.newTrigger('sendPending').timeBased().everyMinutes(5).create();
}

The send call by hand

curl (example message text)
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: sheet-ROW_ID" \
  -d '{"type":"text","to":"66XXXXXXXXX","text":"Hi Anna, your class starts at 10:00 tomorrow."}'

What each send result does to the row

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.

Limits to plan for

Questions

Can Google Sheets send WhatsApp messages?
Yes, through Apps Script. The script calls POST /v1/sessions/{channel}/messages on HelloHop for each ready row and writes the outcome back.
How do I stop it sending a row twice?
Each row sends with the key sheet- plus its id, the row is claimed before the call, and a script lock stops two runs from overlapping. Repeating the same key and body within 24 hours returns the first result.
What if the script hits the 6 minute limit?
The sample stops sending after 4 minutes. Rows it did not reach keep an empty state and the next trigger run continues. A row left claimed by a dead run becomes unknown and is not resent.
Where do I keep the token?
In script properties. Anyone who can edit the script can read them, so keep the sheet private and replace the token if it is shared widely.
Can I try it without paying?
Yes. Every account has one free sandbox channel that allows 180 messages sent a day.

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.