/** * 3.8.0 (docs/APP-1.0-PLAN.md ยง8, decision 11): a STOP this site's WhatsApp webhook received is * passed on to the church's Accounts (`whatsapp.optout`, contracts 1.20.0), which keeps the opt-out * for every product (the App, the Website, Accounts' own codes) and tells them all. Never fails the * STOP itself: it's kept here either way. */ import { accounts, accountsLink } from './client'; import { viaAccounts } from './mode'; /** Passes a STOP on to Accounts; returns whether it did. `phone`: 27821234567. */ export async function stopInAccounts(phone: string, keyword: string): Promise { try { if (!(await viaAccounts())) return false; await (await accounts()).request({ type: 'whatsapp.optout', actor: null, phone: `+${phone.replace(/^\+/, '')}`, receivedAt: new Date().toISOString(), keyword: String(keyword || 'STOP').trim().toUpperCase().slice(0, 40) || 'STOP', }); return true; } catch (e) { console.warn('[accounts] WhatsApp STOP not passed on:', (e as Error).message); return false; } } /** Where someone turns WhatsApp back on: their account page in the church's Accounts. */ export async function accountPageUrl(): Promise { try { if (!(await viaAccounts())) return null; const link = await accountsLink(); return link ? `${link.url.replace(/\/$/, '')}/account` : null; } catch { return null; } }