Skip to main content

WhatsApp Integration

The system integrates with WhatsApp for notifications, aliyot alerts, and community messaging. Implementation relies on a library (likely whatsapp-web.js or similar) wrapped in a custom service.

Architecture

  • Isolation: Each user (Tenant) can have their own WhatsApp session (sessionId linked to userId).
  • Events: Integration uses EventsService to broadcast status updates (e.g., whatsapp:authenticated, ready, qr).

Connection Flow

  1. Initialize: POST /whatsapp/connect - Starts the backend worker for the user's session.
  2. QR Code: GET /whatsapp/qr - Client polls this to display the QR code for pairing.
  3. Status: GET /whatsapp/status - Returns current state (CONNECTED, PAIRING, DISCONNECTED).

Capabilities

Messaging

  • Text Messages: Send standard text messages.
  • Media: Send images/files (SendMediaDto).
  • Contacts: Share contact cards (SendContactDto).
  • Location: Share locations (SendLocationDto).
  • Polls: Create polls (SendPollDto).

Aliyot Publisher

The WhatsappAliyaPublisherService handles formatted messages for Torah readings (Aliyot), allowing Gabba'im to send the list of Olim directly to a group or list.

Internal APIs

  • emit-test: Debug endpoint to test WebSocket events.
  • connection/retry: Force retry logic for stuck sessions.
  • logout: Gracefully terminates the session and cleans up local auth files.

Security

All endpoints require Permission.MANAGE_WHATSAPP. Session directory/files must be securely stored and isolated by userId to prevent data leaks between tenants.