Events 3.8.0, @crosscode/demo 1.1.0: STOP stops all WhatsApp, demo scenarios

Events 3.8.0 (one migration):
- STOP to the church's WhatsApp number stops all WhatsApp, not only news:
  checked before every sendText/sendPdf against WhatsAppStop (by number) and
  User.whatsappOptedOut (from Accounts' user.updated); 2FA codes go by email
- a STOP received here is passed on to Accounts (whatsapp.optout); START turns
  it back on without Accounts; Accounts turning it back on clears it here
- the eight demo scenarios as set-demo profiles, around each church's own
  people (@crosscode/demo, same accounts as Accounts) and campuses; the
  scenario's people are never removed from Accounts

@crosscode/demo 1.1.0: each person's gender.
crosscode script: scenarios as Events demo profiles; Events builds packages/demo.

Checked on PostgreSQL 18: the migration and every scenario loaded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-30 11:42:17 +02:00
co-authored by Claude Opus 5.5
parent 5b9dc559b6
commit 49153e6f07
26 changed files with 549 additions and 48 deletions
@@ -214,9 +214,11 @@ const handleWebhook = async (req, res) => {
/**
* An incoming WhatsApp message (WAWP `message` event). The only thing we act on is an
* opt-out reply — "STOP" — which stops News & announcements on WhatsApp for that number
* (event updates still go out). Only trusted when the URL carries our webhook secret,
* since WAWP doesn't sign webhooks.
* opt-out reply — "STOP". 3.8.0 (APP-1.0-PLAN decision 11): it stops all WhatsApp to that number
* from every one of the church's products, event updates and codes included: kept here
* (utils/whatsappStop), news turned off, and passed on to the church's Accounts, which tells the
* others. Turned back on in Accounts; a site without Accounts takes a "START" reply. Only trusted
* when the URL carries our webhook secret, since WAWP doesn't sign webhooks.
*/
async function handleIncomingMessage(req) {
const crypto = require('crypto');
@@ -236,16 +238,35 @@ async function handleIncomingMessage(req) {
prisma.appSetting.upsert({ where: { key: 'wawp_webhook_last_seen' }, update: { value: now }, create: { key: 'wawp_webhook_last_seen', value: now } }).catch(() => {});
const payload = req.body?.payload || {};
if (payload.fromMe || !isStopKeyword(payload.body)) return;
if (payload.fromMe) return;
const stop = isStopKeyword(payload.body);
const { isStartKeyword, recordStop, clearStop } = require('../utils/whatsappStop');
const { stopInAccounts, accountPageUrl } = require('../accounts/whatsappOptOut');
if (!stop && !isStartKeyword(payload.body)) return;
const phone = phoneFromChatId(payload.from);
if (!phone) {
// Groups, channels, and senders WhatsApp only identifies by a "LID" (no phone number).
console.warn('[whatsapp webhook] STOP from a sender without a phone number:', payload.from);
return;
}
const result = await whatsAppStop(phone);
if (!result) return;
await sendText(phone, "You won't get news and announcements from us on WhatsApp any more. You'll still get messages about events you've registered for.").catch(() => {});
const { getSettingSync } = require('../utils/settingsCache');
const church = getSettingSync('org_name', process.env.ORG_NAME || 'us');
const accountPage = await accountPageUrl();
if (!stop) {
// START: only without Accounts (with it, Accounts keeps the opt-out: turned back on there).
if (accountPage) {
await sendText(phone, `To get WhatsApp messages from ${church} again, turn them back on on your account page: ${accountPage}`, { evenIfStopped: true }).catch(() => {});
return;
}
await clearStop(phone);
await sendText(phone, `WhatsApp messages from ${church} are back on. Reply STOP at any time to stop them.`).catch(() => {});
return;
}
await recordStop(phone, { keyword: payload.body, source: 'events' });
await whatsAppStop(phone);
await stopInAccounts(phone, payload.body);
const undo = accountPage ? `To turn them back on, go to ${accountPage}` : 'Reply START to turn them back on.';
await sendText(phone, `You won't get WhatsApp messages from ${church} any more (event updates and codes come by email). ${undo}`, { evenIfStopped: true }).catch(() => {});
}
module.exports = {