Skip to content

projectninjatech/wordbot-telegram

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

WordBot - Telegram Dictionary Bot πŸ“š

A simple and efficient Telegram bot that provides English word definitions, pronunciations, and examples using the Free Dictionary API.

Features ✨

  • πŸ” 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

Demo

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_

Prerequisites πŸ“‹

  • Python 3.7+
  • A Telegram Bot Token from @BotFather
  • Internet connection for API calls

Installation πŸš€

  1. Clone the repository

    git clone https://github.com/yourusername/wordbot-telegram.git
    cd wordbot-telegram
  2. Install dependencies

    pip install -r requirements.txt
  3. Set up environment variables

    Create a .env file in the project root:

    BOT_TOKEN=your_telegram_bot_token_here
  4. Run the bot

    python main.py

Requirements πŸ“¦

Create a requirements.txt file:

python-telegram-bot==20.7
requests==2.31.0
python-dotenv==1.0.0

Project Structure πŸ“

wordbot-telegram/
β”‚
β”œβ”€β”€ main.py                 # Main bot application
β”œβ”€β”€ .env                    # Environment variables (create this)
β”œβ”€β”€ requirements.txt        # Python dependencies
└── README.md              # This file

Getting a Telegram Bot Token πŸ€–

  1. Open Telegram and search for @BotFather
  2. Start a chat and send /newbot
  3. Follow the prompts to create your bot
  4. Copy the bot token and add it to your .env file

API Information πŸ”Œ

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

Usage πŸ’¬

Available Commands

  • /start - Welcome message and instructions
  • Send any English word - Get definition, pronunciation, and examples

Supported Features

  • βœ… 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

Configuration βš™οΈ

Environment Variables

Variable Description Required
BOT_TOKEN Your Telegram bot token from BotFather Yes

Customization Options

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

Error Handling πŸ› οΈ

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

Logging πŸ“Š

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

Deployment Options 🌐

Local Development

python main.py

Production Deployment

Using systemd (Linux):

  1. 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
  1. 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"]

Contributing 🀝

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Troubleshooting πŸ”§

Common Issues

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

Debug Mode

Enable debug logging by changing:

level=logging.DEBUG

License πŸ“„

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments πŸ™

Support πŸ’ͺ

If you encounter any issues or have questions:

  1. Check the Troubleshooting section
  2. Review the logs for error messages
  3. Open an issue on GitHub with:
    • Error message/logs
    • Steps to reproduce
    • Your environment details

Happy word learning! πŸ“šβœ¨

About

A simple Telegram bot that provides English word definitions using FreeDictionaryAPI.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages