A sophisticated WhatsApp bot powered by Groq AI that can automatically respond to messages from specific contacts using the Llama3 model. The project also includes a Next.js web interface for potential future enhancements.
- AI-Powered Responses: Uses Groq's Llama3-70b model to generate contextual responses
- WhatsApp Integration: Built with whatsapp-web.js for seamless WhatsApp Web connectivity
- QR Code Authentication: Easy setup with QR code scanning
- Contact-Specific Targeting: Responds only to messages from predefined contacts
- Italian Language Support: Optimized for Italian conversations with casual writing style
- Next.js Web Interface: Modern web interface for future dashboard features
- Node.js (v16 or higher)
- npm, yarn, pnpm, or bun package manager
- WhatsApp account
- Groq API key
-
Clone the repository
git clone <repository-url> cd WhatsappBot
-
Install dependencies
npm install # or pnpm install -
Set up environment variables Create a
.envfile in the root directory:GROQ_API_KEY=your_groq_api_key_here
-
Configure contacts Edit the
contactsobject inmain.jsto add your specific contact information:const contacts = { contact_name: "[email protected]", // Add more contacts as needed };
-
Start the bot
npm start <contact_name>
Replace
<contact_name>with one of the contact names defined in your contacts object. -
Scan QR Code
- A QR code will appear in your terminal
- Open WhatsApp on your phone
- Go to Settings > Connected Devices > Connect Device
- Scan the QR code displayed in the terminal
-
Bot is Ready
- Once connected, the bot will automatically respond to messages from the specified contact
- The AI will generate responses in Italian with a casual writing style
-
Start the development server
npm run dev # or pnpm dev -
Open your browser Navigate to http://localhost:3000 to view the web interface.
- Message Reception: The bot listens for incoming messages from the specified contact
- AI Processing: Messages are sent to Groq's Llama3-70b model with a system prompt that:
- Sets the AI to respond as if it were you
- Optimizes for Italian language
- Uses casual writing style (no capital letters, minimal punctuation)
- Response Generation: The AI generates contextual responses
- Message Sending: Responses are sent back through WhatsApp
WhatsappBot/
├── app/ # Next.js app directory
│ ├── globals.css # Global styles
│ ├── layout.tsx # Root layout component
│ └── page.tsx # Main page component
├── public/ # Static assets
├── main.js # Main WhatsApp bot logic
├── package.json # Dependencies and scripts
├── next.config.mjs # Next.js configuration
├── tailwind.config.ts # Tailwind CSS configuration
└── tsconfig.json # TypeScript configuration
Edit the contacts object in main.js:
const contacts = {
contact_alias: "[email protected]",
// Example:
// friend: "[email protected]",
// family: "[email protected]",
};Modify the system prompt in getGroqChatCompletion() function to change the AI's personality and response style.
Uncomment and adjust the delay mechanism in the message handler to add random delays between responses:
const delay = Math.random() * (20 * 60 - 2) + 2; // 2 seconds to 20 minutes
await new Promise((resolve) => setTimeout(resolve, delay * 1000));- Model:
llama3-70b-8192 - Provider: Groq
- Authentication: API key via environment variable
- Uses remote web version cache for stability
- Handles QR authentication automatically
- Provides message listening and sending capabilities
- API Keys: Store your Groq API key securely in environment variables
- Contact Privacy: Phone numbers are stored locally in the code
- Message Privacy: Messages are sent to Groq AI for processing
- Authentication: Uses WhatsApp's official web authentication
whatsapp-web.js- WhatsApp Web API clientgroq-sdk- Groq AI API clientqrcode-terminal- QR code generation in terminalnext- React framework for the web interfacetailwindcss- Utility-first CSS framework
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request