Slack support bot that answers from your Supabase knowledge base

By General Input

When your bot is @mentioned in Slack, it answers from your Supabase knowledge base with cited sources, or files a Linear ticket when it isn't sure.

Integrations

  • Slack Bot
  • Supabase
  • Linear

Type

Agentic Task

Categories

  • Customer Support

Build a Slack support bot that answers questions from my Supabase knowledge base using retrieval-augmented generation, and escalates to Linear when it isn't confident.

Trigger: a Slack events webhook for app_mention. The workflow should fire whenever the bot is @mentioned in any channel it has been added to. Use the slackbot integration (bot token) so the bot has its own identity in the workspace.

When an @mention comes in, do the following:

1) Extract the user's question from the event text, stripping out the bot's own @mention. Capture channel, message ts, and thread_ts (fall back to ts if no thread_ts) so we can reply in the right thread.

2) Generate a vector embedding of the question. Use the same embedding model that was used to populate the knowledge base table (typically OpenAI text-embedding-3-small at 1536 dims). Make the embedding model configurable.

3) Call a Postgres function in Supabase via Call Function (RPC). The default function name is match_documents, taking arguments { query_embedding, match_threshold, match_count }. Defaults: match_threshold = 0.75, match_count = 5. The function is expected to run pgvector cosine similarity against a knowledge_base table and return ranked rows with at least these fields: id, content, title (or source/url), and similarity. Both the function name and the threshold should be tunable parameters at the top of the workflow.

4) Inspect the top result's similarity score. If it is at or above the threshold, synthesize a grounded answer using only the returned passages. The answer should be short and direct, cite the source doc titles inline (e.g. "Source: Refund policy"), and never invent facts that aren't in the passages. If multiple passages are relevant, weave them together rather than dumping them.

5) Post the answer back to Slack with slackbot's Send a Message operation, using the original channel and thread_ts so the reply lands inside the question's thread. Use Slack mrkdwn formatting (single asterisks for bold, <url|text> for links).

6) If the top similarity is below the threshold (low confidence), do NOT guess. Instead: (a) call Get Permalink on the original Slack message to get a thread link, (b) create a Linear issue using Create Issue with title "[Support] " plus a short version of the question, description containing the full question and the Slack permalink, and label "support-handoff". Default to the configured Linear team. Then post a short message in the Slack thread letting the user know a teammate has been pulled in, and include the Linear issue URL.

Configuration knobs the workflow should expose at the top: Supabase function name (default match_documents), confidence threshold (default 0.75), match_count (default 5), embedding model (default text-embedding-3-small), Linear team key, Linear label (default support-handoff), and an optional Linear default assignee.

Note for setup: the user is responsible for having a knowledge_base table with an embedding column (vector(1536) using pgvector) and a Postgres function that performs cosine similarity. The canonical version is in the Supabase pgvector RAG guide: a function that takes (query_embedding vector, match_threshold float, match_count int) and returns rows ordered by 1 - (embedding <=> query_embedding) descending. The agent should mention this in the setup notes if the function doesn't exist yet.

Edge cases to handle: ignore the Slack events url_verification challenge correctly, ignore mentions from the bot itself (bot_id present) to avoid loops, and ignore message_changed/edited subtypes. If the Supabase RPC returns zero rows, treat it as low confidence and escalate.

Related prompts

Explore more prompts
A brand asset library your marketing team actually searchesTurn Mailjet email clicks into ranked HubSpot follow-upsClean out the Looker dashboards and Looks nobody opensLiveKit live operations console for room moderationWake up dormant Keap leads with a researched reasonLiveChat coverage board for planning next week's shiftsPhone routing control panel for LiveKit voice agentsLinkedIn Ads budget pacing dashboard for every client accountGive your team Looker numbers without buying more seatsPause marketing emails to escalated customers, then restore them