Skip to content

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

  1. Navigate to api.slack.com
  2. Sign in to your Slack workspace
  3. Go to Your Apps section
  4. Click Create New App
  5. Choose From scratch
  6. Enter app name (e.g., "n8n Demo Bot")
  7. Select your workspace
  8. Click Create App

Configuring Bot Permissions

Navigate to OAuth & Permissions:

  1. Scroll to Bot Token Scopes
  2. Click Add an OAuth Scope
  3. Add required scopes:
  4. app_mentions:read - Read messages mentioning the bot
  5. chat:write - Send messages as the bot
  6. channels:read - Access channel information
  7. groups:read - Access private channel info
  8. users.profile:read - Read user profiles
  9. users:read - Access user information

Installing the App

  1. Scroll to top of OAuth & Permissions page
  2. Click Install to Workspace
  3. Review permissions
  4. Click Allow
  5. Copy the Bot User OAuth Token (starts with xoxb-)

Configuring Event Subscriptions

  1. Go to Event Subscriptions in sidebar
  2. Toggle Enable Events to ON
  3. For Request URL:
  4. Go to n8n workflow
  5. Add Slack trigger node
  6. Copy the Test URL from webhook URLs
  7. Paste into Slack Request URL field
  8. Wait for verification (run trigger node first)
  9. Add Subscribe to Bot Events:
  10. app_mention - Triggers when bot is @mentioned

  11. Click Save Changes

Connecting Slack to n8n

Creating Slack Credentials

  1. In n8n, add Slack Trigger node (not regular Slack node)
  2. Select On bot/app mention event
  3. Create new credential:
  4. Name: "Slack n8n Demo"
  5. Paste Bot User OAuth Token
  6. Click Save
  7. See "Connection tested successfully"

Configuring the Trigger

  1. Select channel to watch (from list, by ID, or by URL)
  2. Execute step to start listening
  3. Note: If channel list doesn't load, use channel ID method

Adding Bot to Channel

  1. In Slack, go to the target channel
  2. Click channel name → Members
  3. Go to Integrations tab
  4. Click Add an App
  5. Select your bot app

Testing the Connection

  1. Execute the Slack trigger node (listening mode)
  2. In Slack, @mention the bot: @n8n-demo-bot hello
  3. Check n8n - trigger should capture the message
  4. Output includes: text, user ID, channel ID, timestamp

Building the AI Agent Response

Adding AI Agent Node

  1. Add AI Agent node after Slack trigger
  2. Connect text input from Slack to user prompt
  3. Add OpenAI Chat Model (e.g., GPT-4o Mini)
  4. Add Simple Memory for conversation context
  5. Session ID: Use channel ID for context per channel

Adding Slack Response Node

  1. Add Slack node (send message action)
  2. Configure:
  3. Credential: Same Slack credential
  4. Resource: Message
  5. Operation: Send
  6. Channel: By ID (paste or drag from trigger)
  7. Message: Drag AI agent output

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

  1. Trigger updates:
  2. Add "Any Event" as trigger type
  3. Enable "Watch full workspace"
  4. Add your user ID to "Username or ID to ignore" (prevents responding to yourself)

  5. Get your user ID:

  6. In Slack, click your profile
  7. Click three dots → Copy Member ID

  8. AI Agent system prompt:

    You are Marconi, a team member at CodeCloud. Your job is to impersonate Marconi as well as you can and respond to his team member's message on his behalf. Sound friendly and natural in a typical tech working environment.
    

  9. Slack send message updates:

  10. Channel ID: Dynamic (from trigger)
  11. 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

  1. Add Google Doc tool to AI agent
  2. Configure:
  3. Operation: Get
  4. Document: Paste URL of your knowledge document
  5. Update system prompt:
    Use the Google Doc tool when asked about project updates.
    

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

  1. Two credential types exist: Bot tokens for bot actions, User tokens for acting as a user.

  2. Scope permissions are granular: Add only the scopes needed for your use case.

  3. Event subscriptions require verification: n8n must be listening when configuring the request URL.

  4. Bot must be added to channels: The bot won't receive events from channels it hasn't joined.

  5. User ID filtering prevents loops: Ignore your own messages to avoid infinite response loops.

  6. Dynamic channel ID is essential: For workspace-wide bots, channel ID must be dynamic.

  7. System prompts define persona: Clear instructions help the AI maintain consistent character.

  8. RAG enhances accuracy: Attaching document tools provides real, accurate information.

  9. Reinstall after scope changes: New OAuth scopes require app reinstallation.

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