OĞUZ EROLAI·ADS·APPS

WhatsApp and Google Sheets Integration: Orders In, Notices Out

12 min read
CONTENTS11 sections

An automatic data flow between WhatsApp and Google Sheets runs through the WhatsApp Business Platform (Cloud API). Each incoming message reaches a middle layer (your own server or an Apps Script web app) as a webhook, an automatic notice Meta sends to your address, and the middle layer writes a row. In the other direction, a row marked “Loaded” goes to the dealer as an approved template message. The connection is a small job; four rules make it hard: the same event arriving twice, two messages in the same second, number format, and never sending two messages for one row. If you receive a few messages a day, copying by hand is enough.

One month of manual copying: 9 of 236 orders never reached the sheet

The company and all figures are fictional, generated and checked in a Python script. At a construction chemicals manufacturer, 64 dealers send orders and shipment questions to a single company WhatsApp number. The shipment plan lives in Google Sheets. The operations lead copies orders into the sheet and writes “loaded” to each dealer by hand. After 30 days (22 working days), the sheet is compared with the chats:

Month-end findingCount
Incoming messages1,180
Orders / shipment questions / other236 / 412 / 532
Orders never entered in the sheet9
Orders entered twice6
Shipments loaded198
Shipments with a forgotten notification17
Rows with a phone number in a different format14
Messages from numbers not on the dealer list19 (5 numbers)

The sheet shows 233 rows, but only 227 unique orders. The answers to all 412 shipment questions were already in the sheet; each time, someone opened it and searched.

How does a message become a row?

A message becomes a row in three steps: Meta sends it to your webhook address; the middle layer checks the notification; it writes a row to the “Incoming” sheet. The first column is the message ID (starting wamid.), the key to deduplication.

I could not find an official connection that writes rows automatically from the WhatsApp Business app, used by hand on a phone. Meta’s Business Platform page presents connections to back-end systems such as a CRM as a Platform (API) feature (read 01.11.2026). For number registration, account verification and template approval, see WhatsApp Business API setup.

Apps Script or your own server? In an Apps Script web app, an incoming POST request runs the doPost(e) function and the body arrives in e.postData.contents (Google, web apps, read 01.11.2026). I have not tested it; the skeleton looks like this:

// Untested skeleton. 'SHEET_ID' and 'Incoming' are examples; no token goes in this file.
function doPost(e) {
  var value = JSON.parse(e.postData.contents).entry[0].changes[0].value;
  var messages = value.messages || [];   // empty in status notifications
  var lock = LockService.getScriptLock();
  lock.waitLock(10000);                  // throws if not acquired in 10 s
  try {
    var sheet = SpreadsheetApp.openById('SHEET_ID').getSheetByName('Incoming');
    var seen = idsFromLastSevenDays(sheet);   // helper, not written here
    messages.forEach(function (m) {
      if (seen.has(m.id)) return;        // the same event arrived again
      // Format the phone column as plain text first (setNumberFormat('@')); a string starting with '+' may be read as a number or formula. Untested.
      sheet.appendRow([m.id, '+' + m.from, new Date(m.timestamp * 1000), m.type,
                       m.text ? m.text.body : '']);
      seen.add(m.id);
    });
  } finally {
    lock.releaseLock();
  }
  return ContentService.createTextOutput('ok');
}

Apps Script has two gaps. Meta signs every notification with the app secret, sends the signature in the X-Hub-Signature-256 header and recommends validating it (Meta, getting started with webhooks, read 01.11.2026). I could not find request headers among the e object fields on Google’s page; my inference is that the signature cannot be validated in Apps Script. Nor could I find which status code goes back to Meta when the script fails. On your own server both are under your control: the signature is validated and an unwritten row gets a non-200 response so Meta retries. I recommend Apps Script for trials and low volume, your own server for real dealer traffic.

If the same message arrives twice: wamid and a 7-day window

If the endpoint returns anything other than 200, Meta retries the notification with decreasing frequency for up to 7 days and notes that this can cause duplicate notifications (Meta, set up webhooks, read 01.11.2026). The general webhook page instead says unacknowledged notifications are dropped after 36 hours (Meta, getting started with webhooks, read 01.11.2026); the two pages differ, so I use the longer 7 days and leave deduplication to the server.

