From c214d643ddde5330edb8111f0a5af72f7db44189 Mon Sep 17 00:00:00 2001 From: xiaomai Date: Mon, 27 Apr 2026 13:12:25 +0800 Subject: [PATCH] feat: send ticket receipts via WhatsApp and normalize phone numbers Add WhatsApp API integration for automated receipt delivery Enforce country codes for all phone number inputs (defaults to +60) --- .env.example | 3 + README.md | 4 + app/pages/confirmation/[token].vue | 10 +- app/pages/index.vue | 15 ++- app/pages/management/users/index.vue | 11 +- app/pages/receipt/[token].vue | 2 +- docker-compose.dev.yml | 3 + docker-compose.yml | 3 + nuxt.config.ts | 3 + server/api/public/bookings.post.ts | 3 +- .../public/bookings/[token]/confirm.post.ts | 19 ++- server/utils/bookings.ts | 4 +- server/utils/db-init.ts | 2 +- server/utils/user-repository.ts | 7 +- server/utils/users.ts | 4 +- server/utils/whatsapp.ts | 111 ++++++++++++++++++ shared/auth.ts | 17 ++- shared/booking.ts | 15 +++ 18 files changed, 208 insertions(+), 28 deletions(-) create mode 100644 server/utils/whatsapp.ts diff --git a/.env.example b/.env.example index 58f6095..0bb0da4 100644 --- a/.env.example +++ b/.env.example @@ -1,6 +1,9 @@ NUXT_DATABASE_URL=postgresql://postgres:postgres@127.0.0.1:5432/dinner_ticket_system NUXT_REDIS_URL=redis://127.0.0.1:6379 NUXT_SESSION_COOKIE_NAME=dinner_ticket_session +NUXT_WHATSAPP_ACCESS_TOKEN= +NUXT_WHATSAPP_PHONE_NUMBER_ID= +NUXT_WHATSAPP_API_VERSION=v23.0 # Use your deployed HTTPS origin in production so WebAuthn/passkeys validate correctly. NUXT_PUBLIC_APP_URL=http://localhost:20013 diff --git a/README.md b/README.md index 7e39373..1f7c6d0 100644 --- a/README.md +++ b/README.md @@ -17,10 +17,14 @@ Create `.env` from `.env.example` and set: ```bash NUXT_DATABASE_URL=postgresql://postgres:postgres@127.0.0.1:5432/dinner_ticket_system NUXT_REDIS_URL=redis://127.0.0.1:6379 +NUXT_WHATSAPP_ACCESS_TOKEN= +NUXT_WHATSAPP_PHONE_NUMBER_ID= +NUXT_WHATSAPP_API_VERSION=v23.0 NUXT_PUBLIC_APP_URL=http://localhost:20013 ``` `NUXT_PUBLIC_APP_URL` should be your final HTTPS origin in production. Passkeys rely on the RP origin being stable and correct. +Set the WhatsApp variables to enable automatic ticket receipt delivery after PIC confirmation. Without them, confirmation still succeeds and the UI reports that WhatsApp delivery was skipped. ## Setup diff --git a/app/pages/confirmation/[token].vue b/app/pages/confirmation/[token].vue index 722faf5..ef7e1a0 100644 --- a/app/pages/confirmation/[token].vue +++ b/app/pages/confirmation/[token].vue @@ -1,5 +1,5 @@