Simple WhatsApp API using whatsmeow that receives webhooks and sends messages.
- 📱 Connect WhatsApp via web-based QR code (no terminal needed!)
- 📤 Send WhatsApp messages via HTTP POST
- 💾 Persistent session storage
- 🔍 Health check endpoint
- Install dependencies:
go mod download- Run the server:
go run main.go- Open browser and go to
http://localhost:8080/qrto scan QR code
Homepage with API documentation
Display QR code for WhatsApp connection
- Opens a web page with QR code
- Scan with WhatsApp on your phone
- Auto-refreshes until connected
- No terminal access needed!
Send a WhatsApp message
Request:
{
"phone": "523332015171",
"message": "Hello from the API!"
}Response:
{
"success": true,
"message": "Message sent successfully"
}Check connection status
Response:
{
"status": "connected",
"connected": true,
"qr_available": false
}Status values:
connected- WhatsApp is connected and readywaiting_for_qr_scan- QR code is available at /qrdisconnected- Not connected
# Send a message
curl -X POST https://your-app.railway.app/send \
-H "Content-Type: application/json" \
-d '{
"phone": "521234567890",
"message": "Test message"
}'
# Check status
curl https://your-app.railway.app/healthPersistencia: SÍ (automática)
✅ $5/mes gratis (suficiente para este proyecto) ✅ Persistencia automática del filesystem ✅ Deploy super fácil ✅ Logs en tiempo real ✅ Custom domains gratis
Pasos:
- Crea cuenta en https://railway.app
- "New Project" → "Deploy from GitHub repo"
- Selecciona tu repo
- Railway detecta el Dockerfile automáticamente
- Deploy!
- Abre
https://tu-app.railway.app/qrpara escanear QR - IMPORTANTE: Railway mantiene el filesystem, tu sesión persiste automáticamente
Costo: Gratis ($5 crédito/mes, este proyecto usa ~$2-3/mes)
Persistencia: SÍ (con volumen)
✅ Tier gratis con 3 VMs ✅ Volúmenes persistentes incluidos ✅ Global deployment ✅ CLI poderoso
Pasos:
- Instala Fly CLI:
curl -L https://fly.io/install.sh | sh - Login:
fly auth login - En tu proyecto:
fly launch(usa el fly.toml incluido) - Crea volumen:
fly volumes create whatsapp_data --size 1 - Deploy:
fly deploy - Abre:
https://tu-app.fly.dev/qr
Costo: Gratis (con límites generosos)
Persistencia: NO en tier gratis
Solo recomiendo si pagas: Plan "Starter" ($7/mes) incluye persistent disk
Persistencia: NO en tier gratis
❌ No soporta volúmenes persistentes en free tier ❌ No recomendado para este proyecto
| Servicio | Persistencia Gratis | Costo | Recomendación |
|---|---|---|---|
| Railway | ✅ Sí | $0-3/mes | ⭐⭐⭐⭐⭐ |
| Fly.io | ✅ Sí | $0 | ⭐⭐⭐⭐ |
| Render | ❌ No | $7/mes | ⭐⭐ |
| Koyeb | ❌ No | $0 | ❌ |
Railway es la mejor opción porque:
- Persistencia automática - no necesitas configurar nada
- $5 gratis/mes - suficiente para este proyecto
- Super fácil - conectas GitHub y listo
- Logs en vivo - ves todo en tiempo real
- QR en el browser - abres /qr y escaneas
- Abre
https://tu-app.railway.app/qren tu navegador - Escanea el QR con WhatsApp
- ¡Listo! La página se actualiza cuando conecta
- Los logs muestran el QR en texto
- También puedes verlo en Railway logs
# Ver si necesitas escanear QR
curl https://tu-app.railway.app/health
# Si status es "waiting_for_qr_scan", abre /qr en browser- Phone number format: Use country code + number (e.g., "521234567890" for Mexico)
- Session persistence: The
whatsapp.dbfile stores your session - QR Scanning: Go to
/qrendpoint to see QR code in browser - Reconnection: If disconnected, go back to
/qrto get new QR code
PORT: Server port (default: 8080, Railway sets this automatically)
For production use, consider adding:
- API key authentication
- Rate limiting
- HTTPS only (Railway provides this automatically)
- Input validation
- Webhook signature verification
"WhatsApp client is not connected"
- Go to
/qrendpoint and scan QR code - Check
/healthto see current status
QR code not showing
- Wait a few seconds, the page auto-refreshes
- Check Railway logs for errors
Session lost after restart
- Make sure you're using Railway or Fly.io with volumes
- Render free tier will lose session on restart