This project is a Telegram bot developed using Python (Telethon) that listens to messages from a public Telegram channel using a personal Telegram account. New events from the monitored channel are processed and saved into a database.
- Real-Time Message Listening: Monitors a public Telegram channel for new messages using a personal Telegram account.
- Database Integration: Saves all received messages and events directly into a database for persistent storage.
- Personalized Notifications: Redirect the mentioned telegram channel messages into your chat if each keyword is compliant.
pip install requirements.txt -r
user = os.getenv("db_user"),
password = os.getenv("db_password"),
host = os.getenv("db_host"),
port = os.getenv("db_port"),
dbname =os.getenv("db_dbname")CREATE TABLE IF NOT EXISTS users (
user_id BIGINT PRIMARY KEY,
user_name VARCHAR(255),
first_name VARCHAR(255),
last_name VARCHAR(255),
phone_number VARCHAR(50)
CREATE TABLE IF NOT EXISTS keywords (
id BIGINT PRIMARY KEY,
keyword VARCHAR(255),
user_id BIGINT REFERENCES users(user_id) ON DELETE CASCADE
);
CREATE TABLE IF NOT EXISTS messages (
id BIGINT PRIMARY KEY,
telegram_id BIGINT,
content TEXT,
status VARCHAR(50),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
updated_at TIMESTAMP,
deleted_at TIMESTAMP
);- or you can simply call the
creating_tablesfunction located in thedb.pyfile.
- you can get this data here.
desired_channel = os.getenv("desired_channel") # you can add your desired channel for listening
session_user = os.getenv("session_user")
session_bot = os.getenv("session_bot")
api_id = os.getenv("api_id")
api_hash = os.getenv("api_hash")
bot_token = os.getenv("bot_token")
- desired_channel: the channel you want to monitor.
- session_user: A session of a telegram account that is a member of the desired Telegram channel.
- session_bot: the session of your telegram bot.
- api_id and api_hash : are available in
my.telegram.org. - bot_token: you can get it from @BotFather

