Telegram Archive Bot creates Archives consisting of the received messages and attachments every 60 seconds.
Archives are Zip files stored in archive/
.
Before creating an archive, TAB puts the messages and attachments in the temporary directory data/
.
You need to register a Telegram Bot and get its access token before running TAB.
Steps to register a Telegram Bot and get its access token:
- Install a Telegram app on your mobile or desktop.
- Search
@botfather
and start a conversation. - Send
/newbot
. - Enter bot username and bot name
- BotFather will send a message including:
- Bot link: You can start a conversation with the bot by clicking the link.
- HTTP API Token (Access Token): Write down the token. It is necessary to run TAB.
mkdir -p ~/.config/telegram-archive-bot/
cp config.json.example config.json
Put your Telegram bot's access token into config.json
.
cp config.json ~/.config/telegram-archive-bot/config.json
Create the execution environment
virtualenv -p python3 venv
source venv/bin/activate
python3 -m pip install python-telegram-bot logzero
Run TAB
python3 telegram_archive_bot.py --token ~/.config/telegram-archive-bot/config.json [--debug]
or
python3 telegram_archive_bot.py --token <bot-access-token> [--debug]
$ docker-compose up -d
There will be a log file telegram.log
in the directory where telegram_archive_bot.py
is.
Now, you can send messages and files to TAB, and TAB will create Archives in archive/
every 60 seconds.
You can invite TAB to a group to collect and archive messages in the background.
It's necessary to adjust bot's configuration. You need to chat with botfather and disable the privacy mode
add Group Privacy
For demonstrating how to integrate Telegram Bot and Restful API together.
$ cd telegram_bot_backend
$ cp .env.example .env
# Edit .env to fill in desired environment variables
$ cd app
$ cp ../.env .env
$ poetry install
$ poetry run uvicorn main:app --reload --host 0.0.0.0 --port ${port}
# The server would be listening on localhost:{port} now
$ cd backend
$ cp .env.example .env
# Edit .env to fill in desired environment variables
$ docker-compose up -d
send this get request
https://api.telegram.org/bot${your api token}/setWebhook?url=${your deploy url}/hook
and then you need to get this result
{"ok":true,"result":true,"description":"Webhook was set"}