A Node.js application that generates WhatsApp session credentials for bot development using the Baileys library. The session data is automatically sent to your WhatsApp number for easy access.
- π Generate WhatsApp session credentials (creds.json)
- π± Automatic session delivery via WhatsApp messages
- π Real-time Socket.IO communication
- π REST API endpoints
- π Session file management
- π Auto-reconnection handling
- πΎ Backup download option
- Node.js (v14 or higher)
- npm or yarn
- WhatsApp account
- Phone number for session generation
- Clone the repository:
git clone https://github.com/sadhfdrn/sessions.git
cd whatsapp-session-generator- Install dependencies:
npm install- Create public directory (if not exists):
mkdir public- Start the server:
npm startThe server will start on port 3000 by default.
{
"@fizzxydev/baileys-pro": "WhatsApp Web API library",
"@hapi/boom": "HTTP error handling",
"express": "Web framework",
"cors": "Cross-origin resource sharing",
"socket.io": "Real-time communication",
"pino": "Logging",
"archiver": "File compression"
}- Connect to the server via Socket.IO
- Emit
generateSessionevent with phone number - Receive pairing code via
pairingCodeevent - Enter the pairing code in WhatsApp
- Session will be automatically sent to your WhatsApp
Generate Session:
POST http://localhost:3000/api/generate-session
Content-Type: application/json
{
"phoneNumber": "1234567890"
}Generate a new WhatsApp session.
Request Body:
{
"phoneNumber": "1234567890"
}Response:
{
"success": true,
"message": "Session generation started",
"phoneNumber": "1234567890"
}Check server health and active sessions.
Response:
{
"status": "OK",
"activeSessions": 1,
"timestamp": "2025-05-30T12:00:00.000Z"
}Get list of active sessions.
Response:
{
"sessions": [
{
"phoneNumber": "1234567890",
"connected": true
}
]
}Download session files (backup option).
generateSession: Start session generationsocket.emit('generateSession', { phoneNumber: '1234567890' });
-
pairingCode: Receive pairing codesocket.on('pairingCode', (data) => { console.log('Pairing code:', data.pairingCode); });
-
connectionStatus: Connection status updatessocket.on('connectionStatus', (data) => { console.log('Status:', data.status); // 'initializing', 'connecting', 'connected', 'reconnecting', 'logged_out' });
-
sessionReady: Session is ready and sentsocket.on('sessionReady', (data) => { console.log('Session sent:', data.sessionSent); });
-
error: Error messagessocket.on('error', (data) => { console.log('Error:', data.message); });
- Initialization: Server creates a session directory for the phone number
- Pairing: Generates a pairing code that you enter in WhatsApp
- Authentication: Establishes connection with WhatsApp servers
- Session Creation: Combines authentication data into a single creds.json
- Delivery: Sends two WhatsApp messages:
- First: Usage instructions
- Second: creds.json content in one line
The generated session includes:
- Authentication credentials
- Pre-keys for encryption
- Sender keys for group messaging
- Timestamp for tracking
project/
βββ server.js # Main server file
βββ package.json # Dependencies and scripts
βββ README.md # This file
βββ public/ # Static files directory
βββ sessions/ # Generated session data
βββ session_[number]/ # Individual session folders
PORT: Server port (default: 3000)
The application handles various error scenarios:
- Invalid phone numbers
- Connection failures
- Authentication errors
- File system errors
- Network issues
- Session data contains sensitive authentication information
- Never share your creds.json file with others
- Store session data securely
- Regenerate sessions if compromised
- Use HTTPS in production environments
-
Session Generation Fails
- Verify phone number format
- Check internet connection
- Ensure WhatsApp is installed on the phone
-
Pairing Code Not Working
- Try generating a new session
- Verify the phone number is correct
- Check if WhatsApp is already connected elsewhere
-
Session Not Received
- Check WhatsApp messages
- Verify phone number format
- Look for download link in console
Enable debug logging by modifying the pino logger:
const logger = pino({ level: 'debug' });- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is for educational purposes. Please comply with WhatsApp's Terms of Service when using this tool.
This tool is provided as-is for educational and development purposes. Users are responsible for complying with WhatsApp's Terms of Service and applicable laws. The developers are not responsible for any misuse of this tool.
For issues and questions:
- Check the troubleshooting section
- Review the console logs
- Verify your setup against this README
- Create an issue in the repository
Made with β€οΈ for WhatsApp Bot Developers