Intermediate~20 min setupAI & CommunicationVerified April 2026
OpenAI logo
Slack logo

How to Build AI-Powered Q&A Bot with N8n

Auto-respond to Slack mentions by sending questions to GPT-4 and posting AI answers as thread replies.

Steps and UI details are based on platform versions at time of writing β€” check each platform for the latest interface.

Best for

Teams wanting customizable AI bots with complex prompt logic and response formatting control.

Not ideal for

Quick deployments where basic AI responses without customization are sufficient.

Sync type

real-time

Use case type

notification

Real-World Example

πŸ’‘

A 25-person software company uses this bot in their #general channel to answer policy questions, debug errors, and explain internal tools. Before automation, employees interrupted managers 15-20 times daily with questions that had standard answers. Now GPT-4 handles 80% of common questions instantly, and managers only get complex issues that need human judgment.

What Will This Cost?

Drag the slider to your expected monthly volume.

/mo
505005K50K

Each platform counts differently β€” Zapier: 1 task per trigger. Make: 1 operation per module per record. n8n: 1 execution per run.

Prices shown for annual billing. Based on published pricing as of April 2026.

Estimated ROI

1000

min saved/mo

$583

labor value/mo

Free

no platform cost

Based on ~2 min manual effort per operation at $35/hr fully loaded labor cost.

Implementation

Skip the setup

Import this workflow directly into n8n

Copy the pre-built n8n blueprint and paste it straight into n8n. All modules, filters, and field mappings are already configured β€” you just need to connect your accounts.

Before You Start

Make sure you have everything ready.

N8n cloud account or self-hosted instance running
Slack workspace admin access to create bot apps
OpenAI API key with GPT-4 access
Slack app created with bot token and mention permissions

Field Mapping

Map these fields between your apps.

FieldAPI Name
Required
Message Texttext
Channel IDchannel
Message Timestampts
AI Responsetext
Prompt Textprompt
1 optional fieldβ–Έ show
User IDuser

Step-by-Step Setup

1

Workflows > New > + > Slack Trigger

Create new N8n workflow

Start a fresh workflow and add the initial Slack trigger. This monitors your workspace for bot mentions and kicks off the AI response flow.

  1. 1Click 'New Workflow' from the N8n dashboard
  2. 2Click the '+' button to add your first node
  3. 3Search for 'Slack' and select 'Slack Trigger'
  4. 4Choose 'On App Mention' as the trigger event
βœ“ What you should see: You should see a purple Slack Trigger node with 'On App Mention' selected in the parameters panel.
2

Node Parameters > Credentials > Create New

Connect Slack workspace

Authenticate N8n with your Slack workspace. You'll need bot token permissions to read mentions and post replies.

  1. 1Click 'Create New' next to Credentials in the Slack node
  2. 2Select 'OAuth2 API' credential type
  3. 3Click 'Connect my account' and authorize N8n
  4. 4Grant permissions for channels:history and chat:write
βœ“ What you should see: Green checkmark appears next to Credentials field showing successful Slack connection.
⚠
Common mistake β€” Make sure your Slack app has both channels:history and chat:write.public scopes or the bot won't see mentions in public channels.
n8n settings
Connection
Choose a connection…Add
click Add
OpenAI
Log in to authorize
Authorize n8n
popup window
βœ“
Connected
green checkmark
3

Slack Trigger Node > Listen for Test Event

Test Slack trigger

Verify the trigger captures mention data correctly. This confirms your bot receives the message text and thread details needed for GPT-4.

  1. 1Click 'Listen for Test Event' on the Slack trigger node
  2. 2Go to Slack and mention your bot with a test question
  3. 3Return to N8n and click 'Use Workflow Data'
  4. 4Verify the test data shows message text and channel info
βœ“ What you should see: Node shows green with sample data containing fields like 'text', 'channel', 'ts', and 'user'.
⚠
Common mistake β€” If no data appears, check that your Slack app is added to the channel where you're testing mentions.
n8n
β–Ά Run once
executed
βœ“
OpenAI
βœ“
Slack
Slack
πŸ”” notification
received
4

Add Node > OpenAI > Text > Complete

