telegram_channel_backup. How it works
Roadmap
- How to use
- How it works
Action workflow
- action is triggered on schedule at 23:30 UTC every day
- installs
python-telegram-bot
andPyGithub
- makes
_posts
folder for posts - run
backup_telegram_channel.py
with usage ofBOT_TOKEN
- run
upload_to_github.py
with usage ofAUTH_TOKEN
backup_telegram_channel.py
- gets channel updates for last 24 hours and saves as dictionary of the newly created or the last version of updated posts, uses python-telegram-bot library
python-telegram-bot
is a wrapper of the Telegram Bot API. Incoming channel updates are stored on the server no longer than 24 hours. That’s why action in the orkflo is triggered once every day. If you need more functionality, then look into full Telegram API, register new Telegram App and useapi_id
and anapi_hash
for authentification. This script should be rewritten for usage of another API. - save all posts from dictionary in the
YYYY-MM-DD-postId.md
format in_posts
folder
upload_to_github.py
- gets all files in your channel backup repository as a set
- commits and pushes all posts from
_posts
folder with right commit message (updated or created post)
(Optional, not used in the action workflow) backup_telegram_channel_history.py
If you already have a channel and there are already posts older than last 24 hours, then this optional script is for you. You need to have Python3 and Telegram Desktop installed. Telegraph and BeautifulSoup are used to prettify html string from Telegraph articles.
- Checkout this repository and install necessary dependancies:
- Go to Telegram Desktop, open your channel, click on three dots sign in the upper right corner and select
export chat history
, selectJSON
as format andjson_dump
as path - Convert posts and upload them to your repository: