The moment it happens
Back up Telegram bot messages to GitHub
Every message your Telegram bot receives is saved, and at 02:00 the day's messages are committed to a private GitHub repo as one file.
- Runs
- The moment it happens
- Apps
- GitHub, Telegram
- AI
- Not needed
- Access
- bot token; GitHub contents write on one repo (fine-grained token or OAuth repo)
Send this to your assistant
Create a ClickRuntime automation: keep every message my Telegram bot receives, and at 02:00 each day commit the previous day's messages to my private telegram-backup repo on GitHub as one JSON Lines file, then tell me on Telegram how many were saved.
First time? Adding ClickRuntime to your assistant takes about two minutes.
Why use it
Why teams use this automation
A bot that takes orders, support questions or sign-ups holds useful history, but Telegram keeps it only in the chat. If the bot is reset, a chat is deleted or you move to another server, that history is gone.
This automation gives your bot a version-controlled backup. Every incoming message is kept, and once a day ClickRuntime commits the batch to a private GitHub repo as a dated file, then tells you on Telegram that it worked.
It suits developers and small businesses who run a Telegram bot and already use GitHub for code and backups.
What you get out of it
History in a place you control
The repo is yours. Clone it, search it with grep or load it into a script whenever you need.
Full message data
Each line keeps the original message with sender, chat and timestamps, not just the text.
Daily proof it ran
The Telegram note with a commit link tells you each morning that the backup happened.
Git history for free
Every day is its own commit, so you can see what came in and when.
Small, readable files
One JSON Lines file per day is easy to open, diff and process later.
How it works
What happens, step by step
Each message your bot receives, in private chats or groups it belongs to, is kept by ClickRuntime as it arrives.
At 02:00 the previous day's messages are written to one dated file in your GitHub repo, in a messages folder.
Each line holds the full message, including sender, chat and time, so nothing is lost.
Your bot sends you a short note with the number of messages saved and a link to the commit.
Before it runs live
- Connect GitHub
- Connect Telegram
- Paste your automation's link into the other app's webhook settings
What you get
Build your own
Need it to work differently?
Your own rules
Conditions, thresholds, filters and exceptions, written the way you'd explain them to a colleague.
Any number of apps
One automation can read from one app and update several others. Over 248 apps are ready, and anything with an API works too.
AI where it helps
Summaries, classification, extraction and drafts use ClickRuntime's built-in AI, with no extra key.
On a schedule or on each event
Runs as often as every 5 minutes, or the moment an app sends an event, and keeps track of what it already handled.
Changes you can ask for
- Act only on the items that match your own rules, and skip the rest
- Add an AI step, for example to summarize, sort or draft a reply
- Add another app, for example also send it to Slack
- Combine it with other GitHub and Telegram steps into one automation
Under the hood
The code that runs this automation
import base64, json
from clickruntime import on_trigger, credentials, http, state
REPO, OWNER_CHAT = "yourname/telegram-backup", "123456789"
def gh(method, path, **kw):
r = http.request(method, f"https://api.github.com{path}", headers={
"Authorization": f"Bearer {credentials.connection('github', 'work')}", "Accept": "application/vnd.github+json"}, **kw)
r.raise_for_status()
return r.json() if r.content else None
def tg(method, **params):
r = http.post(f"https://api.telegram.org/bot{credentials.secret('TELEGRAM_BOT_TOKEN')}/{method}", json=params)
r.raise_for_status()
return r.json()["result"]
@on_trigger
def run(event):
update = event.get("json") or {}
msg = update.get("message") or update.get("channel_post")
if msg: # webhook
buf = state.get("buffer") or []
buf.append(msg)
state.set("buffer", buf)
return {"buffered": len(buf)}
buf = state.get("buffer") or [] # daily 02:00
if not buf:
tg("sendMessage", chat_id=OWNER_CHAT, text="Backup done: no new messages")
return {"saved": 0}
from datetime import datetime, timezone
day = datetime.fromtimestamp(buf[0]["date"], timezone.utc).strftime("%Y-%m-%d")
path = f"messages/{day}.jsonl"
body = "\n".join(json.dumps(m, ensure_ascii=False, sort_keys=True) for m in buf) + "\n"
try:
existing = gh("GET", f"/repos/{REPO}/contents/{path}")
body = base64.b64decode(existing["content"]).decode() + body
except Exception:
existing = None
res = gh("PUT", f"/repos/{REPO}/contents/{path}", json={"message": f"Backup {len(buf)} Telegram messages ({day})",
"content": base64.b64encode(body.encode()).decode(), **({"sha": existing["sha"]} if existing else {})})
state.set("buffer", [])
chats = len({m["chat"]["id"] for m in buf})
tg("sendMessage", chat_id=OWNER_CHAT, text=f"Backup done: {len(buf)} messages from {chats} chats\n{path}\n{res['commit']['html_url']}",
disable_web_page_preview=True)
return {"saved": len(buf)}
FAQ
Common questions
Does this back up my whole Telegram account?
Should the repo be private?
Are photos and files backed up too?
What permissions does it need?
Does it need AI?
How many runs does it use?
Can I change how it works?
Related
You might also like
Get GitHub issue updates on Telegram
Telegram messages you when an issue in your repository is opened, commented on or closed, with the title and a link.
See how it worksSave notes from Telegram to a GitHub repo
Send your bot a thought, link or to-do, and it is committed to your GitHub notes repo as a Markdown file you can pull into Obsidian or any editor.
See how it worksFile incoming bug reports as GitHub issues with a Telegram alert
Each bug report sent to your trigger link becomes a GitHub issue with a clear title, severity and labels, and Telegram alerts you.
See how it worksKeep exploring
Set up “Back up Telegram bot messages to GitHub” from your assistant
Copy the prompt above, or connect your assistant first. Free plan, no credit card.