The moment it happens
Save files and photos sent to Telegram in Drive
Anything sent to your Telegram bot is filed in Drive in a folder for each sender and date, and the bot replies with the link.
- Runs
- The moment it happens
- Apps
- Google Drive, Telegram
- AI
- Not needed
- Access
- Telegram bot token; Drive write
Send this to your assistant
Create a ClickRuntime automation: when a file or photo is sent to my Telegram bot, save it to Drive in a folder per sender and date and reply with the link.
First time? Adding ClickRuntime to your assistant takes about two minutes.
Why use it
Why teams use this automation
A property maintenance company has workers sending photos of finished jobs, receipts and meter readings through Telegram all day. The office then saves each one by hand, or more often does not, and the photo needed for a client dispute three months later is lost in a chat.
This automation files every photo and document sent to the company bot in Drive, organised by who sent it and when, so nothing is lost and anything can be found later.
What you get out of it
Nothing gets lost in chat history
Every photo and file is saved to Drive the moment it is sent, so it survives phone changes and deleted chats.
Organised without effort
Folders by sender and date mean you can find last Tuesday's photos from one worker in a few clicks.
Proof when you need it
Job photos and receipts are stored with their date, which settles questions from clients and accountants.
Senders know it worked
The bot replies with a Drive link, so the sender can see the file was saved and share the link if needed.
How it works
What happens, step by step
Someone sends a photo or file to your Telegram bot.
ClickRuntime downloads the file from Telegram.
It finds the folder for that sender and today's date in Drive, and creates it if it does not exist yet.
It saves the file there and replies in Telegram with the link.
Before it runs live
- Connect Google Drive
- 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 Google Drive and Telegram steps into one automation
Under the hood
The code that runs this automation
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build
from datetime import date
from googleapiclient.http import MediaInMemoryUpload
from clickruntime import on_event, credentials, http
ROOT = "your-telegram-uploads-folder-id"
def folder(drive, name, parent):
q = f"name='{name}' and '{parent}' in parents and mimeType='application/vnd.google-apps.folder' and trashed=false"
found = drive.files().list(q=q, fields="files(id)").execute()["files"]
return found[0]["id"] if found else drive.files().create(body={"name": name, "parents": [parent],
"mimeType": "application/vnd.google-apps.folder"}, fields="id").execute()["id"]
@on_event
def handle(event):
m = (event.json or {}).get("message", {})
item = m.get("document") or (m.get("photo") or [None])[-1]
if not item:
return {"skipped": True}
tg = f"https://api.telegram.org/bot{credentials.secret('TELEGRAM_BOT_TOKEN')}"
path = http.get(f"{tg}/getFile", params={"file_id": item["file_id"]}).json()["result"]["file_path"]
data = http.get(f"https://api.telegram.org/file/bot{credentials.secret('TELEGRAM_BOT_TOKEN')}/{path}").content
drive = build("drive", "v3", credentials=Credentials(credentials.connection("google", "work")), cache_discovery=False)
sender = m["from"].get("username") or m["from"]["first_name"]
parent = folder(drive, date.today().isoformat(), folder(drive, sender, ROOT))
f = drive.files().create(body={"name": item.get("file_name", path.split("/")[-1]), "parents": [parent]},
media_body=MediaInMemoryUpload(data), fields="webViewLink").execute()
http.post(f"{tg}/sendMessage", json={"chat_id": m["chat"]["id"], "text": f"Saved: {f['webViewLink']}"})
return {"saved": True}FAQ
Common questions
What kinds of files are saved?
Can I limit who can send files to the bot?
Is there a size limit?
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
Search Google Drive from a Telegram bot
Send your bot a few words and get back links to the matching files in your Google Drive, newest first.
See how it worksSave Telegram group messages to Google Drive daily
Your bot collects the messages in a Telegram group through the day and saves them as one dated text file in Google Drive each night.
See how it worksTranscribe voice notes sent to Telegram and save them to Drive
Send a voice note or audio file to your Telegram bot and get the text and a summary back, with both saved to your Transcripts folder.
See how it worksKeep exploring
Set up “Save files and photos sent to Telegram in Drive” from your assistant
Copy the prompt above, or connect your assistant first. Free plan, no credit card.