Documentation:
This repository contains the source code for a Telegram bot designed to implement subscription functionality. Whether you want to manage subscriptions, deliver timely updates, or engage with your audience, this bot, written in Python using the aiogram framework version 2 and an asynchronous SQLite3 wrapper called aiosqlite, has got you covered. 🤖📱
This Telegram bot already includes a fundamental subscription system, complete with subscription verification. You can review the code responsible for this functionality in the payment.py
handlers and the utils
module.
The payment verification process ensures that users have paid the required subscription amount in USDT TRC20. This is achieved by utilizing the USDT_TRC20_WALLET_ADDRESS
and SUBSCRIBE_AMOUNT_IN_USDT_TRC20
variables defined in the config.py
file.
To verify payments, you can refer to the code in utils/subscription_checker.py
. This code checks whether a user has made a payment of at least the specified amount in USDT TRC20 to the designated wallet address. Users who have paid are considered subscribed, while those who haven't paid or paid insufficiently are treated as non-subscribed.
.
├── .env-dist
├── README.md
├── requirements.txt
└── src
├── bot
│ ├── app.py
│ ├── data
│ ├── database
│ ├── filters
│ ├── handlers
│ ├── keyboards
│ ├── loader.py
│ ├── logs
│ ├── middlewares
│ ├── statesgroup.py
│ └── utils
└── db
└── database_schema.sql
Before running the bot, make sure you have Python 3.8+ installed and follow these steps:
-
Clone the repository to your computer:
git clone https://github.com/ProgerOffline/subscribe.git cd subscribe
-
Create a virtual environment (recommended but optional):
python -m venv venv
-
Activate the virtual environment:
source venv/bin/activate
-
Upgrade pip in environment:
pip3 install --upgrade pip
-
Install the dependencies listed in the
requirements.txt
file:pip install -r requirements.txt
Before running the bot, you need to configure the following parameters:
-
Create a bot on Telegram and obtain its token from BotFather.
-
Edit the
.env-dist
file, specifying the obtained token and other settings if necessary:BOT_TOKEN=123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
-
Rename the
.env-dist
file to.env
.
After configuring, you can start the bot with the following command:
cd src/bot/
python3 app.py
The bot will be active and ready to handle commands and user requests on Telegram. Of course, here's the complete text with the added information about the config file:
Of course, here's the complete text with the added information:
To configure specific aspects of your bot's behavior, you can utilize the config.py
file located in the src/bot/data/
directory. This file includes the following variables:
# USDT TRC20 wallet address used for transactions
USDT_TRC20_WALLET_ADDRESS = 'TF8aSMqpwtniPN77wS2EZTTcUKaaJhyorb'
# Amount in USDT TRC20 required for subscription
SUBSCRIBE_AMOUNT_IN_USDT_TRC20 = 5
# Number of days between each payment for subscription
NUMBER_DAYS_FROM_ONE_PAYMENT = 30
private_channels = {
'Channel 1': {
'id': -100123456789,
'invite_url': 'https://t.me/+ABCDEFGHIJKL'
},
}
You can utilize these variables in your code to tailor your Telegram bot's behavior in accordance with the specified values.
In the handlers
module located at src/bot/handlers/
, you have the flexibility to create your own *.py
files and import them into your bot by editing the __init__.py
file as follows:
# -*- coding: utf-8 -*-
from .start import *
from .payment import *
Within any of your handler files, you can implement filters to determine whether a user is subscribed or not. Here's an example:
# -*- coding: utf-8 -*-
from filters.user_not_subscribed import UserNotSubscribedFilter
from filters.user_subscribed import UserSubscribedFilter
# Start command for subscribed users
@dp.message_handler(UserSubscribedFilter(), commands=['start'], state="*")
...
# Same command, but for users who are not subscribed
@dp.message_handler(UserNotSubscribedFilter(), commands=['start'], state="*")
...
This allows you to handle messages differently based on whether a user is subscribed or not, providing greater flexibility in your bot's behavior.