The moment it happens
Record every Telegram bot user in a sheet
Each new person who messages your Telegram bot is added to a sheet and greeted, and returning users get their last-seen date updated.
- Runs
- The moment it happens
- Apps
- Google Sheets, Telegram
- AI
- Not needed
- Access
- Telegram bot token; Sheets read+write
Send this to your assistant
Create a ClickRuntime automation: when someone messages my Telegram bot, add them to my Users sheet with name, username and date if they are new, otherwise update their last-seen date, and greet them.
First time? Adding ClickRuntime to your assistant takes about two minutes.
Why use it
Why teams use this automation
A small online language school uses a Telegram bot for lesson reminders and quick questions. The bot works, but nobody knows how many people use it, who joined this month or who has gone quiet. Telegram itself gives a bot no list of its users, so the team cannot follow up or send an announcement to everyone.
Keeping a simple register in a sheet turns the bot into something the team can manage. Schools, shops, clubs and support teams that run a bot use it to know their audience and to build the chat list for later announcements.
What you get out of it
A list of your audience you own
Every person who writes to the bot is recorded with their name, username and chat ID. That list is yours to sort, filter and use, rather than something only Telegram knows.
See who is active and who has gone quiet
The last-seen date shows who used the bot recently. You can follow up with people who have not been back for a month, or report on how many are active each week.
New users feel welcomed
A first message gets a greeting, and a returning user gets a different one. It is a small touch that makes the bot feel looked after.
Ready for announcements later
The chat IDs in the sheet are exactly what you need to send a message to everyone. When you have news, the audience list already exists.
How it works
What happens, step by step
When someone sends a message to your Telegram bot, Telegram passes it straight to ClickRuntime.
ClickRuntime looks for that person in the Users sheet.
A new person is added as a row with their name, username and today's date; for someone already listed, only their last-seen date is updated.
The bot replies with a welcome for new users or a short hello for returning ones.
Before it runs live
- Connect your Google Sheets account and pick the spreadsheets it may use
- 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 Sheets and Telegram steps into one automation
Under the hood
The code that runs this automation
from datetime import date
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build
from clickruntime import on_event, credentials, http
SHEET_ID = "your-spreadsheet-id"
@on_event
def handle(event):
msg = (event.json or {}).get("message")
if not msg:
return {"skipped": True}
user, today = msg["from"], date.today().isoformat()
values = build("sheets", "v4", credentials=Credentials(credentials.connection("google", "work")),
cache_discovery=False).spreadsheets().values()
ids = [r[0] if r else "" for r in values.get(spreadsheetId=SHEET_ID, range="Users!A2:A").execute().get("values", [])]
if str(user["id"]) in ids:
row = ids.index(str(user["id"])) + 2
values.update(spreadsheetId=SHEET_ID, range=f"Users!E{row}", valueInputOption="RAW", body={"values": [[today]]}).execute()
text = f"Welcome back, {user.get('first_name', '')}!"
else:
values.append(spreadsheetId=SHEET_ID, range="Users!A:E", valueInputOption="RAW", body={"values": [[
str(user["id"]), user.get("first_name", ""), user.get("username", ""), today, today]]}).execute()
text = f"Hi {user.get('first_name', '')}, thanks for getting in touch!"
http.post(f"https://api.telegram.org/bot{credentials.secret('TELEGRAM_BOT_TOKEN')}/sendMessage",
json={"chat_id": msg["chat"]["id"], "text": text})
return {"new": str(user["id"]) not in ids}
FAQ
Common questions
What details are recorded about each user?
Does it work in group chats?
Can I change the greeting?
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
Sell with Telegram Stars and log every payment in a sheet
Customers buy from your bot with Telegram Stars, and every payment and refund lands in your Google Sheet.
See how it worksTrack focus sessions from Telegram in a sheet
Start and stop focus sessions with a Telegram message and every session is logged with its duration, with today's total in the reply.
See how it worksTurn Telegram ideas into short videos logged in a sheet
Message your bot an idea and get back a finished short video, with every video tracked in your Google Sheet.
See how it worksKeep exploring
Set up “Record every Telegram bot user in a sheet” from your assistant
Copy the prompt above, or connect your assistant first. Free plan, no credit card.