In the simulation, 37 of the 1,180 messages arrive twice: 33 within minutes, 4 three days late after a server outage. The endpoint receives 1,217 requests, and the result depends on where deduplication looks:

  • wamid, last 7 days: all 37 duplicates are removed; 1,180 rows remain.
  • Only the last 100 rows: the 33 minute-level duplicates are caught; the 4 late ones slip through, with more than 100 new messages in between.

The window must not be shorter than Meta’s retry period; an unnoticed repeated order means the same pallet is planned twice.

Two messages in the same second: without a lock, a row is overwritten

When a dealer sends a photo and caption back to back, two notifications arrive in the same second and two executions start. If the code reads the last row and then writes below it, both write to the same row and the second message overwrites the first. In the simulation, two messages arrive in the same second 23 times a month. With that method and no lock, 23 messages are lost; with a lock, 0.

LockService.getScriptLock() prevents the guarded code from running twice at the same time, whoever runs it, and waitLock throws an exception when its timeout expires (Google, LockService and Lock, read 01.11.2026). I could not find how appendRow behaves under concurrent calls. The 23 losses belong to the simulated read-then-write method, not to appendRow; I add the lock either way.

Number format: 0532 in the sheet and 90532 in the webhook are the same dealer

To recognise a dealer and reply, both sides need the same format: +905321234567. In Meta’s payload example, the from field of an incoming message has the country code but no plus sign (16505551234). For sending, Meta highly recommends including the plus sign and country code; without them, your business number’s country code is prepended and the message can reach the wrong person (Meta, send messages, read 01.11.2026).

Of the 14 differently formatted numbers, 11 convert: 0532 123 45 67, 532 123 45 67, +90 (532) 123-45-67, 0090 532 123 4567. 3 cannot be converted because digits are missing. I never complete a number by guessing; the row is marked “Invalid number”.

From sheet to message: which change sends a notification?

One change triggers the notification: Status becomes “Loaded” while Sent is empty. Correcting a date or truck plate sends nothing. The rule has five conditions:

  1. A time trigger, not an edit trigger. According to Google, changes made by a script or an API do not run triggers; a cell written with setValue does not fire onEdit (Google, triggers). An edit trigger misses rows filled by another system. A time trigger runs every 1, 5, 10, 15 or 30 minutes (ClockTriggerBuilder, read 01.11.2026).
  2. A Sent column. When the message is accepted, the time and returned message ID go into the row; a filled row never gets another message. Without it, a 5-minute trigger messages the same rows on every run: 1,043,831 messages in 30 days in the simulation.
  3. A 10-minute wait (my recommendation). In the simulation, two rows are marked “Loaded” by mistake and reverted within minutes. Without the wait, one is marked at 14:03, messaged at 14:05 and reverted at 14:07.
  4. Permission. Meta states that messages can only be sent to users who have opted in (send messages page); decide with your lawyer how permission is obtained and stored.
  5. Template. When a customer writes, a 24-hour customer service window opens; once it closes, only pre-approved template messages can be sent (send messages page). A shipment notice usually goes outside the window, so I build it as a template.

Result: 191 of 198 loaded shipments are notified automatically, once each. The remaining 7 (3 invalid numbers, 4 dealers with no permission record) wait on a list with the reason. The 6 rows edited after sending get no second message. In the manual month, 17 notifications were forgotten.

Quotas, sheet size and a file anyone can edit

In Apps Script, one execution runs for at most 6 minutes, and up to 30 executions per user can run at once. Time triggers get 90 minutes of total runtime a day on a consumer account and 6 hours on Workspace. Outbound requests (UrlFetch): 20,000 a day on a consumer account, 100,000 on Workspace (Google, quotas, read 01.11.2026). On the example’s busiest day, 9 notifications go out; quota is not an issue. A server using the Sheets API is limited to 60 read and 60 write requests per minute per user; excess returns 429 (Sheets API limits, read 01.11.2026).

The cell limit is far away: in a year, the “Incoming” sheet grows to 14,160 rows × 8 columns = 113,280 cells, 0.57% of the 20 million cell limit (Google Drive Help, read 01.11.2026). I have not measured slowdown. My inference is that the bottleneck is reading the whole ID column on every request; so deduplication looks only at the last 7 days of rows, and older rows move to a monthly archive sheet.

The real risk is edit access: any editor can delete rows in “Incoming” or clear the Sent column and trigger a new message. A protected range helps, but Google’s own help page says the feature should not be used as a security measure (Google, protect ranges, read 01.11.2026).

