Slack Slash Command AI Chatbot with OpenAI - n8n Workflow

Use this powerful n8n workflow to create a dynamic AI chatbot directly inside Slack. It uses a Webhook n8n trigger to accept slash commands, processes queries via the OpenAI n8n node (gpt-4o-mini), and posts the response back instantly.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Team Leaders & Automation Engineers: Seeking to integrate AI capabilities directly into their daily Slack operations without requiring users to switch applications.
Developers: Looking for ready-made n8n templates for integrating messaging platforms (Slack) with Language Models (OpenAI).
n8n Users: Who want practical examples of how to use the Webhook n8n trigger, Switch n8n node, and Langchain/OpenAI integrations within a single n8n workflow.
Productivity Enthusiasts: Who need instant, context-aware answers accessible via a simple Slack slash command.

Overview

Integrating specialized AI tools into daily communication platforms significantly boosts productivity. This n8n workflow solves the challenge of delayed access to AI insights by turning a Slack slash command into a powerful n8n trigger. When a user types a command (like /ask) followed by a query, the Webhook n8n node instantly captures the request. The automation then routes the query through the robust OpenAI Chat Model n8n node, ensuring a high-quality response using models like gpt-4o-mini. This whole process is encapsulated in one efficient n8n automation, providing an excellent template for building custom internal tools.

How it Works

This n8n workflow operates through a sequence of critical steps, starting with a user-initiated action in Slack.


  1. Incoming Command: The process begins when a user executes a configured slash command (e.g., /ask) in Slack. This action sends an HTTP POST request to the unique URL provided by the Webhook n8n trigger node.

  2. Initial Acknowledgment: The Webhook n8n trigger immediately responds to Slack with a 204 (No Content) status code, preventing timeouts while the AI processing occurs.

  3. Command Routing: The request payload, containing the command (/ask or /another) and the query text, moves to the Switch n8n node. This n8n node is configured to check the body.command value and route the request to the correct branch.

  4. AI Processing: The workflow path for the /ask command leads to the Basic LLM Chain n8n node. This node ingests the user's text ($json.body.text) and is linked to the OpenAI Chat Model n8n node, configured to use gpt-4o-mini for fast and accurate generation.

  5. Delivering the Response: Once the Basic LLM Chain n8n node returns the AI-generated text, it is passed to the Slack 'Send a Message' n8n node. This final n8n node dynamically extracts the original channel_id from the initial Webhook data and posts the AI's answer directly back into the relevant Slack channel or private message where the slash command n8n trigger was initiated.

Installation Guide

To deploy this useful n8n workflow, follow these steps:


  1. Import: Copy the provided JSON data and paste it directly into your n8n instance using the 'New' -> 'Import from JSON' option.

  2. Slack App Setup (Prerequisite): Create a new Slack App. Configure a Slash Command within your app settings (e.g., /ask).

  3. Webhook Configuration: Open the Webhook n8n trigger node in the imported n8n workflow. Click 'Settings' and then 'Listen for Test Events' to generate the unique Request URL. Copy this URL.

  4. Link Slack Command: Paste the copied URL from the n8n trigger into the 'Request URL' field for your new Slash Command in the Slack App configuration.

  5. Credential Setup: Set up your credentials for the Slack n8n node and the OpenAI Chat Model n8n node (API Key). Ensure the Slack n8n node has the necessary scopes to post messages.

  6. Activate: Save the n8n workflow and set it to 'Active'. You can now test the n8n template by typing your slash command in any Slack channel.

Node Details

This n8n workflow leverages specialized nodes to manage the incoming Slack command and integrate the AI functionality:

Webhook (n8n trigger):
Function: Serves as the primary n8n trigger, listening for HTTP POST requests from the configured Slack Slash Command.
Key Configuration: Path is set to a unique ID. Crucially, the 'Response Code' is set to 204 (No Content) to instantly acknowledge receipt and prevent Slack from timing out while the AI processes.

Switch (n8n node):
Function: Routes the workflow based on which slash command was used. It inspects the expression ={{ $json.body.command }}.
Key Configuration: Defines outputs for /ask and /another commands, providing a branching mechanism for different AI functions within the same n8n workflow.

Basic LLM Chain (n8n node):
Function: Acts as the processing core, taking the user's input text (={{ $json.body.text }}) and managing the interaction with the connected language model.
Key Configuration: Input text dynamically derived from the payload. Uses a define prompt type.

OpenAI Chat Model (n8n node):
Function: Provides the intelligence for the n8n workflow, utilizing the OpenAI API to generate the response.
Key Configuration: Model set to gpt-4o-mini, balancing speed and capability for chat applications.

Slack (Send a Message) (n8n node):
Function: Posts the final AI response back to the user's channel.
* Key Configuration: The 'Channel ID' is dynamically set using an expression: ={{ $('Webhook').item.json.body.channel_id }}. This ensures the response is correctly targeted to the originating channel, completing the request handled by this efficient n8n template.

Related n8n Workflows

Free

Nodes: 6 Nodes
Updated: December 26 2025
View all
Created by

Featured*