Prerequisites
Before installing WhatsApp Group Manager, ensure you have the following:Required Software
Node.js 18+
JavaScript runtime required for Next.jsDownload Node.js
pnpm
Fast, disk-efficient package manager
MongoDB
NoSQL database for data storageMongoDB Atlas (Cloud) or local installation
WAHA Server
WhatsApp HTTP API for connectivityWAHA Documentation
Required Services
MongoDB Database
MongoDB Database
Option 1: MongoDB Atlas (Recommended for beginners)
- Create a free account at MongoDB Atlas
- Create a new cluster (free tier available)
- Add your IP to the whitelist (or allow access from anywhere for development)
- Create a database user with read/write permissions
- Get your connection string (looks like
mongodb+srv://user:[email protected]/dbname)
WAHA (WhatsApp HTTP API)
WAHA (WhatsApp HTTP API)
WAHA provides the WhatsApp connectivity layer. You have several options:Option 1: Docker (Recommended)Option 2: Cloud HostedUse a cloud-hosted WAHA instance from providers or deploy to your own VPS.Option 3: NPM
Make note of your WAHA URL (default:
http://localhost:3000) and API key for configuration.Mailgun Account
Mailgun Account
Required for password reset and admin notification emails:
- Sign up at Mailgun
- Verify your email domain (or use sandbox domain for testing)
- Get your API key from the dashboard
- Note your domain name (e.g.,
mg.yourdomain.com)
Local Development Setup
Install Dependencies
Install all project dependencies using pnpm:This command will:
- Install all packages from
package.json - Run the
postinstallscript to generate Prisma client - Set up the development environment
Configure Environment Variables
Create your environment configuration file:Edit
.env with your actual configuration:Generate Secure Secrets
Generate a cryptographically secure secret for Better Auth:Use the output as your
BETTER_AUTH_SECRET value.Set Up Database
Push the Prisma schema to your MongoDB database:This creates all necessary collections:
user- User accounts and authenticationsession- User sessionsaccount- OAuth accounts and passwordsWhatsAppSession- WhatsApp connection sessionsWhatsAppGroup- Synced WhatsApp groupsMessageCampaign- Message campaignsMessage- Individual scheduled messagesVerification- Email verification tokens
Start Development Server
Start Message Scheduler
In a separate terminal, start the background scheduler:The scheduler:
- Runs independently of the Next.js app
- Checks for pending messages every 30 seconds
- Automatically sends messages at scheduled times
- Logs all activity to the console
The scheduler must run continuously for automated message delivery. In production, use PM2 or similar process manager.
Production Deployment
Frontend Deployment (Vercel)
Deploy the Next.js application to Vercel for optimal performance:Import to Vercel
- Visit Vercel
- Click “Add New Project”
- Import your GitHub repository
- Configure project settings:
- Framework Preset: Next.js
- Build Command:
pnpm build(default) - Output Directory:
.next(default)
Backend Scheduler (DigitalOcean VPS)
The message scheduler needs to run on a server 24/7. Here’s how to deploy it to a VPS:Create DigitalOcean Droplet
Create a VPS to run the scheduler:
- Get $200 in credits (referral link)
- Create a new Droplet:
- Distribution: Ubuntu 22.04 LTS
- Plan: Basic ($6/month, 1GB RAM is sufficient)
- Datacenter: Choose closest to your WAHA server
- Authentication: SSH keys recommended (or password for beginners)
Deploy Application
Clone your repository and set up the scheduler:Add your production environment variables:Save and exit (Ctrl+X, then Y, then Enter).
Start with PM2
Use PM2 to run the scheduler as a persistent background service:The scheduler will now:
- Run automatically on server restart
- Restart automatically if it crashes
- Log all activity for monitoring
Updating Production Deployment
To update your production scheduler:Environment Variables Reference
MongoDB connection stringFormat:
mongodb+srv://username:[email protected]/database-nameExample: mongodb+srv://admin:[email protected]/whatsapp-prodBase URL of your WAHA serverExample:
http://localhost:3000 or https://waha.yourdomain.comAPI key for authenticating with WAHAExample:
abc123xyz789Secret key for Better Auth session encryptionGenerate with:
openssl rand -base64 32Example: xK8vN2mP9qR4sT5uV6wX7yZ8aB1cD2eF3gH4iJ5kL6==Base URL of your applicationDevelopment:
http://localhost:3001Production: https://your-app.vercel.appMailgun API key for sending emailsFormat:
key-xxxxxxxxxxxxxxxxxxxxxxxxFind in: Mailgun Dashboard → Settings → API KeysYour verified Mailgun domainExample:
mg.yourdomain.com or sandboxxxxx.mailgun.orgEmail address to send from (must use Mailgun domain)Example:
[email protected]Admin email for receiving notificationsExample:
[email protected]Admin WhatsApp number for notificationsFormat: Include country code with +Example:
+1234567890Show or hide footer in applicationDefault:
trueOptions: true or falseDatabase Schema Overview
The application uses these main collections:User & Authentication
User & Authentication
- user: User accounts with roles (ADMIN, USER, GUEST)
- session: Active user sessions with expiry
- account: Password hashes and OAuth provider data
- verification: Email verification tokens
WhatsApp Connections
WhatsApp Connections
- WhatsAppSession: Connected WhatsApp accounts
sessionName: Unique session identifierphoneNumber: Connected phone numberstatus: CONNECTED or DISCONNECTED
- WhatsAppGroup: Synced WhatsApp groups
groupName: Display namegroupId: WhatsApp group ID
Campaign Management
Campaign Management
- MessageCampaign: Scheduled campaigns
title: Campaign nametemplate: Message template with placeholderssendTimeUtc: Scheduled send timestatus: DRAFT, SCHEDULED, IN_PROGRESS, COMPLETED, CANCELLED, FAILED
- Message: Individual messages to send
content: Processed message contentscheduledAt: When to sendsentAt: When actually sentisSent: Delivery status
Available Scripts
Troubleshooting
Prisma Client Generation Failed
Prisma Client Generation Failed
Error:
@prisma/client did not initialize yetSolution:MongoDB Connection Issues
MongoDB Connection Issues
Error:
Error connecting to database or ECONNREFUSEDSolutions:- Verify
DATABASE_URLis correctly formatted - For MongoDB Atlas:
- Whitelist your IP address in Network Access
- Check username/password are URL-encoded
- Ensure database user has read/write permissions
- For local MongoDB:
- Ensure MongoDB service is running
- Try
mongodb://localhost:27017/whatsapp-manager
WAHA Connection Failed
WAHA Connection Failed
Error:
Cannot connect to WAHA serverSolutions:- Verify WAHA is running:
curl http://localhost:3000/health - Check
WAHA_API_URLpoints to correct address - Verify
WAHA_API_KEYmatches WAHA configuration - Ensure no firewall blocking the connection
Email Sending Fails
Email Sending Fails
Error:
Failed to send email or Mailgun errorsSolutions:- Verify Mailgun API credentials are correct
- Check domain is verified in Mailgun dashboard
- Ensure
FROM_EMAILuses your Mailgun domain - For sandbox domain, add recipient email to authorized recipients
Messages Not Sending Automatically
Messages Not Sending Automatically
Issue: Scheduled messages remain in SCHEDULED statusSolutions:
- Ensure scheduler is running:
pnpm scheduler:start - Check scheduler logs for errors
- Verify scheduled time is in the past (UTC)
- Check WhatsApp session is CONNECTED
- Ensure WAHA server is accessible from scheduler
Port 3001 Already in Use
Port 3001 Already in Use
Error:
Port 3001 is already in useSolution:Security Best Practices
- Never commit
.envfile to version control - Use strong, unique secrets for
BETTER_AUTH_SECRETin production - Rotate API keys regularly (Mailgun, WAHA)
- Enable MongoDB authentication and use strong passwords
- Restrict MongoDB network access to your server IPs only
- Use HTTPS for production deployments (Vercel provides this automatically)
- Set up IP whitelisting for WAHA if possible
- Regularly update dependencies with
pnpm update - Monitor logs for suspicious activity
- Backup database regularly (MongoDB Atlas has automated backups)
Next Steps
After successful installation:User Guide
Learn how to use the dashboard and manage campaigns
API Documentation
Explore tRPC API endpoints and integration options
Contributing
Contribute to the project on GitHub
Support
Get help and report issues