A Flask-based WhatsApp bot that automatically translates messages to your desired language. It supports both text and voice messages, using OpenAI's GPT-3.5 for translation and Whisper for voice transcription.
- Text message translation
- Voice message transcription and translation
- Configurable target language
- Automatic service management with systemd
- Error handling and automatic retries
- Rotating log files
- Python 3.10 or higher
- ffmpeg (for audio processing)
- WhatsApp Business API access
- OpenAI API key
- Clone the repository:
git clone https://github.com/SzczepanBEN/whatsapp-translator.git
cd whatsapp-translator- Install required packages:
pip install -r requirements.txt- Install ffmpeg:
sudo apt-get update
sudo apt-get install ffmpeg- Copy the example environment file and fill in your credentials:
cp .env.example .env- Set up the systemd service:
sudo cp whatsapp-translator.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable whatsapp-translator
sudo systemctl start whatsapp-translatorEdit the .env file with your credentials:
OPENAI_API_KEY: Your OpenAI API keyWHATSAPP_VERIFY_TOKEN: A random string for webhook verificationWHATSAPP_ACCESS_TOKEN: Your WhatsApp Business API token (you can get it from https://developers.facebook.com/apps/)WHATSAPP_PHONE_NUMBER_ID: Your WhatsApp Business phone number IDTARGET_LANGUAGE: The language to translate messages to (default: "Polish", you can change it to any language you want like "English", "German", "French", etc.)
-
Set up your WhatsApp Business API webhook to point to your server:
https://your-domain.com/webhook(you can run it locally using ngrok) -
The bot will automatically:
- Translate any text message to the target language
- Transcribe and translate voice messages
- Send "Working on it..." message while processing
- Handle errors gracefully
Check service status:
sudo systemctl status whatsapp-translatorView logs:
# Service logs
sudo journalctl -u whatsapp-translator -f
# Application logs
tail -f app.logThe application includes:
- Automatic retries for API calls
- Temporary file cleanup
- Detailed logging
- Error notifications to users
MIT License
Szczepan BEN