Skip to content

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.

Paste it into your assistant. It tells you what it will send or change before it runs live.

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

  1. Every 5 minutes, ClickRuntime checks Gmail for new support emails.

  2. It searches your Supabase knowledge table for the answers most related to each question.

  3. AI writes a reply using only those answers, and it's saved as a draft in the email thread.

  4. It also looks at replies you've sent since the last check and saves them to the knowledge table.

  5. 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

RunsEvery 5 minutes
Draft support replies in Gmail from your Supabase knowledge basetoday, 9:00Succeeded
Gmail · DraftsRe: Can I change my billing date? – Hi Sam, yes: go to Settings → Billing and pick a new date…

Build your own

Need it to work differently?

This template is a starting point. Copy the prompt and change it, or describe a different automation from scratch, with your own conditions, more apps or an AI step. Your assistant writes it, tests it and runs it on ClickRuntime.
  • 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

This is the Python script that runs each time the automation starts. Your AI assistant writes it for you when you send the prompt, and you allow each step in your assistant. To change how the automation works, describe the change to your assistant and it updates the script for you. For every function it can use, see the script reference.
email_auto_replies_from_a_supabase_knowledge_base.pyexample
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?
No. It only creates drafts in the original thread. You review and send them.
How does it find relevant answers?
It calls a search function in your Supabase project, such as a text or vector match on your knowledge table, and uses the top results.
Which emails get drafts?
New messages matching your support search, such as emails to support@ or with a Support label.
What permissions does it need?
Gmail compose+read; Supabase read+write. Nothing else in your accounts is used.
Does it need AI?
Yes. It uses ClickRuntime's built-in AI, so you don't need an OpenAI or Anthropic key. Every plan includes a monthly AI allowance.
How many runs does it use?
One run each time it checks. Checks that find nothing new and stop right away aren't counted.
Can I change how it works?
Yes. Describe the change to your AI assistant, for example a different schedule, channel or filter. It updates the automation, tests it and tells you what changed.

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.