The moment it happens
Run a Telegram assistant that remembers each user
Your Telegram bot replies with AI and remembers each user's recent messages, stored in your Supabase tables, so conversations stay in context.
- Runs
- The moment it happens
- Apps
- Supabase, Telegram
- AI
- Yes, uses the built-in AI allowance
- Access
- Supabase read+write; bot token
Send this to your assistant
Create a ClickRuntime automation: when someone messages my Telegram bot, reply with AI using their last 20 messages from my Supabase messages table, and save both their message and the reply.
First time? Adding ClickRuntime to your assistant takes about two minutes.
Why use it
Why teams use this automation
A coach or small community runs a Telegram bot for members. Without memory, every message starts from zero: the bot forgets the member's name, their goal and what it said yesterday, so the conversation feels robotic.
Keeping each user's recent messages in Supabase and passing them to the reply gives the bot continuity, while you keep full ownership of the conversation history.
What you get out of it
Conversations that make sense
The bot remembers what each person said earlier, so replies follow on naturally.
Separate memory for every user
Each person's history is kept apart, so nothing leaks between chats.
History you own
Messages are stored in your Supabase project, where you can review, export or delete them.
Costs kept in check
Only the last 20 messages are sent with each reply.
How it works
What happens, step by step
Someone sends your Telegram bot a message.
ClickRuntime records the user in your Supabase users table if they're new.
It loads their last 20 messages from your messages table.
AI writes a reply that takes that history into account.
The bot sends the reply, and both messages are saved to Supabase.
Before it runs live
- Connect Supabase
- 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 Supabase and Telegram steps into one automation
Under the hood
The code that runs this automation
from clickruntime import on_event, credentials, http, ai
PERSONA = "You are the Northwind running club's friendly training assistant. Keep replies short."
SUPABASE = "https://your-project.supabase.co/rest/v1"
def sb(method, path, **kw):
key = credentials.secret("SUPABASE_KEY")
r = http.request(method, f"{SUPABASE}/{path}", **kw, headers={"apikey": key, "Authorization": f"Bearer {key}", "Prefer": "return=representation,resolution=merge-duplicates"})
return r.raise_for_status() or (r.json() if r.content else None)
def tg(method, **params):
return http.post(f"https://api.telegram.org/bot{credentials.secret('TELEGRAM_BOT_TOKEN')}/{method}", json=params).json()
@on_event
def handle(event):
msg = (event.json or {}).get("message") or {}
if not msg.get("text"):
return {"skipped": True}
user = msg["from"]
sb("POST", "users?on_conflict=id", json={"id": user["id"], "name": user.get("first_name")})
history = sb("GET", f"messages?user_id=eq.{user['id']}&order=created_at.desc&limit=20")[::-1]
convo = "\n".join(f"{m['role']}: {m['text']}" for m in history)
reply = ai.generate(f"{convo}\nuser: {msg['text']}\nassistant:", system=f"{PERSONA} The user's name is {user.get('first_name')}.", max_output_tokens=400).text
tg("sendMessage", chat_id=msg["chat"]["id"], text=reply)
sb("POST", "messages", json=[{"user_id": user["id"], "role": "user", "text": msg["text"]}, {"user_id": user["id"], "role": "assistant", "text": reply}])
return {"user": user["id"], "history": len(history)}FAQ
Common questions
Can I set the bot's personality?
How do I delete someone's history?
What tables does it need?
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
Answer questions in Telegram from your own documents
People ask your Telegram bot a question and get an answer drawn from the documents stored in your Supabase table.
See how it worksAdd and list Supabase records from Telegram commands
You type /add, /list or /delete to your Telegram bot and the matching rows in your Supabase table are created, shown or removed.
See how it worksCheck form sign-ups, save them to Supabase and ping Telegram
Each customer your form sends is checked, saved to Supabase unless they already exist, and you get a Telegram message either way.
See how it worksKeep exploring
Set up “Run a Telegram assistant that remembers each user” from your assistant
Copy the prompt above, or connect your assistant first. Free plan, no credit card.