Telebot is a simple project which forwards all Telegram messages sent to a bot into a chat (i.e. master chat) and vice-versa.
create table agents (
chat_id int not null primary key,
is_group boolean not null default false,
name varchar(120) not null
);
create table updates (
update_id int not null primary key,
payload varchar(1200) not null
);
create table messages (
chat_id int not null,
message_id int not null,
reply_chat_id int,
reply_message_id int,
timestamp timestamp not null,
primary key (chat_id, message_id)
);
create table rate_limits (
chat_id int not null primary key,
max_messages int not null default 0,
timespan int not null default 0
);
create table forwarded_messages (
from_chat_id int not null,
from_message_id int not null,
to_chat_id int not null,
to_message_id int not null,
primary key (to_chat_id, to_message_id)
);
Grant SELECT, INSERT, UPDATE, DELETE privileges to the tables
Go to bot father and create a new bot with /newbot command
Disable group privacy with /setprivacy command
Follow the guide: https://packaging.python.org/en/latest/guides/installing-using-pip-and-virtual-environments/
To activate virtual environment:
Windows .\env\Scripts\activate
Unix ./env/bin/python
Run the following command:
pip install python-dotenv python-telegram-bot
For webhook strategy only (not needed for polling strategy):
pip install flask
For MySql:
pip install mysql-connector-python
For Postgresql:
pip install psycopg2
- Copy .env_sample to .env and fill in the variables
- Run the application using either of the commands below:
py polling.pypy webhook.py
- Create Heroku account and create a new project
- Set the env variables in the project settings
- Install Heroku CLI from their website:
https://devcenter.heroku.com/articles/heroku-command-line - Login via CLI (remember to add executable folder to PATH):
heroku login - Add the Heroku remote:
heroku git:remote -a <project_name> - Install the Heroku dependency:
pip install gunicorn - Create a seperate branch for Heroku
- Create
Procfilefile with the following as its content:web: gunicorn webhook:app - Define libraries used for Heroku:
pip freeze > requirements.txt - Commit the two created files
- Push to Heroku:
git push heroku <branch>:master
Type /setagent to the chat bot and enter the agent password when prompted