How many messages a day can Sheets handle, and where does an application start?

The choice depends less on message count than on how many people edit the sheet and what a mistake costs.

RouteEnough whenLimit
Copying by handA few messages a day, one person in chargeMissing and duplicate rows stay invisible
Apps Script + SheetsTrials, low volume, one or two people edit the sheetNo signature validation, anyone can delete rows
Own server + SheetsThe team stays in the sheet; security and retries are requiredThe sheet can still be edited freely
Application to be builtSeveral roles, audit log, dealer-specific viewsWritten scope, server, maintenance

If one person enters a few orders a day, I do not recommend an integration: setup and maintenance outweigh the gain. With 9 lost orders and 17 forgotten notifications in a month, as in the example, the picture changes.

Two-way flow in the application to be built

In the application to be built, Sheets can stay as the familiar report screen; records and rules live in the application. What follows is scope that can be developed. It can be built to fit your needs; the scope is defined in writing in the first step.

  • Inbox: signature-validated notifications are deduplicated by wamid; numbers are converted to international format and linked to dealer codes. Unknown numbers go to a separate list.
  • Message to order: AI suggests products and quantities; no order exists until the operations lead approves it.
  • Notifications: “Loaded” + wait + permission + template rules; every send is recorded with its ID and delivery status.
  • Roles: the operations lead can see all messages; the shipment planner can change status but cannot delete messages; a sales rep can see only assigned dealers. The audit log shows who changed what, and when.

The server (VPS) can be opened in your company’s name. The records are yours and can be exported to Excel or CSV at any time. For small and mid-sized teams there is no per-user licence; the cost is the server and maintenance. The source code sits in a repository you can access, with run instructions, a dependency list and known limitations. How I work in general: custom web apps for your team.

The first meeting is paid. Bring the column headers of your shipment sheet and the three questions dealers ask most, and we write the rules from there: contact.

Points I have not verified

  • I have not tested the code skeleton or the rules on a real WhatsApp account or in Apps Script; the logic was simulated and checked in Python.
  • Request-header access, the failure status code (not found in the docs), Meta’s GET verification at registration (doGet) and whether Meta counts an Apps Script response as 200 should be tested before setup.
  • I did not test whether a number starting with + stays plain text in the cell; the column should be set to plain text.
  • The number conversion rule assumes Turkish mobile numbers; a foreign number converts only if written with + or 00.

Frequently Asked Questions

Do messages reach the sheet immediately?

If the endpoint is up, the row is written when the notification arrives. If not, Meta retries for up to 7 days and the row arrives late; so the time column holds the message time from the notification, not the writing time.

Are voice messages and photos written to a row too?

A row is written, the type column shows “audio” or “image” and the text stays empty. Downloading and storing the file is a separate step, agreed in the scope.

Do we need to change our existing shipment sheet?

Usually adding two columns is enough: Sent, and the phone number in international format. Column names should stay fixed; the code finds a column by its name, not its position.

Back to top ↑
WHAT YOU CAN ASK FOR

How do I work?
Work-hour packages

Tell me about your business and what you need on WhatsApp or by phone; we agree on a work block of somewhere between 5 and 40 hours and I start doing what is needed. What you get is not a calendar window: it is net working hours spent directly on your business. I can use 40 hours working three days straight, or deliberately spread it out and finish it over a year: whatever the work calls for. I do not spend my time estimating how long something will take, I spend it doing the work; every hour I spend leaves a lasting result in your business. We keep going for as long as you find it useful.

WORK BLOCKS

Why not monthly?
Does a 40-hour block mean one week?

On a fixed monthly fee both sides are watching the wrong thing: you watch a fixed cost, the other side watches how many more contracts like this they can line up. Working by the hour puts us both in front of the same thing: the real value of the work that got done. I know not having an upfront answer to "how much will this cost in total?" is the natural cost of this model. But instead of paying a fixed fee for months to a setup that is not producing results, you only pay for the qualified time spent on your work: and you see exactly where that time went, start to finish. That is why my clients keep coming back.

5hours300€ + VAT60€ per hourChoose this block
10hours500€ + VAT50€ per hourChoose this block
20hours800€ + VAT40€ per hourChoose this block
40hours1,400€ + VAT35€ per hourChoose this block