Beginner-Friendly Telegram Bot Boilerplate: Easy Setup and Modular Design
Beginner-Friendly Telegram Bot Boilerplate: Easy Setup and Modular Design

Beginner-Friendly Telegram Bot Boilerplate: Easy Setup and Modular Design

Discover a simple and modular Telegram bot boilerplate built with Pyrogram. Perfect for beginners, this guide walks you through the setup, structure, and features to get your bot up and running in minutes.

By Avisek Ray |
4 min read | 780 views
Beginner-Friendly Telegram Bot Boilerplate: Easy Setup and Modular Design

Building Telegram Bots Made Simple: A Beginner-Friendly Boilerplate

If you've ever wanted to create a Telegram bot but felt overwhelmed by the complexity, I've got you covered! Let me introduce you to a simple, beginner-friendly boilerplate that makes starting your Telegram bot project a breeze.

Hereโ€™s everything you need to know to get started with this boilerplate, step by step.


๐Ÿ› ๏ธ What Is This Boilerplate?

This boilerplate is a ready-to-use framework for creating Telegram bots using Pyrogram, a powerful Python library for interacting with the Telegram Bot API.

Itโ€™s designed to:

  • Save time by setting up a basic structure for your project.
  • Keep your code clean and organized using a modular approach.
  • Help you focus on building cool features instead of worrying about setup.

You can check it out here: GitHub Repository


๐Ÿš€ Why Use This Boilerplate?

  1. Simplicity: You donโ€™t need to start from scratchโ€”just plug in your details and go.
  2. Modular Design: Commands and features are organized into separate files, making it easy to add or modify functionality.
  3. Beginner-Friendly: Even if youโ€™re new to Python or Pyrogram, the structure makes it easy to understand.
  4. Quick Setup: With just a few commands, your bot will be up and running in minutes.

๐Ÿ“‚ Project Structure

Hereโ€™s a quick look at how everything is organized:

tgbot-boilerplate/ 
โ”œโ”€โ”€ plugins/ # All your bot commands and features โ”‚ 
โ”œโ”€โ”€ callback.py # Example for handling button clicks (callbacks) 
โ”‚ โ””โ”€โ”€ commands.py # Example for basic commands like /start 
โ”œโ”€โ”€ bot.py # Main file that runs the bot 
โ”œโ”€โ”€ db.py # Placeholder for database connection (if needed) 
โ”œโ”€โ”€ vars.py # Handles environment variables like API keys 
โ”œโ”€โ”€ requirements.txt # Python dependencies 
โ””โ”€โ”€ .env # Your API keys and bot credentials (ignored by Git)	

๐Ÿ“ Step-by-Step Guide to Get Started

1. Clone the Repository

First, grab the boilerplate from GitHub and navigate into the project directory:

git clone https://github.com/biisal/tgbot-boilerplate.git  
cd tgbot-boilerplate  

2. Install Dependencies

Make sure you have Python 3.9 or higher installed. Install the required Python libraries using:

pip install -r requirements.txt  

3. Set Up Your Bot Credentials

  • Go to Telegram BotFather and create a bot.
  • Note down the API ID, API Hash, and Bot Token provided by BotFather.

Next, create a .env file in the project root and add the following:

API_ID=your_api_id  
API_HASH=your_api_hash  
BOT_TOKEN=your_bot_token  
ADMIN=your_telegram_user_id  

4. Run the Bot

Now, itโ€™s time to launch your bot! Just run:

python3 bot.py  

๐ŸŽ‰ Thatโ€™s it! Your bot is now live and ready to respond.

 


โœจ Cool Features in the Boilerplate

Example Command: /start

When users type /start, they get a friendly message along with an inline keyboard:

@Client.on_message(filters.command("start") & filters.incoming)  
async def start(client: Client, message: Message):  
    await message.reply_text(  
        f"**Hello {message.from_user.first_name}!**\nThis boilerplate is ready to go.",  
        reply_markup=InlineKeyboardMarkup(  
            [  
                [  
                    InlineKeyboardButton("Help", url="https://t.me/devdoptpy"),  
                    InlineKeyboardButton("Callback ping", callback_data=f"ping#{message.from_user.id}")  
                ]  
            ]  
        )  
    )  

 

Example Callback

The boilerplate also includes an example of handling button callbacks using the callback.py file.

 

๐ŸŒŸ Why This Boilerplate Is Perfect for Beginners

  • No Messy Setup: The project is already organizedโ€”you can just dive into writing commands.
  • Customizable: Add features like databases, APIs, or advanced commands without breaking a sweat.
  • Pyrogram Power: Pyrogram simplifies interactions with Telegram, giving you more time to focus on your botโ€™s logic.

๐Ÿ’ก Tips for Expanding Your Bot

  1. Add New Commands: Create new Python files in the plugins/ folder for different commands.
  2. Integrate Databases: Use db.py to connect your bot to a database like MongoDB or PostgreSQL.
  3. Explore Pyrogram Docs: Learn about the full range of features Pyrogram offers here.

๐Ÿค Contribute and Customize

This boilerplate is open-source, and contributions are welcome! If you have ideas or improvements, feel free to fork the repo and create a pull request.


๐Ÿš€ Ready to Build Your Own Telegram Bot?

Start your journey with this boilerplate:
๐Ÿ‘‰ GitHub Repository

Letโ€™s build something awesome together! ๐ŸŽ‰


About the Author

Avisek Ray

I am a skilled full-stack developer with expertise in Python (Django, FastAPI) and JavaScript (Next.js, React). With over a year of experience, Iโ€™ve delivered scalable web applications, including a news website and an AI-powered project planner. I focus on creating secure, high-performance solutions while continually expanding my skills in SQLAlchemy, Docker, and advanced Python practices. Driven by curiosity and a passion for problem-solving, I aim to build impactful, innovative applications

Related Posts

20 Essential Linux Commands You Probably Don't Know (But Should)

20 Essential Linux Commands You Probably Don't Know (But Should)

The Linux command line is a powerful tool, but many users only scratch the surface. This guide introduces 20 underrated commands that can simplify complex tasks, from file management to system monitoring. Perfect for beginners and experienced users alike

Read this post
Stop Website Crashes:  A Simple Guide to Token Bucket Rate Limiting for Developers

Stop Website Crashes: A Simple Guide to Token Bucket Rate Limiting for Developers

Is your website slowing down or crashing under heavy traffic? Learn how the token bucket algorithm can be your secret weapon! This easy-to-understand guide breaks down rate limiting with real-world examples, showing developers how to protect their sites and APIs from overload โ€“ no complex jargon needed!

Read this post
DeepSeek: Genius or Cheater? The Debate on AI Transparency & Data Practices

DeepSeek: Genius or Cheater? The Debate on AI Transparency & Data Practices

Is DeepSeek a cheater or a genius? Should OpenAI be held accountable for its data practices? Dive into this post as we break down the debate on AI transparency, data ethics, and the future of AI technology. Share your thoughts in the comments! ๐Ÿ˜Š

Read this post