Chapter 8: Slack API Setup and Integration¶
Video: Watch this chapter on YouTube (1:41:48)
Overview¶
This chapter covers two main topics: setting up Slack API integration with n8n, and building an advanced workflow where an AI agent can respond to Slack messages on your behalf. It includes permission configuration, event subscriptions, and creating a RAG-enabled assistant.
Detailed Summary¶
Part 1: Basic Slack API Setup¶
Creating a Slack App¶
- Navigate to
api.slack.com - Sign in to your Slack workspace
- Go to Your Apps section
- Click Create New App
- Choose From scratch
- Enter app name (e.g., "n8n Demo Bot")
- Select your workspace
- Click Create App
Configuring Bot Permissions¶
Navigate to OAuth & Permissions:
- Scroll to Bot Token Scopes
- Click Add an OAuth Scope
- Add required scopes:
app_mentions:read- Read messages mentioning the botchat:write- Send messages as the botchannels:read- Access channel informationgroups:read- Access private channel infousers.profile:read- Read user profilesusers:read- Access user information
Installing the App¶
- Scroll to top of OAuth & Permissions page
- Click Install to Workspace
- Review permissions
- Click Allow
- Copy the Bot User OAuth Token (starts with
xoxb-)
Configuring Event Subscriptions¶
- Go to Event Subscriptions in sidebar
- Toggle Enable Events to ON
- For Request URL:
- Go to n8n workflow
- Add Slack trigger node
- Copy the Test URL from webhook URLs
- Paste into Slack Request URL field
- Wait for verification (run trigger node first)
- Add Subscribe to Bot Events:
-
app_mention- Triggers when bot is @mentioned -
Click Save Changes
Connecting Slack to n8n¶
Creating Slack Credentials¶
- In n8n, add Slack Trigger node (not regular Slack node)
- Select On bot/app mention event
- Create new credential:
- Name: "Slack n8n Demo"
- Paste Bot User OAuth Token
- Click Save
- See "Connection tested successfully"
Configuring the Trigger¶
- Select channel to watch (from list, by ID, or by URL)
- Execute step to start listening
- Note: If channel list doesn't load, use channel ID method
Adding Bot to Channel¶
- In Slack, go to the target channel
- Click channel name → Members
- Go to Integrations tab
- Click Add an App
- Select your bot app
Testing the Connection¶
- Execute the Slack trigger node (listening mode)
- In Slack, @mention the bot:
@n8n-demo-bot hello - Check n8n - trigger should capture the message
- Output includes: text, user ID, channel ID, timestamp
Building the AI Agent Response¶
Adding AI Agent Node¶
- Add AI Agent node after Slack trigger
- Connect text input from Slack to user prompt
- Add OpenAI Chat Model (e.g., GPT-4o Mini)
- Add Simple Memory for conversation context
- Session ID: Use channel ID for context per channel
Adding Slack Response Node¶
- Add Slack node (send message action)
- Configure:
- Credential: Same Slack credential
- Resource: Message
- Operation: Send
- Channel: By ID (paste or drag from trigger)
-
Message: Drag AI agent output
-
Under Options, disable "Include link to workflow"
Part 2: AI Agent Responding on Your Behalf¶
This advanced section creates an AI that impersonates you in Slack.
Additional OAuth Permissions¶
Add User Token Scopes (not bot scopes):
- channels:history - Read channel messages
- channels:read - Access channel info
- chat:write - Send as user
- groups:history - Read private channel history
- groups:read - Access private channels
- im:history - Read DM history
- im:read - Access DMs
- mpim:history - Read group DM history
- mpim:read - Access group DMs
Add to Bot Token Scopes:
- chat:write.customize - Send messages on behalf of users
Important: Reinstall app after adding new scopes.
Event Subscriptions for User Messages¶
Under Subscribe to events on behalf of users:
- message.channels - Channel messages
- message.groups - Private channel messages
- message.im - Direct messages
- message.mpim - Group DMs
Workflow Modifications¶
- Trigger updates:
- Add "Any Event" as trigger type
- Enable "Watch full workspace"
-
Add your user ID to "Username or ID to ignore" (prevents responding to yourself)
-
Get your user ID:
- In Slack, click your profile
-
Click three dots → Copy Member ID
-
AI Agent system prompt:
-
Slack send message updates:
- Channel ID: Dynamic (from trigger)
- Under Options: Add "Send as user" with your username
Part 3: Adding RAG Capabilities¶
To make responses more accurate, add document context:
Adding Google Doc Tool¶
- Add Google Doc tool to AI agent
- Configure:
- Operation: Get
- Document: Paste URL of your knowledge document
- Update system prompt:
Testing RAG Responses¶
When asked about projects: 1. AI accesses the Google Doc 2. Extracts relevant information 3. Responds with accurate, document-based answers
Use Cases Beyond Impersonation¶
This setup can be adapted for: - Technical support bots - FAQ automation - HR assistant bots - Legal document lookup - Marketing content retrieval - Customer support automation
Key Takeaways¶
-
Two credential types exist: Bot tokens for bot actions, User tokens for acting as a user.
-
Scope permissions are granular: Add only the scopes needed for your use case.
-
Event subscriptions require verification: n8n must be listening when configuring the request URL.
-
Bot must be added to channels: The bot won't receive events from channels it hasn't joined.
-
User ID filtering prevents loops: Ignore your own messages to avoid infinite response loops.
-
Dynamic channel ID is essential: For workspace-wide bots, channel ID must be dynamic.
-
System prompts define persona: Clear instructions help the AI maintain consistent character.
-
RAG enhances accuracy: Attaching document tools provides real, accurate information.
-
Reinstall after scope changes: New OAuth scopes require app reinstallation.
-
User token enables impersonation: Sending as user (not bot) makes messages appear from you.
Conclusion¶
Slack integration opens powerful automation possibilities, from simple notification bots to sophisticated AI agents that can handle conversations on your behalf. The dual-trigger architecture—one for initial setup and one for ongoing messages—demonstrates n8n's flexibility in handling complex event flows. Adding RAG capabilities transforms a simple chatbot into a knowledgeable assistant that can provide accurate, document-based responses. While the "AI impersonation" demo is presented for educational purposes, the same techniques enable practical business applications like customer support, internal helpdesks, and automated FAQ systems. Understanding Slack's permission model and event subscription system is essential for building reliable, production-ready integrations.