Back to journal
AI & Automation

GPT-Powered Slack Bot With n8n: Build It

Learn how to build a GPT Slack bot with n8n step-by-step. Give your team an internal AI assistant that answers questions without leaving Slack.

Tommy Rush
GPT-Powered Slack Bot With n8n: Build It
Share

If you want to build a GPT Slack bot with n8n, you already know the pitch: your team spends a non-trivial chunk of their day hunting for answers that already exist somewhere — in a shared doc, a past email thread, a policy PDF nobody bookmarks. An internal AI assistant Slack integration changes that pattern. Instead of interrupting a colleague or spelunking through Google Drive, someone types a question in a channel and gets a useful answer in seconds. This guide walks through exactly how to wire that up using n8n and OpenAI, with enough detail that you can run it in your own environment by end of day.

Why n8n for a Slack AI Bot?

You have options. You could write a custom Node.js app, use Zapier's OpenAI integration, or pay for a third-party Slack AI product. Each has a place, but n8n hits a useful middle ground for SMBs:

  • Self-hostable or cloud-hosted. If your business has data-sensitivity requirements, running n8n on your own server means messages never touch a vendor you haven't vetted. The n8n cloud plan works fine too if self-hosting isn't a priority.
  • Visual workflow editor. Building and iterating is faster when you can see the data flow between nodes. Non-developers can understand (and often maintain) what's happening.
  • Native integrations. n8n ships with Slack and OpenAI nodes out of the box, so you're not writing API boilerplate.
  • Cost-effective. The n8n GPT workflow build guide you'll follow here runs on whatever OpenAI API spend your usage generates — you're not paying a per-seat SaaS markup on top of model costs.

The tradeoff: n8n requires a little more setup discipline than a point-and-click chatbot builder. What you get in return is full control over the logic, the model, and the data that flows through it.

What You'll Build

A no-code Slack AI assistant that:

  1. Listens for messages in specific Slack channels (or all channels where the bot is invited).
  2. Sends each message to OpenAI's Chat Completions API with a system prompt you control.
  3. Posts the model's response back into the same Slack thread.

Optionally, you can extend this to include document context — pasting in excerpts from your SOPs or knowledge base so the model's answers are grounded in your actual content. That extension is covered at the end.

Prerequisites

Before you open n8n, gather these:

  • An n8n instance — either self-hosted (Docker is the simplest path) or an n8n Cloud account.
  • An OpenAI API key — from platform.openai.com. If your organization already uses GPT-4 or GPT-4o through an Azure deployment, n8n supports that too.
  • A Slack app with the following scopes: app_mentions:read, chat:write, channels:history, groups:history. Enable Event Subscriptions and point the Request URL at your n8n webhook.

If you haven't created a Slack app before, Slack's App Dashboard at api.slack.com/apps is the starting point. Create a new app "from scratch," pick your workspace, and configure the OAuth scopes under "Bot Token Scopes." Install the app to your workspace and copy the Bot User OAuth Token — you'll need it in n8n.

Step 1: Set Up the Slack Trigger in n8n

