WhatsApp Messaging & Templates

All WhatsApp goes through wa-hub (triotoonz), plain-text send. The Vedamrita getaseed sender is NOT used by this app.

Sender config

  • Shared credentials: /root/.config/wa-hub.env (WA_HUB_TOKEN, WA_HUB_URL) — edit once, all apps read it. The backend loads it after its local .env.
  • Per-app brand: WHATSAPP_BRAND in the backend .env.

Template store (central)

Every message's wording lives in the wa_templates DB table — one row per message type. This is the single place to change what customers receive. Use {{var}} placeholders.

key when it sends variables
otp login OTP to the shopkeeper greeting, brand, code
reminder manual balance reminder (and auto-reminder job) name, shop, amount
udhaar_added customer's khata gets a credit (udhaar) entry name, shop, amount, note, balance
payment_received customer's khata gets a payment entry name, shop, amount, balance
welcome a customer with a phone is added name, shop
  • View via API: GET /api/templates (auth).
  • Edit (single-owner): update the row directly, e.g. UPDATE wa_templates SET text='...' WHERE key='reminder'; (picked up within ~60s; no restart needed).
  • Seeds run once (ON CONFLICT DO NOTHING) so npm run migrate never clobbers your edits.

Features

  1. OTP — login, via otp template.
  2. Entry notifications — when an entry is recorded for a customer who has a phone, they get a WhatsApp (udhaar_added / payment_received) with the amount and new balance. Fire-and-forget: a WhatsApp failure never blocks or fails the ledger write. Toggle with NOTIFY_ON_ENTRY=false.
  3. Manual reminder — POST /api/customers/:id/remind sends the reminder template with the current balance; logged in reminders.
  4. Auto reminders (opt-in, OFF by default) — backend/scripts/auto_reminders.js reminds every customer with a phone + outstanding balance not reminded in the last N days. Enable with AUTO_REMINDERS_ENABLED=true (+ AUTO_REMINDER_MIN_DAYS, default 7). Run manually to test: node scripts/auto_reminders.js --force. A disabled systemd timer udhaar-reminders.timer is installed; systemctl enable --now udhaar-reminders.timer to schedule it daily.

Safety notes

  • Auto-reminders are OFF by default so real customers are never auto-pinged without an explicit opt-in.
  • All sends are rate-paced and failures are swallowed + logged, never user-facing crashes.