Static page with SMS/email waitlist (Google Sheet via Apps Script), B2B onboarding call/email CTA, branches and FAQ. Logo, icons, product images and brand tokens taken from the Gishen monorepo. TASKS.md tracks Kerod's inbox setup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
49 lines
2.3 KiB
JavaScript
49 lines
2.3 KiB
JavaScript
// Gishen waitlist backend: a Google Sheet + this Apps Script.
|
|
// Setup: create a Sheet → Extensions → Apps Script → paste this file → Deploy → New deployment →
|
|
// Web app, Execute as "Me", Access "Anyone" → copy the /exec URL into ENDPOINT in index.html.
|
|
// NOTIFY: every signup is also emailed here. Set it to the inbox Kerod sets up (see TASKS.md).
|
|
const NOTIFY = 'info@gishenpharmacy.org';
|
|
const HEADERS = ['createdAt', 'name', 'phone', 'email', 'channel', 'locale', 'page'];
|
|
|
|
function sheet_() {
|
|
const sh = SpreadsheetApp.getActiveSpreadsheet().getSheets()[0];
|
|
if (sh.getLastRow() === 0) sh.appendRow(HEADERS);
|
|
return sh;
|
|
}
|
|
|
|
const json_ = (o) => ContentService.createTextOutput(JSON.stringify(o)).setMimeType(ContentService.MimeType.JSON);
|
|
|
|
// GET → { count } for the "N people are already waiting" pill.
|
|
function doGet() {
|
|
return json_({ count: Math.max(sheet_().getLastRow() - 1, 0) });
|
|
}
|
|
|
|
function doPost(e) {
|
|
try {
|
|
const d = JSON.parse(e.postData.contents || '{}');
|
|
if (d.company) return json_({ ok: true }); // honeypot: bots fill the hidden field
|
|
const name = String(d.name || '').trim().slice(0, 120);
|
|
const phone = /^\+\d{8,15}$/.test(d.phone || '') ? d.phone : '';
|
|
const email = /^[^@\s]+@[^@\s]+\.[^@\s]+$/.test(d.email || '') ? String(d.email).toLowerCase().slice(0, 200) : '';
|
|
if (name.length < 2 || (!phone && !email)) return json_({ ok: false, error: 'invalid' });
|
|
|
|
const lock = LockService.getScriptLock();
|
|
lock.waitLock(10000);
|
|
try {
|
|
const sh = sheet_();
|
|
const rows = sh.getLastRow() > 1 ? sh.getRange(2, 3, sh.getLastRow() - 1, 2).getValues() : [];
|
|
// Prefix with ' so Sheets keeps +251… as text, not a number.
|
|
const dup = rows.some(([p, m]) => (phone && String(p).replace(/^'/, '') === phone) || (email && m === email));
|
|
if (!dup) {
|
|
sh.appendRow([new Date(), name, phone ? "'" + phone : '', email, d.channel === 'email' ? 'email' : 'sms', String(d.locale || '').slice(0, 20), String(d.page || '').slice(0, 200)]);
|
|
if (NOTIFY) MailApp.sendEmail(NOTIFY, 'New Gishen waitlist signup: ' + name, [name, phone, email].filter(String).join('\n'));
|
|
}
|
|
} finally {
|
|
lock.releaseLock();
|
|
}
|
|
return json_({ ok: true });
|
|
} catch (err) {
|
|
return json_({ ok: false, error: 'server' });
|
|
}
|
|
}
|