Open n8n, create a new workflow, and add a Webhook node as the trigger. Configure it:

  • HTTP Method: POST
  • Path: something memorable like /slack-gpt-bot
  • Response Mode: "Respond to Webhook" (you'll need to send a response back to Slack within 3 seconds to avoid retries)

Copy the webhook URL that n8n generates. Go back to your Slack app settings, open "Event Subscriptions," toggle it on, and paste the URL into the "Request URL" field. Slack will send a challenge request; your n8n webhook will need to be active to respond. Once verified, subscribe to the app_mention event under "Subscribe to bot events." This means the bot only triggers when someone explicitly mentions it with @YourBotName, which avoids noisy behavior in busy channels.

Why app_mention instead of message.channels? The message.channels event fires on every message in every channel the bot is in — that gets expensive in API calls fast. Starting with app_mention keeps usage focused and intentional.

Step 2: Extract the Message Text

After the Webhook node, add a Set node (or use an Expression inline) to extract the user's question from the Slack event payload. The structure you'll work with looks like this:

{{ $json.body.event.text }}

Slack includes the bot mention in the text (e.g., @YourBot what's our refund policy?), so you'll want to strip that out. A simple Function node can handle it:

const text = $input.first().json.body.event.text;
const cleaned = text.replace(/<@[A-Z0-9]+>/g, '').trim();
return [{ json: { question: cleaned } }];

Also capture the channel ID and thread timestamp — you'll need both to post the response back into the correct thread:

const event = $input.first().json.body.event;
return [{
  json: {
    question: event.text.replace(/<@[A-Z0-9]+>/g, '').trim(),
    channel: event.channel,
    thread_ts: event.thread_ts || event.ts
  }
}];

Step 3: Send to OpenAI

Add an OpenAI node and configure it:

  • Resource: Chat
  • Operation: Message a Model
  • Model: gpt-4o or gpt-4o-mini (the latter is faster and cheaper for most internal Q&A use cases)
  • Messages:
    • Role: system, Content: your system prompt (see below)
    • Role: user, Content: {{ $json.question }}

Your system prompt is the most important thing you'll configure. A starting point for an internal AI assistant Slack use case:

You are a helpful internal assistant for [Company Name]. Answer questions clearly and concisely. If you don't know the answer, say so — don't guess. Keep responses under 300 words unless detail is specifically requested.

You can be as specific as you like here. If the bot should only answer questions about HR policy, say that. If it should default to a certain tone, specify it. The model follows explicit instructions well when they're written clearly.

Step 4: Post the Response Back to Slack

Add a Slack node:

  • Operation: Post Message
  • Channel: {{ $('Function').item.json.channel }}
  • Text: {{ $json.choices[0].message.content }}
  • Thread Timestamp: {{ $('Function').item.json.thread_ts }}

Posting in a thread rather than the channel root keeps conversations organized. Users get their answer nested under their original question, which makes it easy to follow context.

Finally, connect a Respond to Webhook node before the OpenAI call to immediately return a 200 OK to Slack. Slack will otherwise retry the webhook after 3 seconds if it doesn't get a response, causing duplicate messages. The actual response to the user goes through the Slack node after the model returns its answer.

Step 5: Test the Workflow

Activate the workflow in n8n, go to your Slack workspace, and mention the bot in a channel it's been invited to:

@YourBot what does our PTO policy say about rollover?

Within a few seconds you should see a threaded reply. If the bot doesn't respond, check:

  1. The n8n execution log for errors.
  2. Whether Slack's Event Subscriptions are correctly pointed at your webhook URL.
  3. Whether the Bot User OAuth Token is correctly saved in n8n's Slack credentials.

Extending With a Knowledge Base

The basic setup answers questions based on whatever GPT already knows, which is useful but limited for company-specific information. To ground the bot's answers in your actual documents, you have two main options:

Option A — Paste context into the system prompt. For short documents (under a few thousand words), paste the content directly into the system prompt. This works well for a single policy doc, a price list, or a product FAQ. The downside is that system prompts have token limits, and you'll pay for that context on every call.

Option B — Retrieval-augmented generation (RAG). For larger knowledge bases, a vector database like Pinecone or Supabase's pgvector stores embeddings of your documents. When a question comes in, n8n first queries the vector DB for relevant chunks, then injects those chunks into the OpenAI prompt as context. This scales to hundreds of documents without bloating every API call.

For most SMBs starting out, Option A is sufficient and far simpler to maintain. You can always migrate to a RAG architecture later without rebuilding the core Slack bot.

Common Pitfalls

  • Duplicate responses. Almost always caused by not responding to Slack's webhook challenge quickly enough. Ensure the Respond to Webhook node fires before the OpenAI call.
  • Bot responding to itself. Add a filter node after the webhook trigger that checks $json.body.event.bot_id — if it's present, stop the workflow. This prevents the bot from looping on its own messages.
  • Context-free conversations. By default, each mention is treated as a fresh conversation. If you need the bot to remember prior turns in a thread, you'll need to fetch thread history via the Slack API before sending to OpenAI, then construct a multi-turn message array. That's a worthwhile extension for support-style bots, but optional for simple Q&A.

What This Gets You

A self-hosted Slack AI bot built this way answers questions in Slack without routing sensitive internal questions through a third-party SaaS product you don't control. The workflow is readable, editable, and doesn't require a developer to update the system prompt or swap the underlying model. For a small team, consider a scenario where a new hire can get answers to onboarding questions at any hour without blocking a senior employee — that's a concrete, daily time-save.

The pattern also extends beyond Q&A. The same n8n OpenAI Slack bot architecture can summarize threads when you mention the bot, draft responses to customer messages, classify support tickets, or trigger downstream workflows based on what someone asks.

Ready to Set This Up for Your Business?

If you'd rather have this deployed and tailored to your team's needs than build it from scratch, Intuitional handles the full implementation — from Slack app configuration to knowledge base integration and ongoing maintenance. schedule a conversation about your workflow to talk through what an internal AI assistant would look like in your specific environment.

Explore this topic further

Jump into the journal with one of the themes from this article.

Want AI that actually improves the workflow?

We design AI-assisted systems that help with routing, summarization, decision support, and repetitive work without making the team lose trust.

Run the workflow ROI calculator