Skip to content

SzczepanBEN/whatsapp-translator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

WhatsApp Translator

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.

Features

  • Text message translation
  • Voice message transcription and translation
  • Configurable target language
  • Automatic service management with systemd
  • Error handling and automatic retries
  • Rotating log files

Prerequisites

  • Python 3.10 or higher
  • ffmpeg (for audio processing)
  • WhatsApp Business API access
  • OpenAI API key

Installation

  1. Clone the repository:
git clone https://github.com/SzczepanBEN/whatsapp-translator.git
cd whatsapp-translator
  1. Install required packages:
pip install -r requirements.txt
  1. Install ffmpeg:
sudo apt-get update
sudo apt-get install ffmpeg
  1. Copy the example environment file and fill in your credentials:
cp .env.example .env
  1. 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-translator

Configuration

Edit the .env file with your credentials:

  • OPENAI_API_KEY: Your OpenAI API key
  • WHATSAPP_VERIFY_TOKEN: A random string for webhook verification
  • WHATSAPP_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 ID
  • TARGET_LANGUAGE: The language to translate messages to (default: "Polish", you can change it to any language you want like "English", "German", "French", etc.)

Usage

  1. Set up your WhatsApp Business API webhook to point to your server: https://your-domain.com/webhook (you can run it locally using ngrok)

  2. 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

Monitoring

Check service status:

sudo systemctl status whatsapp-translator

View logs:

# Service logs
sudo journalctl -u whatsapp-translator -f

# Application logs
tail -f app.log

Error Handling

The application includes:

  • Automatic retries for API calls
  • Temporary file cleanup
  • Detailed logging
  • Error notifications to users

License

MIT License

Author

Szczepan BEN

About

Whatsapp text+audio message translator. Any language. Forward a message to the bot and get a transcript and translation.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages