Google Sheets
Orders and appointments are often kept in Google Sheets. A ready Apps Script, pasted into the table once, sends a row to the Flows address as an event: you change the status of an order by hand, a customer answers a Google Form linked to the table, another system adds a row — and the customer gets the right message in Viber or SMS.
The rows that are already in the table when you connect it are marked and never sent: the history does not go out as a mailing.
This page is written from the public documentation of Google Apps Script and has not been checked on a live account yet.
What you need
- Any Google account: the script is free. Google's quotas: 20,000 requests a day for a regular account and 100,000 for Google Workspace; triggers run up to 90 minutes a day (6 hours for Workspace); one run lasts up to 6 minutes.
- One address per table, or one for all tables: the event is named in the body of each request.
Step 1. Create a connection
- Open
Flows → Connections, press Connect a system and choose Google Sheets (Apps Script). - Press Copy address. It looks like
https://events.alphasms.net/hooks/<TOKEN>— keep it secret.
Step 2. Add the script to the table
- In row 1 of the sheet put the names of the columns:
phone(orТелефон),email,external_id,first_name(orІм'я),event,order_id,total,status,ttn,visit_atand others. Theeventcolumn is optional: without it a row goes asDEFAULT_EVENT. - Make the phone column Format → Number → Plain text, or write the numbers with
380: otherwise the table drops the leading 0. - Open Extensions → Apps Script and replace the contents of
Code.gswith the script below. InFLOW_URLreplacePASTE_THE_ADDRESS_HEREwith the address from the cabinet, keeping the quotes; put the name of your sheet intoSHEET_NAME. Press Save. - Choose the function
setupFlowTriggersand press Run. Allow access — once.
setupFlowTriggers marks every row already in the sheet SKIP: був до підключення in the flow_sent column, so
the history is not sent, and creates three installable triggers: on edit (onEditFlow), on form submit
(onFormSubmitFlow) and every 10 minutes (sendPending).
/**
* AlphaFlow: a Google Sheets row → a scenario event.
* 1. Extensions → Apps Script → paste this code, replace FLOW_URL and SHEET_NAME → Save.
* 2. Choose the setupFlowTriggers function → Run → allow access (once).
* Columns in row 1: phone, email, external_id, first_name, event, order_id, total, status, ttn, visit_at…
*/
var FLOW_URL = 'PASTE_THE_ADDRESS_HERE'; // the address from the AlphaFlow cabinet
var SHEET_NAME = 'Замовлення'; // the sheet with the data
var DEFAULT_EVENT = 'order_created'; // the event when the row has no event column
var TRIGGER_COLUMN = 'status'; // a manual change of this column sends the row
var SEND_NEW_ROWS = false; // true — every 10 min send new rows added not by hand
var SENT_COLUMN = 'flow_sent'; // the script writes the result here
var ALIASES = { 'телефон': 'phone', 'номер телефону': 'phone', 'phone number': 'phone',
'електронна пошта': 'email', 'e-mail': 'email', "ім'я": 'first_name', 'name': 'first_name' };
var CONTACT_KEYS = ['phone', 'email', 'external_id'];
var TRAIT_KEYS = ['first_name', 'last_name', 'language', 'timezone'];
function headers_(sheet) {
var last = Math.max(sheet.getLastColumn(), 1);
var h = sheet.getRange(1, 1, 1, last).getValues()[0].map(function (v) {
var k = String(v).trim();
return ALIASES[k.toLowerCase()] || k;
});
if (h.indexOf(SENT_COLUMN) === -1) {
sheet.getRange(1, last + 1).setValue(SENT_COLUMN);
h.push(SENT_COLUMN);
}
return h;
}
function hex_(s) {
return Utilities.computeDigest(Utilities.DigestAlgorithm.SHA_1, s, Utilities.Charset.UTF_8)
.map(function (b) { return ('0' + (b & 255).toString(16)).slice(-2); }).join('');
}
function buildEvent_(sheet, h, row, r) {
var ev = { event: DEFAULT_EVENT, contact: {}, traits: {}, properties: {} };
h.forEach(function (key, i) {
var v = row[i];
if (!key || key === SENT_COLUMN || v === '' || v === null) return;
if (v instanceof Date) v = v.toISOString();
if (key === 'event') ev.event = String(v).trim();
else if (CONTACT_KEYS.indexOf(key) !== -1) ev.contact[key] = String(v).trim();
else if (TRAIT_KEYS.indexOf(key) !== -1) ev.traits[key] = v;
else ev.properties[key] = v;
});
if (!Object.keys(ev.contact).length) return null;
var id = ev.properties.order_id || ev.properties.appointment_id || ('row' + r);
ev.message_id = 'sheet:' + sheet.getSheetId() + ':' +
hex_([id, ev.event, ev.properties.status || ''].join('|')).slice(0, 32);
if (ev.properties.order_id || ev.properties.appointment_id) ev.dedupe_key = String(id);
ev.occurred_at = new Date().toISOString();
ev.context = { source: 'google_sheets', sheet: sheet.getName(), row: r };
return ev;
}
function sendRow_(sheet, r) {
var h = headers_(sheet);
var row = sheet.getRange(r, 1, 1, h.length).getValues()[0];
var cell = sheet.getRange(r, h.indexOf(SENT_COLUMN) + 1);
var ev = buildEvent_(sheet, h, row, r);
if (!ev) { cell.setValue('SKIP: немає phone, email чи external_id'); return; }
var mark;
try {
var code = UrlFetchApp.fetch(FLOW_URL, {
method: 'post',
contentType: 'application/json',
payload: JSON.stringify(ev),
muteHttpExceptions: true
}).getResponseCode();
mark = (code >= 200 && code < 300 ? 'OK ' : (code === 429 || code >= 500 ? 'ERR ' : 'FAIL ')) + code;
} catch (err) {
mark = 'ERR ' + err.message;
}
cell.setValue(mark + ' ' + new Date().toISOString());
}
function onEditFlow(e) {
var sheet = e.range.getSheet();
if (sheet.getName() !== SHEET_NAME) return;
var col = headers_(sheet).indexOf(TRIGGER_COLUMN) + 1;
if (!col || col < e.range.getColumn() || col > e.range.getLastColumn()) return;
for (var r = Math.max(2, e.range.getRow()); r <= e.range.getLastRow(); r++) sendRow_(sheet, r);
}
function onFormSubmitFlow(e) {
var sheet = e.range.getSheet();
if (sheet.getName() === SHEET_NAME) sendRow_(sheet, e.range.getRow());
}
function sendPending() {
var sheet = SpreadsheetApp.getActive().getSheetByName(SHEET_NAME);
if (!sheet || sheet.getLastRow() < 2) return;
var s = headers_(sheet).indexOf(SENT_COLUMN);
var marks = sheet.getRange(2, s + 1, sheet.getLastRow() - 1, 1).getValues();
for (var i = 0, n = 0; i < marks.length && n < 200; i++) {
var m = String(marks[i][0]);
if (m.indexOf('ERR') === 0 || (SEND_NEW_ROWS && m === '')) { sendRow_(sheet, i + 2); n++; }
}
}
function setupFlowTriggers() {
var ss = SpreadsheetApp.getActive();
var sheet = ss.getSheetByName(SHEET_NAME);
if (!sheet) throw new Error('Немає аркуша ' + SHEET_NAME);
ScriptApp.getProjectTriggers().forEach(function (t) {
if (['onEditFlow', 'onFormSubmitFlow', 'sendPending'].indexOf(t.getHandlerFunction()) !== -1) {
ScriptApp.deleteTrigger(t);
}
});
var h = headers_(sheet);
if (sheet.getLastRow() >= 2) { // rows that are already there are not sent
var range = sheet.getRange(2, h.indexOf(SENT_COLUMN) + 1, sheet.getLastRow() - 1, 1);
range.setValues(range.getValues().map(function (v) {
return [v[0] === '' ? 'SKIP: був до підключення' : v[0]];
}));
}
ScriptApp.newTrigger('onEditFlow').forSpreadsheet(ss).onEdit().create();
ScriptApp.newTrigger('onFormSubmitFlow').forSpreadsheet(ss).onFormSubmit().create();
ScriptApp.newTrigger('sendPending').timeBased().everyMinutes(10).create();
}
The settings at the top of the script:
| Setting | What it does |
|---|---|
FLOW_URL | The address from the cabinet |
SHEET_NAME | The sheet with the data, Замовлення in the script |
DEFAULT_EVENT | The event of a row without the event column, order_created |
TRIGGER_COLUMN | The column whose change by hand sends the row, status |
SEND_NEW_ROWS | true — every 10 minutes send the new rows that were added not by hand |
SENT_COLUMN | Where the script writes the result, flow_sent |
How the columns are read:
phone,email,external_idname the contact. A row without all three is markedSKIP: немає phone, email чи external_id.first_name,last_name,language,timezonego to the fields of the contact.- Any other column goes to the properties of the event under its own name, a Cyrillic header too.
- Write
phone,email,external_id,first_nameexactly so, in lower case. The synonymsТелефон,Номер телефону,Phone numberare read asphone;Електронна поштаandE-mailasemail;Ім'яandNameasfirst_name— in synonyms capital letters do not matter. - Dates in cells are sent as ISO 8601 in UTC.
How the rows are sent:
- a change of the
statuscolumn by hand sends the row; - a response of a Google Form linked to the table is sent at once;
- rows added not by hand — an import, another system — are sent every 10 minutes, if
SEND_NEW_ROWS = true.
The result is written to flow_sent: OK 200; ERR — a network error, 429 or 5xx, repeated in 10 minutes;
FAIL — 4xx, not repeated; SKIP — the row was not sent.
Step 3. Send a test
Add a row with your own phone and change its status by hand. flow_sent shows OK 200, and the event appears in
Flows → Connections → Event journal. The connection shows
Recognised: Google Sheets (Apps Script).
Events
| The row | AlphaFlow event | Columns |
|---|---|---|
Without the event column | order_created (DEFAULT_EVENT) | order_id, total |
event — order_status_changed | order_status_changed | order_id, status |
event — appointment_scheduled | appointment_scheduled | appointment_id, visit_at |
Do not keep a name like order_paid or order_shipped in the event column of a row whose status still changes:
every change of status sends the row again under the same name, and a partly paid order would reach the customer as
"paid". Leave order_status_changed and check status in the conditions of the flow.
The script sends a body like this:
{
"event": "order_status_changed",
"contact": { "phone": "380671234567" },
"traits": { "first_name": "Олена" },
"properties": { "order_id": "A-1042", "total": 1250.5, "status": "Відправлено", "visit_at": "2026-11-20T10:00:00.000Z" },
"message_id": "sheet:123456:9f2a65001478379c0fb36fde20232f63",
"dedupe_key": "A-1042",
"occurred_at": "2026-11-16T17:00:16.450Z",
"context": { "source": "google_sheets", "sheet": "Замовлення", "row": 2 }
}
message_id is built from order_id (or appointment_id, or the number of the row), the event and the status:
writing the same status again sends nothing, a new status starts a new event. Without order_id the key is the
number of the row, and sorting the sheet changes it. occurred_at is the time of sending. The names of the events
are the ones the ready-made templates expect — see Recommended events.
Good to know
- The script repeats
ERRrows itself every 10 minutes, up to 200 rows per run. - The handlers are called
onEditFlowandonFormSubmitFlow, notonEdit: a simpleonEdittrigger cannot callUrlFetchApp, and a function with that name would run twice. Do not rename them. - Only edits by hand fire the edit trigger: edits by other scripts, by the API and imports do not, so for them set
SEND_NEW_ROWS = true. The script's own writes toflow_sentdo not fire it either. - A phone without the country code that lost its leading 0 cannot be read by AlphaFlow.
- The address always answers
200. Above the daily event limit the event is refused in AlphaFlow withquota_exceededand shown in the journal, whileflow_sentshowsOK 200.