ServicesProductsDocsBlogConsultingAboutContactBook a free call

Free resource

Free WhatsApp to Google Sheets Template (Apps Script Webhook)

A free Apps Script that logs every WhatsApp Cloud API message into a Google Sheet the moment it arrives, with a second tab that shows who is still waiting for a reply and for how many minutes. Copy the sheet, publish the script as a web app and connect it to your Meta app. It runs in your own Google account, no monthly fee.

Make a copyOpens Google with your own copy. Nothing is shared with us.

Set it up

  1. Before you start: this needs the WhatsApp Business Platform (Cloud API) and a Meta app. The WhatsApp Business app on a phone has no API, so it can't send messages to a sheet.
  2. Click Make a copy (the code and the Conversations formulas come with it). Open Extensions > Apps Script, replace VERIFY_TOKEN at the top with a long random string of your own, and save.
  3. Click Deploy > New deployment > Web app. Execute as: Me, so rows land in your sheet. Who has access: Anyone, because Meta's servers can't sign in to Google. Deploy, authorize, and copy the web app URL that ends in /exec.
  4. In your Meta app, open WhatsApp > Configuration. Paste the /exec URL as the webhook address and the same verify token, then save. Meta calls the script once and doGet answers with the challenge.
  5. Subscribe the webhook to the messages field. From then on every incoming message is logged as in, every reply you send as out, and the Conversations tab shows who is waiting. Anyone waiting over an hour turns red.

The full script

whatsapp-to-google-sheets.gs
// Logs every WhatsApp Cloud API webhook into the Messages sheet.
// Columns: Time | Direction | Customer | Type | Text | Message ID
const VERIFY_TOKEN = 'change-me-to-a-long-random-string';

function doGet(e) {
  // Meta checks the URL once, when you subscribe the webhook
  if (e.parameter['hub.verify_token'] === VERIFY_TOKEN) {
    return ContentService.createTextOutput(e.parameter['hub.challenge']);
  }
  return ContentService.createTextOutput('forbidden');
}

function doPost(e) {
  const body = JSON.parse(e.postData.contents);
  const sheet = SpreadsheetApp.getActive().getSheetByName('Messages');
  const seen = new Set(sheet.getRange('F:F').getValues().flat());
  const time = (s) => new Date(Number(s) * 1000); // WhatsApp sends seconds
  const rows = [];

  (body.entry || []).forEach((entry) => {
    (entry.changes || []).forEach((change) => {
      const v = change.value || {};
      (v.messages || []).forEach((m) => {
        rows.push([time(m.timestamp), 'in', m.from, m.type, (m.text || {}).body || '', m.id]);
      });
      (v.statuses || []).forEach((s) => {
        if (s.status === 'sent') rows.push([time(s.timestamp), 'out', s.recipient_id, '', '', s.id]);
      });
    });
  });

  // Meta may send the same event twice, even inside one delivery
  const fresh = rows.filter((r) => {
    if (seen.has(r[5])) return false;
    seen.add(r[5]);
    return true;
  });
  if (fresh.length) {
    sheet.getRange(sheet.getLastRow() + 1, 1, fresh.length, 6).setValues(fresh);
  }
  return ContentService.createTextOutput('ok');
}

Common mistakes

Meta says the URL couldn't be verified.
The verify token in Meta must match VERIFY_TOKEN in the code exactly. If you changed the code after deploying, publish it again: Deploy > Manage deployments > Edit > Version: New version. The /exec URL stays the same.
Every row says 1970.
WhatsApp sends the time in seconds and JavaScript counts milliseconds. The template multiplies by 1000; if you wrote your own version, do the same.
One message shows up as two rows.
Meta retries for up to seven days when it doesn't get an OK, and can deliver the same event twice. The script skips any message ID already in column F, so keep that column and don't sort IDs away from their rows.
A customer dropped off the waiting list but nobody answered them.
Automatic replies and template messages sent from your number count as a reply. If you use an auto-greeting, treat the list as "not yet answered by anyone or anything".
Is the web app URL safe to share?
No. Apps Script can't read Meta's signature header, so anyone with the /exec URL could post fake rows. Keep it private, and since message text is personal data, delete old rows on a schedule.

We value your privacy

We use essential cookies to make our site work. With your consent, we may also use non-essential cookies to improve user experience and analyze website traffic. By clicking "Accept", you agree to our website's cookie use as described in our Cookie Policy.