A free WhatsApp OTP (One-Time Password) verification service built using whatsapp-web.js and Express.
- Send OTP verification codes via WhatsApp
- Verify OTP responses through WhatsApp or API
- Easy to integrate with any application
- Deployable on Railway
- Node.js 14+ installed
- A WhatsApp account with an active number
- Clone this repository:
git clone https://github.com/yourusername/whatsapp-otp.git
cd whatsapp-otp
- Install dependencies:
npm install
- Start the application:
npm start
- When you first run the application, a QR code will be displayed in the terminal. Scan this with your WhatsApp mobile app:
- Open WhatsApp on your phone
- Tap Menu or Settings
- Select WhatsApp Web
- Scan the QR code displayed in the terminal
Send a POST request to /send-otp with the following JSON payload:
{
"phoneNumber": "201234567890" # 20 if for Egyptian number prefix
}The phone number should be in international format without any symbols (e.g., "1234567890").
OTPs can be verified in two ways:
-
Via WhatsApp: The recipient can simply reply to the WhatsApp message with the OTP code.
-
Via API: Send a POST request to
/verify-otpwith the following JSON payload:
{
"phoneNumber": "201234567890",
"otp": "123456"
}-
Create a Railway account at railway.app
-
Install the Railway CLI:
npm i -g @railway/cli
- Login to Railway:
railway login
- Initialize Railway in your project:
railway init
- Deploy your app:
railway up
-
After deployment, visit your deployed application's URL (e.g., https://your-app-name.railway.app) to see the QR code in the browser.
-
You can also access the QR code directly at the
/qrendpoint:https://your-app-name.railway.app/qr -
Scan the QR code with your WhatsApp app to authenticate.
-
After scanning, refresh the page to confirm authentication was successful.
If you encounter QR code issues in Railway:
-
Can't see the QR code in logs: The QR code in Railway's logs is often unreadable. Use the web interface instead by visiting your app's URL.
-
Authentication not persisting: Railway might not persist the WhatsApp session between deployments. You may need to re-authenticate after redeployments.
-
Session storage issues: To improve persistence, consider using a database or storage service instead of local auth storage.
GET /: Health check endpointPOST /send-otp: Send an OTP to a WhatsApp numberPOST /verify-otp: Verify an OTP via API
MIT