Add OpenAI node

Insert the GPT-4 node that processes user questions. This sends the mentioned text to OpenAI and receives the AI-generated response.

  1. 1Click '+' after the Slack trigger to add a new node
  2. 2Search for 'OpenAI' and select it
  3. 3Choose 'Text' operation and 'Complete' resource
  4. 4Set Model to 'gpt-4' in the dropdown
βœ“ What you should see: OpenAI node appears connected to Slack trigger with 'Text Complete' operation selected.
5

OpenAI Node > Credentials > Create New

Configure OpenAI credentials

Add your OpenAI API key so N8n can make requests to GPT-4. This enables the actual AI processing of user questions.

  1. 1Click 'Create New' next to Credentials in OpenAI node
  2. 2Paste your OpenAI API key into the API Key field
  3. 3Click 'Save' to store the credential
  4. 4Verify connection shows as successful
βœ“ What you should see: Green checkmark next to Credentials showing OpenAI connection is active.
⚠
Common mistake β€” GPT-4 API access requires a paid OpenAI account - the free tier only includes GPT-3.5-turbo.
6

OpenAI Node > Parameters > Prompt

Map question text to GPT-4 prompt

Extract the user's question from the Slack mention and format it for OpenAI. This removes bot mention syntax and creates a clean prompt.

  1. 1In the OpenAI node Prompt field, click the expression editor
  2. 2Enter: {{ $node['Slack Trigger'].json['text'].replace(/<@.*?>/g, '').trim() }}
  3. 3Set Max Tokens to 500 for reasonable response length
  4. 4Set Temperature to 0.7 for balanced creativity
βœ“ What you should see: Prompt field shows expression that extracts clean question text from Slack mention data.
⚠
Common mistake β€” Don't forget the trim() function - Slack mentions include extra whitespace that can confuse GPT-4 context.
OpenAI fields
choices[0].message.content
model
usage.prompt_tokens
usage.completion_tokens
finish_reason
available as variables:
1.props.choices[0].message.content
1.props.model
1.props.usage.prompt_tokens
1.props.usage.completion_tokens
1.props.finish_reason
7

OpenAI Node > Execute Node

Test AI response

Verify GPT-4 generates appropriate responses to user questions. This confirms the OpenAI integration works before adding Slack reply logic.

  1. 1Click 'Execute Node' on the OpenAI node
  2. 2Check the output data contains a 'text' field with AI response
  3. 3Verify the response makes sense for your test question
  4. 4Note the response length and adjust Max Tokens if needed
βœ“ What you should see: OpenAI node shows green with output containing GPT-4's text response to your question.
8

Add Node > Slack > Message > Post

Add Slack reply node

Create the node that posts GPT-4's response back to Slack. This completes the bot loop by sending AI answers as threaded replies.

  1. 1Click '+' after the OpenAI node to add another node
  2. 2Search for 'Slack' and select it again
  3. 3Choose 'Message' resource and 'Post' operation
  4. 4Select 'Post to Thread' to reply in the original thread
βœ“ What you should see: Second Slack node appears with 'Post Message to Thread' configuration selected.
⚠
Common mistake β€” Choose 'Post to Thread' not regular 'Post' - otherwise responses appear as new messages instead of threaded replies.
9

Slack Reply Node > Parameters

Configure thread reply mapping

Map the OpenAI response text and Slack thread details for proper reply posting. This ensures responses appear as threaded replies to the original mention.

  1. 1Set Channel to: {{ $node['Slack Trigger'].json['channel'] }}
  2. 2Set Text to: {{ $node['OpenAI'].json['text'] }}
  3. 3Set Thread TS to: {{ $node['Slack Trigger'].json['ts'] }}
  4. 4Leave other fields at default values
βœ“ What you should see: Reply node shows expressions pulling channel, response text, and timestamp from previous nodes.
⚠
Common mistake β€” Thread TS must use the original message timestamp - using event_ts instead will break threading.
10

Workflow > Execute Workflow

Test complete workflow

