A comprehensive WhatsApp Flow endpoint for managing hospital appointment bookings with encrypted interactions, featuring patient registration, appointment scheduling, and secure communication.
- Patient Registration: Support for new and existing patients
- Appointment Booking: Doctor and time slot selection
- Payment Method Selection: Private or insurance options
- Secure Communication: End-to-end encryption with WhatsApp Flow
- Multiple Clinics: Support for various medical specialties
- Environment-based Configuration: Secure credential management
- Node.js (v16.0.0 or higher)
- npm or yarn package manager
- WhatsApp Business API access
- RSA key pair for encryption
- Clone the repository:
git clone <repository-url>
cd whatsapp-flow-tools- Install dependencies:
npm install- Set up environment variables:
cp .env.example .env- Configure your
.envfile with actual values (see Configuration section below)
Create a .env file based on .env.example and configure the following variables:
| Variable | Description | Example |
|---|---|---|
RSA_PASSPHRASE |
Passphrase for RSA private key | your_secure_passphrase |
RSA_PRIVATE_KEY |
RSA private key for decryption | -----BEGIN RSA PRIVATE KEY----- ... |
API_BASE_URL |
Base URL for webhook endpoints | https://your-n8n-instance.domain.com |
API_SIGNUP_ENDPOINT |
Signup webhook path | /webhook/signup |
API_SIGNIN_ENDPOINT |
Sign-in webhook path | /webhook/sign_in |
API_BOOKING_ENDPOINT |
Booking submission webhook path | /webhook/submitbooking |
| Variable | Description | Default |
|---|---|---|
NODE_ENV |
Environment mode | development |
- Generate RSA Key Pair (if you don't have one):
# Generate private key
openssl genrsa -des3 -out private.pem 2048
# Generate public key
openssl rsa -in private.pem -outform PEM -pubout -out public.pem- Configure WhatsApp Flow:
- Upload the public key to WhatsApp Business Manager
- Add the private key content to
RSA_PRIVATE_KEYin your.envfile - Set the passphrase in
RSA_PASSPHRASE
Configure your n8n or webhook service with the following endpoints:
- Signup: Handles new patient registration
- Sign-in: Authenticates existing patients
- Booking: Processes appointment submissions
npm run devnpm startThe booking flow follows this sequence:
- ADMISSION - Clinic, doctor, date, time, patient type, and payment selection
- REGISTRATION (new patients) - Personal information form
- PASIEN (existing patients) - Sign-in with name/phone and birth date
- KONFIRMASI - Booking confirmation
- COMPLETE - Success screen with booking details
- All communication is encrypted using RSA + AES-128-GCM
- Environment variables store sensitive credentials
- Private keys are never exposed in code
- The
.envfile is automatically gitignored - Environment validation ensures all required variables are present
whatsapp-flow-tools/
├── hospital booking/
│ └── booking.js # Main flow endpoint
├── .env # Environment variables (gitignored)
├── .env.example # Environment template
├── .gitignore # Git ignore rules
├── package.json # Node.js dependencies
└── README.md # This file
The application automatically validates that all required environment variables are present on startup. If any are missing, it will throw a clear error message indicating which variables need to be configured.
-
Decryption Errors:
- Verify RSA private key format
- Check passphrase accuracy
- Ensure key matches WhatsApp public key
-
API Connectivity:
- Verify webhook URLs are accessible
- Check network connectivity
- Validate API endpoint responses
-
Environment Variables:
- Ensure
.envfile exists in project root - Check for typos in variable names
- Verify no trailing whitespace in values
- Ensure
Set NODE_ENV=development to enable detailed logging:
NODE_ENV=development npm startThis project extends the original WhatsApp Flow payload processor concept with hospital booking functionality.
- parseIncoming(body): Detects if body contains messages, statuses, or flow action
- normalizeMessages(entries): Flattens to uniform internal message objects
- buildFlowResponse({ type, data }): Returns object to JSON.stringify for Meta reply
- buildAck(): Minimal 200 OK payload
// inside an express /webhook POST handler
app.post('/webhook', (req, res) => {
const responsePayload = processWebhookBody(req.body);
res.status(200).json(responsePayload);
});- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
MIT License - see LICENSE file for details