whatsapp-ai-assistant
v1.0.0
Published
An AI-powered WhatsApp assistant bot with group management and file sharing capabilities
Maintainers
Readme
WhatsApp AI Assistant
An intelligent WhatsApp bot powered by Google's Gemini AI that can manage group statistics, document conversation lore, share files, send stickers, and provide AI-powered responses.
Features
- 🤖 AI-Powered Responses: Uses Google Gemini AI for intelligent conversations
- 📊 Group Statistics: Tracks message counts and member activity
- 📖 Lore Documentation: Automatically summarizes group conversations
- 📁 File Sharing: Share files from a designated directory
- 🎭 Sticker Support: Send custom stickers based on context
- 🔇 Ignore System: Ignore/unignore specific conversations
- ⚙️ Configurable: Easy configuration through JSON files
Installation
npm install -g whatsapp-ai-assistantQuick Start
Initialize a new bot project:
whatsapp-assistant init my-bot cd my-botConfigure your bot:
whatsapp-assistant configOr manually edit
config.json:{ "apiKey": "your-gemini-api-key-here", "sessionName": "my-whatsapp-bot", "headless": false, "loreMsgsNo": 3, "statsUpdateMsgs": 1, "statsResetDays": 7 }Add your content:
- Place files to share in the
files_to_share/directory - Add custom stickers to the
stickers/directory - Customize the AI prompt in
assets/public_prompt.txt
- Place files to share in the
Start your bot:
whatsapp-assistant start
Configuration
config.json Options
| Option | Description | Default |
|--------|-------------|---------|
| apiKey | Your Google Gemini API key | Required |
| sessionName | WhatsApp session name | "whatsapp-assistant" |
| headless | Run browser in headless mode | false |
| loreMsgsNo | Messages before documenting lore | 3 |
| statsUpdateMsgs | Messages before updating stats | 1 |
| statsResetDays | Days before resetting stats | 7 |
Getting a Gemini API Key
- Go to Google AI Studio
- Sign in with your Google account
- Create a new API key
- Copy the key and add it to your
config.json
Commands
CLI Commands
whatsapp-assistant init [directory]- Initialize a new bot projectwhatsapp-assistant start [-c config.json]- Start the botwhatsapp-assistant config- Interactive configuration
WhatsApp Commands
Private Message Commands
!ignoreor/ignore- Bot will ignore your messages!unignoreor/unignore- Bot will respond to your messages again
Group Commands
/stats- Show group statistics (message counts, top contributors)
Project Structure
After initialization, your project will have this structure:
my-bot/
├── config.json # Bot configuration
├── package.json # Project metadata
├── assets/ # Bot assets
│ ├── public_prompt.txt # AI system prompt
│ └── stickers.csv # Available stickers list
├── files_to_share/ # Files the bot can share
├── stickers/ # Custom sticker images
├── group_stats/ # Group statistics data
│ └── Backup/ # Stats backups
└── group_lores/ # Generated group lore summariesCustomization
AI Prompt
Edit assets/public_prompt.txt to customize how your AI assistant behaves. You can also create assets/prompt.txt for a private prompt that overrides the public one.
Stickers
- Add image files to the
stickers/directory - Update
assets/stickers.csvwith the format:emotion,filename,description happy,smile.png,A happy smiling face sad,cry.png,A crying face
File Sharing
Place any files you want the bot to be able to share in the files_to_share/ directory. Users can ask the bot to share these files.
Features in Detail
Group Statistics
- Tracks message counts per group and member
- Shows top 5 contributors
- Automatic periodic resets with backup
- Use
/statscommand in groups to view
Lore Documentation
- Automatically summarizes group conversations
- Creates narrative-style summaries
- Configurable message threshold
- Saved as text files in
group_lores/
AI Actions
The bot can perform various actions based on AI decisions:
- Answer questions
- Share files from the designated directory
- Send contextual stickers
- Ignore conversations when appropriate
Troubleshooting
Common Issues
"API key not found"
- Make sure you've added your Gemini API key to
config.json
- Make sure you've added your Gemini API key to
"Config file not found"
- Run
whatsapp-assistant initfirst - Make sure you're in the correct directory
- Run
WhatsApp connection issues
- Try setting
headless: falsein config to see the browser - Clear the session data and restart
- Try setting
Permission errors
- Make sure the bot has write permissions in the project directory
Debug Mode
Run with visible browser to debug WhatsApp connection issues:
{
"headless": false
}Development
To contribute or modify the package:
- Clone the repository
- Install dependencies:
npm install - Make your changes
- Test locally:
npm link
License
MIT License - see LICENSE file for details.
Support
For issues and feature requests, please visit the GitHub repository.
