Every 5 minutes
Draft support replies in Gmail from your Supabase knowledge base
New support emails get a draft reply in Gmail based on answers stored in your Supabase knowledge table, and replies you send are saved back as new knowledge.
- Runs
- Every 5 minutes
- Apps
- Gmail, Supabase
- AI
- Yes, uses the built-in AI allowance
- Access
- Gmail compose+read; Supabase read+write
Send this to your assistant
Create a ClickRuntime automation: every 5 minutes, for new support emails, find relevant answers in my Supabase knowledge table, draft a reply in Gmail, and save the replies I actually send back into the table.
First time? Adding ClickRuntime to your assistant takes about two minutes.
Why use it
Why teams use this automation
A two-person support team answers the same questions every week, retyping or hunting for last month's reply. The answers exist, scattered across sent mail, but finding them takes longer than writing a new one.
Drafting each reply from a knowledge base, and adding every reply you send to that base, means the drafts get better over time and nobody writes the same answer twice.
What you get out of it
Faster first replies
A ready draft waits in Gmail, so answering takes a quick read and a click.
You stay in control
Nothing is sent automatically. You edit and send each draft yourself.
It learns from you
Replies you send are saved as knowledge, so tomorrow's drafts use today's corrections.
Consistent answers
Customers get the same correct answer whoever is on support.
How it works
What happens, step by step
Every 5 minutes, ClickRuntime checks Gmail for new support emails.
It searches your Supabase knowledge table for the answers most related to each question.
AI writes a reply using only those answers, and it's saved as a draft in the email thread.
It also looks at replies you've sent since the last check and saves them to the knowledge table.
Emails already handled are remembered, so each gets one draft.
Before it runs live
- Connect Google through your own Google app (a one-time, 10-minute setup), so it works with your own Gmail
- Connect Supabase
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 Gmail and Supabase steps into one automation
Under the hood
The code that runs this automation
import base64
from email.message import EmailMessage
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build
from clickruntime import on_trigger, credentials, http, state, ai, report_fetched
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)
@on_trigger
def run(event):
gmail, done = build("gmail", "v1", credentials=Credentials(credentials.connection("google", "work")), cache_discovery=False), set(state.get("done") or [])
msgs = [m for m in gmail.users().messages().list(userId="me", q="label:Support is:unread newer_than:1d").execute().get("messages", []) if m["id"] not in done]
sent = [m for m in gmail.users().messages().list(userId="me", q="in:sent label:Support newer_than:1d").execute().get("messages", []) if m["id"] not in done]
report_fetched(len(msgs) + len(sent))
if not msgs and not sent:
return {"summary": "Nothing new"}
for m in msgs:
full = gmail.users().messages().get(userId="me", id=m["id"]).execute()
h = {x["name"]: x["value"] for x in full["payload"]["headers"]}
docs = sb("POST", "rpc/match_documents", json={"query_text": full["snippet"], "match_count": 4})
reply = ai.generate("Write a short, friendly support reply using only these notes:\n" + "\n".join(d["content"] for d in docs)
+ f"\n\nCustomer wrote: {full['snippet']}", max_output_tokens=400).text
msg = EmailMessage()
msg["To"], msg["Subject"], msg["In-Reply-To"] = h["From"], "Re: " + h.get("Subject", ""), h.get("Message-ID", "")
msg.set_content(reply)
gmail.users().drafts().create(userId="me", body={"message": {"threadId": full["threadId"], "raw": base64.urlsafe_b64encode(msg.as_bytes()).decode()}}).execute()
done.add(m["id"])
for m in sent:
sb("POST", "knowledge", json={"content": gmail.users().messages().get(userId="me", id=m["id"]).execute()["snippet"], "source": "sent reply"})
done.add(m["id"])
state.set("done", list(done)[-2000:])
return {"drafts": len(msgs), "learned": len(sent)}FAQ
Common questions
Does it send emails on its own?
How does it find relevant answers?
Which emails get drafts?
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 action items in your email into Supabase tasks
Every 15 minutes, tasks mentioned in your new emails, with owners and due dates, are added as rows in your Supabase tasks table.
See how it worksReply to quote requests with prices from your Supabase products
Quote requests in your inbox get a reply priced from your Supabase product table, and every quote is logged.
See how it worksScreen emailed CVs into a Supabase candidates table
CVs sent to your hiring inbox are read, summarised and scored against the role, and each candidate is added to your Supabase table.
See how it worksKeep exploring
Set up “Draft support replies in Gmail from your Supabase knowledge base” from your assistant
Copy the prompt above, or connect your assistant first. Free plan, no credit card.