The moment it happens
Answer Telegram questions from a Google Sheet
People message your Telegram bot and get answers drawn from your sheet, with every question and reply logged.
- Runs
- The moment it happens
- Apps
- Google Sheets, Telegram
- AI
- Yes, uses the built-in AI allowance
- Access
- Telegram bot token; Sheets read+write
Send this to your assistant
Create a ClickRuntime automation: when someone messages my Telegram bot, answer using the data in my Events sheet and log the question and answer in a Log tab.
First time? Adding ClickRuntime to your assistant takes about two minutes.
Why use it
Why teams use this automation
A small events organiser keeps the schedule, venues and ticket prices in one Google Sheet. Every week the same questions arrive by message: what time does the workshop start, is there parking, can I still buy a ticket. Answering them one by one eats evenings, and replies given from memory are sometimes out of date.
With this automation your Telegram bot reads the sheet each time someone writes and answers from what is in it. Update a row and the next answer reflects the change. Every question and answer is logged, so you can see what people ask most and fill the gaps.
What you get out of it
Answers stay in step with your data
The bot reads the sheet at the moment of the question, so a changed time or price is used straight away. There is no separate FAQ to keep in sync.
Fewer repeat messages for you
Routine questions about times, places and prices are handled without you. You step in only for the unusual ones that the sheet cannot answer.
A record of what people ask
The log tab shows every question and reply with a time. Recurring questions point to information you should add to the sheet or your event page.
Follow-up questions make sense
Recent messages from the same person are kept, so a reply like 'and on Sunday?' is understood in context. Conversations feel natural rather than one-shot.
Works at any hour
Attendees often check details late the night before. The bot replies right away, even when nobody on the team is online.
How it works
What happens, step by step
When someone sends a message to your Telegram bot, ClickRuntime receives it straight away.
It reads the rows in your Events sheet and the last few messages from that chat.
AI writes a short reply using only what is in the sheet, and the bot sends it back.
The question and answer are added as a new row in the Log tab of the sheet.
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
- Change what the AI looks for, or how it writes the result
- 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 datetime, timezone
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build
from clickruntime import on_event, credentials, http, state, ai
SHEET_ID = "your-spreadsheet-id"
@on_event
def handle(event):
msg = (event.json or {}).get("message") or {}
chat, text = msg.get("chat", {}).get("id"), msg.get("text")
if not chat or not text:
return {"skipped": True}
sheets = build("sheets", "v4", credentials=Credentials(credentials.connection("google", "work")), cache_discovery=False).spreadsheets()
rows = sheets.values().get(spreadsheetId=SHEET_ID, range="Events!A1:F200").execute().get("values", [])
history = state.get(f"chat:{chat}") or []
data = "\n".join(" | ".join(r) for r in rows)
try:
answer = ai.generate(f"Data:\n{data}\n\nRecent chat:\n" + "\n".join(history[-6:]) + f"\n\nQuestion: {text}",
system="Answer briefly using only the data. If it is not there, say so.", max_output_tokens=300).text.strip()
except ai.AIError:
answer = "Sorry, I can't answer right now. Please try again later."
token = credentials.secret("TELEGRAM_BOT_TOKEN")
http.post(f"https://api.telegram.org/bot{token}/sendMessage", json={"chat_id": chat, "text": answer})
state.set(f"chat:{chat}", (history + [f"Q: {text}", f"A: {answer}"])[-10:])
sheets.values().append(spreadsheetId=SHEET_ID, range="Log!A:D", valueInputOption="USER_ENTERED",
body={"values": [[datetime.now(timezone.utc).isoformat(timespec="minutes"), str(chat), text, answer]]}).execute()
return {"answered": True}FAQ
Common questions
What kind of sheet works best?
What happens when the answer is not in the sheet?
Can several people use the bot at once?
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
Turn 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 worksTurn receipt photos into rows in your expense sheet
Send a photo of a receipt to your Telegram bot and the merchant, date, total and category land in your expenses sheet.
See how it worksLog meals and macros by messaging a Telegram bot
Tell your bot what you ate and get calories and macros logged in your sheet, with today's total in the reply.
See how it worksKeep exploring
Set up “Answer Telegram questions from a Google Sheet” from your assistant
Copy the prompt above, or connect your assistant first. Free plan, no credit card.