I chose to create this project when I was discussing with a friend about the channels you could use to interact with a LLM. The Telegram platform provides you with the ability to build a bot you can message via text and voice. You could use these capabilities for your own personal LLM that acts on assignments via Telegram and limit access by only accepting request from your personal ID. This project is the foundation for this capability.
- Telegram Integration: Seamless communication through Telegram messaging
- Text Message Processing: Handles incoming text messages and provides intelligent responses
- Voice Message Support: Downloads and processes voice messages (conversion to text ready for implementation)
- Group Chat Support: Welcomes users when added to groups and maintains conversation flow
- Modular Architecture: Clean separation of concerns with dedicated modules for different functionalities
- Extensible Design: Ready for AI/LLM integration to provide intelligent responses
- Python 3.7+
- Telegram Bot Token (obtain from @BotFather)
- Environment variables configuration
-
Clone the repository
git clone https://github.com/yourusername/duane-ai-helper.git cd duane-ai-helper -
Create a virtual environment (recommended)
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Configure environment variables Create a
.envfile in the root directory:BOT_TOKEN=your_telegram_bot_token_here
-
Run the bot
python main.py
duane-ai-helper/
βββ main.py # Main application entry point
βββ requirements.txt # Python dependencies
βββ .env # Environment variables (create this)
βββ .gitignore # Git ignore rules
βββ util/ # Utility modules
β βββ telegram.py # Telegram API interactions
βββ audio/ # Voice message storage
βββ venv/ # Virtual environment
Create a .env file with the following variables:
| Variable | Description | Required |
|---|---|---|
BOT_TOKEN |
Your Telegram bot token from @BotFather | β Yes |
- Message @BotFather on Telegram
- Create a new bot with
/newbot - Copy the provided token
- Add it to your
.envfile
Once configured, run the bot with:
python main.pyThe bot will:
- Connect to Telegram API
- Start polling for messages
- Process incoming text and voice messages
- Send appropriate responses
- Text Messages: Send any text message to get a response
- Voice Messages: Send voice messages (currently downloads and saves audio files)
- Group Chats: Add the bot to groups for automated welcome messages
The bot currently handles:
- β Text message reception and basic echo responses
- β Voice message download and storage
- β Group chat integration with welcome messages
- β Error handling and logging
- β Modular architecture for easy extension
- π² AI Integration: Connect to LLM services (OpenAI, Anthropic, etc.)
- π² Voice-to-Text: Convert voice messages to text
- π² Contextual Responses: Maintain conversation context
- π² Command System: Add specific bot commands
- π² Database Integration: Store user preferences and conversation history
- π² Multi-language Support: Internationalization
The project is structured to easily add AI capabilities. The util/llm.py file is ready for implementation:
# Example integration point in main.py
# Replace: reply_text = f"You said: {text}"
# With: reply_text = llm.generate_response(text)def process_updates(bot_token: str, updates: list) -> int:
for update in updates:
message = update.get('message')
if message:
chat_id = message.get('chat', {}).get('id')
text = message.get('text', '')
# Process text message
if text:
reply_text = f"You said: {text}"
telegram.send_message(bot_token, chat_id, reply_text)elif voice:
voice_audio_file = telegram.download_voice_message(bot_token, message)
print(f"Voice message saved to: {voice_audio_file}")
reply_text = "Voice messages are not supported yet."
telegram.send_message(bot_token, chat_id, reply_text)- Start the bot
- Send text messages to your bot on Telegram
- Test voice message functionality
- Add the bot to a group and test welcome messages
Consider adding unit tests for:
- Message processing logic
- Telegram API interactions
- Error handling scenarios
The bot is designed to run locally or on a server with Python 3.7+ support.
- Heroku: Easy deployment with free tier available
- AWS EC2: Scalable cloud hosting
- DigitalOcean: Simple VPS deployment
- Railway: Modern cloud platform
- Use environment variables for sensitive data
- Implement proper logging
- Set up monitoring and alerting
- Consider using a process manager (PM2, systemd)
- Implement rate limiting for API calls
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Follow PEP 8 guidelines
- Use meaningful variable names
- Add comments for complex logic
- Keep functions focused and small
- Telegram Bot API for messaging platform
- Python community for excellent libraries
- Contributors and testers
Last updated: October 2025