Skip to content

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.

Paste it into your assistant. It tells you what it will send or change before it runs live.

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

  1. Each message your bot receives, in private chats or groups it belongs to, is kept by ClickRuntime as it arrives.

  2. At 02:00 the previous day's messages are written to one dated file in your GitHub repo, in a messages folder.

  3. Each line holds the full message, including sender, chat and time, so nothing is lost.

  4. 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

RunsThe moment it happens
Back up Telegram bot messages to GitHubjust nowSucceeded
Telegram · your botBackup done: 212 messages from 7 chats messages/2026-11-09.jsonl https://github.com/yourname/telegram-backup/commit/9f3c2a1

Build your own

Need it to work differently?

This template is a starting point. Copy the prompt and change it, or describe a different automation from scratch, with your own conditions, more apps or an AI step. Your assistant writes it, tests it and runs it on ClickRuntime.
  • 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

This is the Python script that runs each time the automation starts. Your AI assistant writes it for you when you send the prompt, and you allow each step in your assistant. To change how the automation works, describe the change to your assistant and it updates the script for you. For every function it can use, see the script reference.
back_up_telegram_bot_messages_to_github.pyexample
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?
No. It saves messages your bot receives: direct messages to the bot, and group or channel messages where the bot is a member and can read them. Personal chats with other people are not reachable through the Bot API.
Should the repo be private?
Yes. Message text, names and user IDs are personal data, so use a private repository and limit who can read it.
Are photos and files backed up too?
The file references are saved in each message line. Ask your assistant to also download attachments with getFile and commit them, keeping in mind GitHub's 100 MB file limit.
What permissions does it need?
bot token; GitHub contents write on one repo (fine-grained token or OAuth repo). Nothing else in your accounts is used.
Does it need AI?
No. It runs without AI, so it doesn't use your plan's AI allowance.
How many runs does it use?
One run for each event the app sends.
Can I change how it works?
Yes. Describe the change to your AI assistant, for example a different schedule, channel or filter. It updates the automation, tests it and tells you what changed.

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.