Run the full bot flow end-to-end to verify everything works. This confirms mentions trigger AI responses that post back to Slack correctly.

  1. 1Click 'Execute Workflow' to test the complete flow
  2. 2Go to Slack and mention your bot with a new question
  3. 3Check that a threaded reply appears with GPT-4's response
  4. 4Verify the response timing and accuracy
βœ“ What you should see: Bot responds to Slack mention with threaded AI-generated answer within 10-15 seconds.
11

Workflow > Active Toggle

Activate workflow

Turn on the workflow to handle mentions automatically. This switches from manual testing to live bot operation in your Slack workspace.

  1. 1Click the toggle switch in the top right to 'Active'
  2. 2Verify the workflow status changes to 'Active'
  3. 3Save the workflow with a descriptive name like 'AI Q&A Bot'
  4. 4Test one final mention to confirm live operation
βœ“ What you should see: Workflow shows 'Active' status and responds to mentions automatically without manual execution.
⚠
Common mistake β€” Active workflows consume execution credits even during low usage - monitor your N8n plan limits.

Drop this into an n8n Code node.

Copy this template{{ $node['Slack Trigger'].json['text'].replace(/<@.*?>/g, '').replace(/^\s+|\s+$/g, '').substring(0, 500) }}
β–Έ Show code
{{ $node['Slack Trigger'].json['text'].replace(/<@.*?>/g, '').replace(/^\s+|\s+$/g, '').substring(0, 500) }}

... expand to see full code

{{ $node['Slack Trigger'].json['text'].replace(/<@.*?>/g, '').replace(/^\s+|\s+$/g, '').substring(0, 500) }}

Scaling Beyond 500+ mentions/day+ Records

If your volume exceeds 500+ mentions/day records, apply these adjustments.

1

Add request queuing

Use N8n's Wait node with random delays between 1-5 seconds to avoid hitting OpenAI's rate limits. The free tier allows 3 requests/minute, paid accounts get 60/minute.

2

Cache common responses

Add a lookup node that checks frequently asked questions against a predefined response list before calling GPT-4. This cuts API costs by 40-60% for repetitive questions.

Going live

Production Checklist

Before you turn this on for real, confirm each item.

Troubleshooting

Common errors and how to fix them.

Frequently Asked Questions

Common questions about this workflow.

Analysis

VerdictWhy n8n for this workflow

Use N8n for this if you want full control over the AI prompt formatting and response processing. N8n's expression editor lets you clean up Slack mention syntax, add context, and format GPT-4 responses exactly how you want. The code nodes also handle complex logic like conversation history or response filtering. Pick Zapier instead if you need this running in 5 minutes with zero customization.

Cost

This workflow uses 3 operations per mention: Slack trigger, OpenAI request, and Slack reply. At 200 mentions/month, that's 600 operations monthly. N8n's Starter plan at $20/month includes 2,500 operations, so you're well covered. Zapier would cost $29.99/month for their Professional plan to handle the same volume with GPT-4. Make's $10.59 plan works but caps at 1,000 operations, so you'd hit limits fast.

Tradeoffs

Zapier wins on setup speed - their OpenAI integration has pre-built prompt templates and auto-formats responses. Make handles high volume better with built-in error retry and rate limiting that N8n requires manual configuration to match. But N8n beats both on customization depth. You can add conversation memory, user-specific prompts, or response post-processing that would require multiple Zaps or complex Make scenarios.

GPT-4 API calls fail randomly about 2% of the time due to OpenAI server load - add error handling or users will see no response to their questions. Slack's real-time API occasionally delivers mention events twice, so track processed message timestamps to avoid duplicate responses. OpenAI charges per token in both directions, so long user questions plus detailed bot responses cost more than simple Q&A pairs.

Ideas for what to build next

  • β†’
    Add conversation memory β€” Store chat history in a database and include recent context in GPT-4 prompts for more intelligent responses.
  • β†’
    Create response quality ratings β€” Add thumbs up/down reactions to bot replies and log feedback for improving prompts and model selection.
  • β†’
    Expand to direct messages β€” Duplicate the workflow with a DM trigger so users can ask questions privately without cluttering channels.

Related guides

Was this guide helpful?
← OpenAI + Slack overviewn8n profile β†’