{"id":13826176,"url":"https://github.com/sanjit-sinha/TelegramBot-Boilerplate","last_synced_at":"2025-07-09T00:32:39.343Z","repository":{"id":62841419,"uuid":"548499524","full_name":"sanjit-sinha/TelegramBot-Boilerplate","owner":"sanjit-sinha","description":"Create Telegram Bot with this friendly python boilerplate using pyrogram framework.","archived":false,"fork":false,"pushed_at":"2023-10-19T21:35:30.000Z","size":734,"stargazers_count":108,"open_issues_count":4,"forks_count":44,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-08-05T09:14:55.794Z","etag":null,"topics":["beginner","boilerplate","boilerplate-template","mongodb","mtproto","pyrogram","pyrogram-bot","python","rate-limiting","telegram","telegram-bot","telegram-bot-api","telegram-bot-boilerplate","telegram-bot-example","telegrambot"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sanjit-sinha.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2022-10-09T17:42:38.000Z","updated_at":"2024-07-23T20:13:55.000Z","dependencies_parsed_at":"2024-01-09T08:14:29.867Z","dependency_job_id":null,"html_url":"https://github.com/sanjit-sinha/TelegramBot-Boilerplate","commit_stats":null,"previous_names":["sanjit-sinha/telegram-bot-boilerplate"],"tags_count":2,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanjit-sinha%2FTelegramBot-Boilerplate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanjit-sinha%2FTelegramBot-Boilerplate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanjit-sinha%2FTelegramBot-Boilerplate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sanjit-sinha%2FTelegramBot-Boilerplate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sanjit-sinha","download_url":"https://codeload.github.com/sanjit-sinha/TelegramBot-Boilerplate/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225476384,"owners_count":17480215,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["beginner","boilerplate","boilerplate-template","mongodb","mtproto","pyrogram","pyrogram-bot","python","rate-limiting","telegram","telegram-bot","telegram-bot-api","telegram-bot-boilerplate","telegram-bot-example","telegrambot"],"created_at":"2024-08-04T09:01:33.362Z","updated_at":"2024-11-20T05:30:24.980Z","avatar_url":"https://github.com/sanjit-sinha.png","language":"Python","funding_links":[],"categories":["Python"],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\u003ch1\u003eTelegram Bot Boilerplate\u003cbr\u003e[ Pyrogam version ]\u003c/h1\u003e\n\u003cimg src=\"https://telegra.ph/file/4621c1419e443ebb01b2b.jpg\" align=\"center\" style=\"width: 100%\" /\u003e\n\u003c/div\u003e\n\n------\n\n\u003cdiv align=\"center\"\u003e\n\u003ch1\u003e\u003cb\u003eAbout this repository?\u003c/b\u003e\u003c/h1\u003e\n\u003c/div\u003e\n\nThis repository serves as a template for creating a new Telegram bot using Python. It aims to save time for those starting new projects from scratch, and provides a helpful resource for those who are new to the Telegram API and want to learn and understand basic file structure. The repository includes a Pluggable boilerplate that is easy to use and customize for your own project. You can use the repository as a template or fork it to begin a new project. The following are some of the features of this repository:\n\n- Fully asynchronous code: The code in this repository makes use of libraries such as httpx, aiofiles, pyrogram and mongodb motor to enable fully asynchronous execution. This means that the code can perform multiple tasks concurrently, improving the performance and efficiency of the bot.\n\n- Pre-built features: This repository contains a range of pre-built plugins, functions, and decorators to assist you in getting started. Some examples include commands for broadcasting, pasting, checking spam counter, evaluating/executing code, checking database and server stats, and more..\n\n- Pluggable plugins: The code in this repository is designed to be modular and extensible, allowing you to easily add new functionality to the bot by creating and integrating plugins.\n\n- Ratelimiting: To prevent FloodWait errors, the code in this repository includes ratelimiting functionality that uses the leaky bucket algorithm and the pyrate_limiter library to limit the number of requests that can be made by users in a given time period.\n\n- MongoDB support: The code in this repository includes support for storing data in a MongoDB database, allowing you to easily keep track of users and channels associated with the bot.\"\n\n\n_____\n\n\u003cdiv align=\"center\"\u003e\n\u003ch1\u003e\u003cb\u003eMore information and links\u003c/b\u003e\u003c/h1\u003e\n\u003c/div\u003e\n\u003cimg src=\"https://telegra.ph/file/db914ce03059dca6e2e02.gif\" align=\"right\" width=\"150\"\u003e\n\n\u003cp\u003e\n\u003cb\u003eThis bot uses the Pyrogram framework, which is based on the MTProto protocol, to communicate with the Telegram API. .\u003c/b\u003e\n\u003cbr\u003e\n\u003cbr\u003e\nPyrogram is a modern, elegant , much faster and asynchronous MTProto API\u003ca href=\"https://docs.pyrogram.org/topics/mtproto-vs-botapi\"\u003e (MTproto vs botapi)\u003c/a\u003e framework.\n\u003cbr\u003e\n\u003cbr\u003e\n\u003ca href=\"https://docs.pyrogram.org/\"\u003e\u003cstrong\u003ePyrogram Documentation\u003c/strong\u003e\u003c/a\u003e | \u003ca href=\"https://t.me/pyrogramchat\"\u003e\u003cstrong\u003ePyrogram Support Group\u003c/strong\u003e\u003c/a\u003e | \u003ca href=\"https://core.telegram.org/api\"\u003e\u003cstrong\u003eTelegram API Documentation\u003c/strong\u003e\u003c/a\u003e\n\u003cbr\u003e\n\u003cbr\u003e Some other libraries and Framework: \u003ca href=\"https://github.com/python-telegram-bot/python-telegram-bot\"\u003e\u003cstrong\u003ePython Telegram Bot\u003c/strong\u003e\u003c/a\u003e | \u003ca href=\"https://github.com/LonamiWebs/Telethon\"\u003e\u003cstrong\u003eTelethon\u003c/strong\u003e\u003c/a\u003e | \u003ca href=\"https://core.telegram.org/bots/samples\"\u003e\u003cstrong\u003eList of libraries and frameworks using various type of languages.\u003c/strong\u003e\u003c/a\u003e\n\u003cbr\u003e\n\u003cbr\u003e\nJoin \u003ca href=\"https://t.me/ani_support\"\u003e\u003cstrong\u003eDiscussion Group\u003c/strong\u003e\u003ca\u003e if you have any suggestion or bugs to discuss.\n\u003cp\u003e\n  \n---------\n\n\u003cdiv align=\"center\"\u003e \n\u003ch1\u003e\u003cb\u003eScreenshots\u003c/b\u003e\u003c/h1\u003e\n\u003c/div\u003e\n\n| ![](https://te.legra.ph/file/565b3f47e0886fc93e75c.jpg) | ![](https://te.legra.ph/file/e6e16e6f3a1d07524a23b.jpg)|\n|--------------------------------------------------------|--------------------------------------------------------|\n| ![](https://te.legra.ph/file/29f7e8163406f63bfb4f8.jpg) | ![](https://te.legra.ph/file/c26991c1eaae34920216c.jpg) |\n\n_______\n\n\u003cdiv align=\"center\"\u003e \n\u003ch1\u003e\u003cb\u003eBot Deployment and Usage\u003c/b\u003e\u003c/h1\u003e\n\u003cp\u003e\u003cb\u003e( VPS or Local hosting )\u003c/b\u003e\u003c/p\u003e\n\u003c/div\u003e\n\n( checkout no database branch if you don't want to use database in your bot. )\n  \nUpgrading, Updating and setting up required packages in Server.\n\n```\nsudo apt-get update \u0026\u0026 sudo apt-get upgrade -y\nsudo apt install python3-pip -y\nsudo pip3 install -U pip\n```\n\nCloning Github Repository and Starting the Bot in Server.\n \n```\ngit clone https://github.com/sanjit-sinha/Telegram-Bot-Boilerplate \u0026\u0026 cd Telegram-Bot-Boilerplate \npip3 install -U -r requirements.txt\n```\n\n\nNow edit the config vars by typing `nano config.env` and save it by pressing \u003ckbd\u003ectrl\u003c/kbd\u003e+\u003ckbd\u003eo\u003c/kbd\u003e and \u003ckbd\u003ectrl\u003c/kbd\u003e+\u003ckbd\u003ex\u003c/kbd\u003e.\n\u003cbr\u003e\n\u003cbr\u003e\n\u003cdetails open=\"open\"\u003e\n\u003csummary\u003e\u003cstrong\u003e Setting up config variables files (config.env) \u003c/strong\u003e\u003c/summary\u003e\n\u003cbr\u003e\n\u003cul\u003e\n \u003cli\u003eGet your API_ID and API_HASH from \u003ca href=\"https://my.telegram.org/auth\"\u003eTelegram.org\u003c/a\u003e, BOT_TOKEN from \u003ca href=\"https://t.me/botfather\"\u003eBotfather.\u003c/a\u003e You can get user ids for sudo users and owner from \u003ca href=\"https://t.me/MissRose_bot\"\u003eMissRoseBot\u003c/a\u003e by just using /info command and copying ID value from result. \u003c/li\u003e\n  \u003cli\u003eTo get guide for getting MONGO_URI click \u003ca href=\"https://graph.org/How-to-create-mongodb-URI-01-01\"\u003ehere\u003c/a\u003e\u003c/li\u003e\n  \u003c/ul\u003e\n\u003c/details\u003e\n  \nnow you can start the bot by simply typing `bash start` or `python3 -m TelegramBot`\n\n\u003cimg src=\"https://telegra.ph/file/03a650af46de1bcc27756.png\" align=\"right\" width=\"150\"\u003e\n\nThe bot will stop working once you logout from the server. You can run the bot 24*7 in the server by using screen or tmux.\n```\nsudo apt install tmux -y\ntmux \u0026\u0026 bash start\n```\n  \nNow the bot will run 24*7 even if you logout from the server. [Click here to know about tmux and screen advance commands.](https://grizzled-cobalt-5da.notion.site/Terminal-Multiplexers-to-run-your-command-24-7-3b2f3fd15922411dbb9a46986bd0e116)\n\n\n\u003cdetails open=\"open\"\u003e\n\u003csummary\u003e\u003cstrong\u003eBasic Bot Commands and it's usage\u003c/strong\u003e\u003c/summary\u003e\n\u003cul\u003e\n\u003cbr\u003e\n\t\u003cli\u003e\n\t\u003ci\u003e\u003cb\u003eUsers Commands\u003c/b\u003e\u003c/i\u003e\u003cbr\u003e\u003cbr\u003e\n\t/start - To get the start message.\u003cbr\u003e\n\t/help - Alias command for start. \u003cbr\u003e\n\t/ping - Ping the telegram api server\u003cbr\u003e\n\t/paste - Paste the text in katb.in\n\t\u003c/li\u003e\n\u003cbr\u003e\n\t\u003cli\u003e\n\t\u003ci\u003e\u003cb\u003eSudo User Commands \u003c/b\u003e\u003c/i\u003e\u003cbr\u003e\u003cbr\u003e\n\t/speedtest - Check the internet speed of bot server.\u003cbr\u003e\n\t/serverstats - Get the stats of bot server.\u003cbr\u003e\n\t/stats - Alias command for serverstats.\u003cbr\u003e\n\t/dbstats - Get the stats of bot database. \n\t\u003c/li\u003e\n\u003cbr\u003e\n\t\u003cli\u003e\n\t\u003ci\u003e\u003cb\u003eDeveloper Commands \u003c/b\u003e\u003c/i\u003e\u003cbr\u003e\u003cbr\u003e \n\t/shell - To run the terminal commands via bot.\u003cbr\u003e\n\t/py - To run the python commands via bot. \u003cbr\u003e\n\t/update - To update the bot to latest commit from repository. \u003cbr\u003e \n\t/restart - Restart the bot. \u003cbr\u003e\n\t/log - To get the log file of bot. \u003cbr\u003e\n\t/broadcast - broadcast the message to bot users and chat. \n\u003c/ul\u003e\n\u003c/details\u003e\n\u003cbr\u003e \n\t\n\n-------\n  \n\u003cdiv align=\"center\"\u003e\n\u003ch1\u003e\u003cimg src=\"https://telegra.ph/file/c182d98c9d2bc0295bc86.png\" width=\"45\"\u003e\u003cb\u003e  \nDirectoryLayout \u003cb\u003e\u003c/h1\u003e\n\u003c/div\u003e\n\n\n```\n\n├── Dockerfile                          \n├── LICENSE\n├── README.md\n├── config.env                         ( For storing all the  environment variables)\n├── requirements.txt                   ( For keeping all the library name wich project is using)\n├── TelegramBot\n│   │\n│   ├── __init__.py                   ( Initializing the bot from here.)\n│   ├── __main__.py                   ( Starting the bot from here.)\n│   ├── config.py                     ( Importing and storing all envireonment variables from config.env)\n│   ├── logging.py                    ( Help in logging and get log file)\n│   │\n│   ├── assets                        ( An assets folder to keep all type of assets like thumbnail, font, constants, etc.)\n│   │   └── __init__.py\n│   │   ├── font.ttf\n│   │   └── template.png\n│   │\n│   ├── database                      (Sperate folder to manage database related stuff for bigger projects.)\n│   │   ├── __init__.py\n│   │   ├── database.py              (contain functions related to handle database operations all over the bor)\n│   │   └── MongoDb.py               (Contain a MongoDB class to handle CRUD operations on MongoDB collection )\n│   │  \n│   ├── helpers                       ( Contain all the file wich is imported and  used all over the code. It act as backbone of code.)\n│   │   ├── __init__.py\n│   │   ├── filters.py \n│   │   ├── decorators.py            ( Contain all the python decorators)\n│   │   ├── ratelimiter.py           (Contain RateLimiter class that handle ratelimiting part of the bot.)\n│   │   └── functions.py             ( Contain all the functions wich is used all over the code. )\n│   │\n│   ├── plugins                       ( plugins folder contain all the plugins commands via wich user interact)  \n│   │   ├── __init__.py \n│   │   ├── developer\n│   │   │   ├── __init__.py\n│   │   │   ├── terminal.py\n│   │   │   └── updater.py\n│   │   │\n│   │   ├── sudo\n│   │   │   ├── __init__.py\n│   │   │   ├── speedtest.py\n│   │   │   ├── dbstats.py\n│   │   │   └── serverstats.py\n│   │   │   \n│   │   └── users\n│   │       ├── __init__.py\n│   │       ├── alive.py\n│   │       └── start.py\n│   │      \n│   └── version.py         \n└── start                             ( A start file containing bash script to start the bot using bash start)\n\n```    \n  \n\u003cdetails\u003e\n   \u003csummary\u003eSome important articles and Links wich will help you to understand the code better.\u003c/summary\u003e\n   \u003cul\u003e\n    \u003cbr\u003e\n    \u003cli\u003e \u003ca href=\"https://stackoverflow.com/questions/448271/what-is-init-py-for#:~:text=The%20__init__.py%20file%20makes%20Python,directories%20containing%20it%20as%20modules\"\u003eWhat is __init__.py\u003c/a\u003e│ \u003ca href=\"https://youtu.be/cONc0NcKE7s\"\u003e( YouTube video )\u003c/a\u003c/li\u003e         \n    \u003cli\u003e \u003ca href=\"https://www.geeksforgeeks.org/what-does-the-if-__name__-__main__-do/\"\u003eWhat is __name__ = \"__main__\" in python?\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"https://realpython.com/python-logging/\n\"\u003eAbout python logging\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"https://www.educative.io/blog/python-concurrency-making-sense-of-asyncio\"\u003ePython concurrecny and asyncio\u003ca\u003e\u003c/li\u003e\n    \u003cli\u003e\u003ca href=\"https://developer.vonage.com/blog/21/10/01/python-environment-variables-a-primer\"\u003eWhat is Environment Variables (.env files) ?\u003ca\u003e\u003c/li\u003e  \n    \u003cli\u003e\u003ca href=\"https://www.programiz.com/python-programming/decorator\n\"\u003eAbout Python decorator\u003c/a\u003e\u003c/li\u003e\n    \u003cli\u003e \u003ca href=\"https://stackoverflow.com/questions/4042905/what-is-main-py\"\u003eWhat is __main__.py\u003c/a\u003e \u003c/li\u003e \n       \u003cli\u003e\u003ca href=\"https://learnpython.com/blog/python-requirements-file\"\u003eWhat is requirements.txt and why should we use it?\u003c/a\u003e\u003c/li\u003e\n     \u003cli\u003e \u003ca href=\"https://geekflare.com/dockerfile-tutorial/\"\u003eWhat iS Dockerfile?\u003c/a\u003e \u003c/li\u003e\n     \u003cli\u003e \u003ca href=\"https://developerexperience.io/practices/license-in-repository\"\u003ewhat is License in a repository?\u003c/a\u003e │\u003ca href=\"https://choosealicense.com/\"\u003echoosealicense.\u003c/a\u003e\u003c/li\u003e \n     \u003cli\u003e\u003ca href=\"https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-readmes\"\u003eWhat is README.md?\u003c/a\u003e │ \u003ca href=\"https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax\"\u003e( writing format for Github readme ) \u003c/a\u003e│ \u003ca href=\"https://readme.so \"\u003e( website wich will help you in writing readme ) \u003c/a\u003e│website to get png images wich  can be used in making readme:- \u003ca href=\"https://shields.io/\"\u003eshields.io│\u003c/a\u003e \u003ca href=\"https://www.flaticon.com/\"\u003eflaticon.com\u003c/a\u003e\u003c/li\u003e\n     \n   \u003c/ul\u003e\n\u003c/details\u003e\n\n\n-------\n  \n\u003cdiv align=\"center\"\u003e\n\u003ch1\u003e\u003cb\u003eBasic structure for building your own plugin.\u003c/b\u003e\u003c/h1\u003e\n\u003c/div\u003e\n\n\n```py\nfrom TelegramBot.helpers.decorators import ratelimiter\nfrom pyrogram import Client, filters\nfrom pyrogram.types import Message\n\n\n@Client.on_message(filters.command([\"hello\", \"hi\"]))\n@ratelimiter\nasync def hello(client: Client, message: Message):\n    \"\"\"\n    simple plugin to demonstrate in readme.\n    \"\"\"   \t\n    return await message.reply_text(\"world\")\t    \n```\n\t    \n_____\n  \n\u003cdiv align=\"center\"\u003e\n\u003ch1\u003e\u003cb\u003eCredits and Contibution\u003c/b\u003e\u003c/h1\u003e\n\u003c/div\u003e\n  \n\u003cimg src=\"https://telegra.ph/file/b26313d73e4d05de84a85.png\" align=\"right\" width=\"150\"\u003e\n\u003cp\u003e\nCodes and structure of this bot is heavily inspired by open source projects like \u003ca href=\"https://github.com/TeamYukki/YukkiMusicBot\"\u003e\u003cstrong\u003eYukkiMusicbot\u003c/strong\u003e\u003c/a\u003e | \u003ca href=\"https://github.com/UsergeTeam/Userge\"\u003e\u003cstrong\u003eUserge\u003c/strong\u003e\u003c/a\u003e | \u003ca href=\"https://github.com/EverythingSuckz/TG-FileStreamBot\"\u003e\u003cstrong\u003eTG-FileStreamBot etc.\u003c/strong\u003e\u003c/a\u003e.\n\u003cbr\u003e\n\u003cbr\u003e\n Special Thanks to \u003cbr\u003e\n• \u003ca href=\"https://github.com/delivrance\"\u003e\u003cstrong\u003eDan\u003c/strong\u003e\u003c/a\u003e for creating \u003ca href=\"https://github.com/pyrogram/pyrogram\"\u003e\u003cstrong\u003ePyrogram.\u003c/strong\u003e\u003c/a\u003e\u003cbr\u003e\n• \u003ca href=\"https://github.com/starry69\"\u003e Starry\u003c/a\u003e for guiding and acutebot repository. \u003cbr\u003e\n• \u003ca href=\"https://github.com/annihilatorrrr\"\u003eAnnihilator\u003c/a\u003e for helping me out with pyrogram stuff.\n\n\u003cbr\u003e\n\u003cbr\u003e\nAny type of suggestions, pointing out bug or contribution is highly appreciated. :)\n\u003c/p\u003e\n \n  \n-------\n  \n\u003cdiv align=\"center\"\u003e\n\u003ch1\u003e\u003cb\u003eCopyright and License\u003c/b\u003e\u003c/h1\u003e\n\u003c/div\u003e\n\u003cbr\u003e\n\u003cimg src=\"https://telegra.ph/file/b5850b957f081cfe5f0a6.png\" align=\"right\" width=\"110\"\u003e\n  \n\n* copyright (C) 2023 by [Sanjit sinha](https://github.com/sanjit-sinha)\n* Licensed under the terms of the [The MIT License](https://github.com/sanjit-sinha/Telegram-Bot-Boilerplate/blob/main/LICENSE)\n\n\u003cdiv align=\"center\"\u003e\n\u003cimg src=\"https://img.shields.io/badge/License-MIT-green.svg\" align=\"center\"\u003e\n\u003c/div\u003e\n\n-------\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsanjit-sinha%2FTelegramBot-Boilerplate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsanjit-sinha%2FTelegramBot-Boilerplate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsanjit-sinha%2FTelegramBot-Boilerplate/lists"}