Status: Archived (2026)
- Reason: this template is built on Pyrogram, which is no longer maintained (upstream archived in December 2024), and its pinned dependencies no longer install on current Python versions.
- Created: 2024
- Related: it was used once as the base of simulasicpns; CPNS simulation work now continues in simulasi-cpns-telegram. For new Python bots, consider a maintained library such as python-telegram-bot or aiogram.
The code is kept for reference only. Issues and pull requests are not monitored.
Welcome to the Telegram Bot project! This bot is built using the Pyrogram library and includes basic commands like /start and /help. It is designed to be easily extendable and comes with robust logging for easy monitoring and debugging.
- 🚀 Start Command: Responds to the
/startcommand. - 📖 Help Command: Responds to the
/helpcommand. - 🛠️ Modular Event Handling: Easily add new commands by creating new modules in the
eventsdirectory. - 📋 Custom Logging: Logs bot activities and errors for easier debugging and monitoring.
-
Clone the repository:
https://github.com/erzawansyah/pyrogram_telebot.git cd pyrogram_telebot -
Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables:
- Create a
.envfile in the root directory of your project. - Copy the contents of
.env.exampleto.envand replaceAPI_ID,API_HASH, andBOT_TOKENwith your actual values.
TELEGRAM_APP_API_ID=API_ID # Replace API_ID with your own API_ID. You can get it from https://my.telegram.org TELEGRAM_APP_API_HASH=API_HASH # Replace API_HASH with your own API_HASH. You can get it from https://my.telegram.org TELEGRAM_BOT_TOKEN=BOT_TOKEN # Replace BOT_TOKEN with your own BOT_TOKEN. You can get it from https://t.me/botfather
- Create a
-
Run the bot:
python main.py
-
Interacting with the bot:
- Send
/startto the bot to receive a welcome message. - Send
/helpto get help information.
- Send
├── .env.example
├── main.py
├── requirements.txt
├── settings
│ ├── bot.py
│ ├── config.py
│ ├── event_handler.py
│ ├── logger.py
├── events
│ ├── help.py
│ └── start.py
├── .env.example**: Example environment variables file.
├── main.py**: Entry point of the bot.
├── requirements.txt**: List of dependencies.
├── settings/**: Contains configuration, bot initialization, event handling, and logging logic.
├── events/**: Contains command handlers for the bot.
To add a new command to the bot:
-
Create a new Python file in the
eventsdirectory:# events/new_command.py from pyrogram import Client, filters def handler(app: Client): @app.on_message(filters.command("newcommand")) async def _(client, message): await message.reply_text("This is a response to the new command.")
-
Register the new command in
main.py:# main.py handler.register( EventHandlerType( filename="new_command", description="New command", ) )
The bot uses a custom logger for logging events. Logs include informational messages and error reports, which help in monitoring the bot's performance and debugging issues. Here’s an example of how logging is implemented in this bot:
from settings.logger import BotLogger
# Initialize the logger
logger = BotLogger("app")
# Log information when the bot starts
logger.info("Starting the bot")
# Log an error if there is an issue
try:
app.run()
except Exception as e:
logger.error(f"Error occurred: {e}")For more detailed information, please refer to the 📖 API Documentation
If you wish to contribute to this project, feel free to fork the repository and submit a pull request. Ensure that your code adheres to the existing coding standards and is well-documented.
Follow us on:
This bot can be hosted on various platforms. We recommend Hostinger for reliable and affordable hosting. Use our referral link to get a discount and support our project!
This README file was generated with the assistance of GitHub README on ChatGPT by Sourceduty. While efforts have been made to ensure the accuracy and completeness of the information provided, please review and verify all details to ensure they meet your project's requirements.
Made with ❤️ by @erzawansyah