A feature-rich Telegram bot built using the Telegraf framework for Node.js.
- 🤖 Welcome message for new users
- 📋 Help command with available options
- 🔄 Echo functionality
- 🕐 Current time display
- 🎲 Random number generator
- 💬 Smart text message responses
- 📸 Media file recognition (photos, stickers)
- ⚡ Error handling and graceful shutdown
- 🧩 Random coding problems with examples and tags
- 📊 Time complexity cheatsheet
- 🏗️ Data structures quick reference
- 🔄 Algorithm patterns and techniques
- 🏁 Contest information and platforms
- 📝 Code templates for C++, Python, and Java
- 🧮 Math formulas for competitive programming
- Node.js (version 14 or higher)
- npm or yarn package manager
- A Telegram account
- Open Telegram and search for
@BotFather - Start a chat with BotFather and send
/newbot - Follow the instructions to create your bot:
- Choose a name for your bot
- Choose a username (must end with 'bot')
- BotFather will provide you with a bot token - save this token!
# Clone or download this project
# Navigate to the project directory
cd creating-own-telegram-bot
# Install dependencies
npm install- Open the
.envfile in the project root - Replace
your_bot_token_herewith your actual bot token from BotFather:
BOT_TOKEN=replace_with_your_bot_token# Start the bot
npm start
# Or for development
npm run devYou should see:
🚀 Starting Telegram bot...
✅ Bot is running successfully!
Press Ctrl+C to stop the bot
| Command | Description |
|---|---|
/start |
Welcome message and bot introduction |
/help |
Display all available commands |
/about |
Information about the bot |
/echo [message] |
Bot will repeat your message |
/time |
Get current date and time |
/random |
Generate a random number (1-100) |
| Command | Description |
|---|---|
/problem |
Get a random coding problem to solve |
/complexity |
Time complexity cheatsheet |
/ds |
Data structures quick reference |
/algorithms |
Algorithm patterns and techniques |
/contest |
Contest information and platforms |
/template |
Code templates for C++, Python, Java |
/math |
Math formulas for competitive programming |
- Text Messages: The bot responds intelligently to common greetings, farewells, and thanks
- Media Files: Recognizes and responds to photos and stickers
- Error Handling: Gracefully handles errors and provides user feedback
creating-own-telegram-bot/
├── index.js # Main bot implementation
├── package.json # Project configuration
├── .env # Environment variables (bot token)
├── .gitignore # Git ignore file
└── README.md # This file
You can easily customize the bot by modifying index.js:
- Add new commands using
bot.command('commandname', callback) - Handle different message types with
bot.on('message_type', callback) - Modify responses and add new features
-
Bot not responding
- Check if the bot token is correct in
.env - Ensure the bot is running (
npm start) - Verify internet connection
- Check if the bot token is correct in
-
"Unauthorized" error
- Double-check your bot token
- Make sure there are no extra spaces in the
.envfile
-
Commands not working
- Ensure commands start with
/ - Check console for error messages
- Ensure commands start with
- Check the Telegraf documentation
- Review Telegram Bot API
- Never commit your
.envfile to version control - Keep your bot token secret
- The
.gitignorefile is configured to exclude sensitive files
ISC License - feel free to modify and use this bot for your projects!
Happy botting! 🤖