A simple and efficient Telegram bot that provides English word definitions, pronunciations, and examples using the Free Dictionary API.
- π Word Definitions: Get comprehensive definitions for English words
- π€ Pronunciations: IPA phonetic transcriptions for proper pronunciation
- π Examples: Real-world usage examples for better understanding
- π― Part of Speech: Clear categorization (noun, verb, adjective, etc.)
- β‘ Fast Response: Quick dictionary lookups with timeout handling
- π‘οΈ Error Handling: Robust error management and user-friendly messages
- π Source Attribution: Credits Wiktionary as the data source
Send any English word to the bot and get instant definitions:
User: hello
Bot: **hello**
π€ /hΙΛlΙΚ/ β’ /hΙΛlΙΚ/ β’ /hΙΛloΚ/
π Meanings:
**interjection**: A greeting (salutation) said when meeting someone or acknowledging someone's arrival or presence.
_Example_: Hello, everyone.
**interjection**: A greeting used when answering the telephone.
_Example_: Hello? How may I help you?
_Source: Wiktionary_
- Python 3.7+
- A Telegram Bot Token from @BotFather
- Internet connection for API calls
-
Clone the repository
git clone https://github.com/yourusername/wordbot-telegram.git cd wordbot-telegram
-
Install dependencies
pip install -r requirements.txt
-
Set up environment variables
Create a
.env
file in the project root:BOT_TOKEN=your_telegram_bot_token_here
-
Run the bot
python main.py
Create a requirements.txt
file:
python-telegram-bot==20.7
requests==2.31.0
python-dotenv==1.0.0
wordbot-telegram/
β
βββ main.py # Main bot application
βββ .env # Environment variables (create this)
βββ requirements.txt # Python dependencies
βββ README.md # This file
- Open Telegram and search for @BotFather
- Start a chat and send
/newbot
- Follow the prompts to create your bot
- Copy the bot token and add it to your
.env
file
This bot uses the Free Dictionary API:
- Endpoint:
https://freedictionaryapi.com/api/v1/entries/en/
- Data Source: Wiktionary
- Rate Limiting: No official limits mentioned
- License: CC BY-SA 4.0
/start
- Welcome message and instructions- Send any English word - Get definition, pronunciation, and examples
- β Single English words (e.g., "hello", "computer", "amazing")
- β Common words and technical terms
- β Multiple definitions per word
- β Pronunciation guides (IPA format)
- β Usage examples
- β Multi-word phrases (currently not supported)
- β Non-English words
Variable | Description | Required |
---|---|---|
BOT_TOKEN |
Your Telegram bot token from BotFather | Yes |
You can modify these settings in main.py
:
# Maximum definitions per word (default: 5)
if definition_count >= 5:
break
# API timeout (default: 10 seconds)
response = requests.get(API_URL + word, timeout=10)
# Maximum pronunciations shown (default: 3)
if len(phonetic_texts) >= 3:
break
The bot handles various error scenarios:
- Network Issues: Timeout and connection errors
- Invalid Words: Words not found in dictionary
- API Errors: Service unavailable or malformed responses
- Rate Limiting: Automatic retry logic (if implemented)
- Multi-word Input: Prompts user to send single words only
The bot includes comprehensive logging:
# Log levels
INFO - Normal operations and successful requests
WARN - API issues and invalid responses
ERROR - Network errors and exceptions
Logs include:
- User requests and responses
- API call results
- Error details for debugging
python main.py
Using systemd (Linux):
- Create service file
/etc/systemd/system/wordbot.service
:
[Unit]
Description=WordBot Telegram Bot
After=network.target
[Service]
Type=simple
User=your-user
WorkingDirectory=/path/to/wordbot
ExecStart=/usr/bin/python3 /path/to/wordbot/main.py
Restart=always
[Install]
WantedBy=multi-user.target
- Enable and start:
sudo systemctl enable wordbot
sudo systemctl start wordbot
Using Docker:
FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["python", "main.py"]
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Bot not responding:
- Check if bot token is correct
- Verify internet connection
- Check logs for error messages
"Word not found" errors:
- API might be temporarily unavailable
- Try with common English words first
- Check API status at freedictionaryapi.com
Installation issues:
- Ensure Python 3.7+ is installed
- Try using virtual environment:
python -m venv venv source venv/bin/activate # Linux/Mac # or venv\Scripts\activate # Windows pip install -r requirements.txt
Enable debug logging by changing:
level=logging.DEBUG
This project is licensed under the MIT License - see the LICENSE file for details.
- Free Dictionary API for providing the dictionary data
- Wiktionary for the comprehensive word database
- python-telegram-bot library for Telegram integration
If you encounter any issues or have questions:
- Check the Troubleshooting section
- Review the logs for error messages
- Open an issue on GitHub with:
- Error message/logs
- Steps to reproduce
- Your environment details
Happy word learning! πβ¨