n8n

How to Route Slack Slash Commands for AI Answers?

Get fast AI answers inside Slack with a simple slash command. Team members type a command and receive a clear reply posted to the same channel. It is great for quick Q and A, draft messages, and short summaries without leaving chat.

When someone triggers a slash command, Slack sends the text to an n8n webhook. The webhook confirms the request with a 204 response so Slack does not wait. A Switch node routes each command, so you can support different actions. The Basic LLM Chain passes the message text to the OpenAI Chat Model and returns a clean answer. The Slack node then posts that answer back into the original channel using the channel id from the request. You can add more branches to handle extra commands like summarize or translate.

To set this up, you need a Slack app with a slash command and an OpenAI API key. Connect Slack and OpenAI in n8n, map the channel field, and keep the default 204 reply in the webhook. Expect faster replies in channels, fewer context switches, and less copy and paste. This fits internal help desks, on call handoffs, and marketing content drafts.

What are the key features?

  • Webhook trigger receives slash command requests and sends a 204 response to prevent Slack timeouts.
  • Switch routing separates commands so you can support different actions like ask or summarize.
  • Basic LLM Chain sends the command text to the OpenAI Chat Model and produces a clear reply.
  • Slack Send a Message posts the AI result back to the original channel using the channel id from the request.
  • Model set to gpt 4o mini for fast and low cost responses that still read well.
  • Canvas notes guide the setup steps so configuration is easy to follow.

What are the benefits?

  • Reduce manual work from 10 minutes to 30 seconds per answer
  • Automate up to 80 percent of simple Q and A in team channels
  • Handle 5 times more requests during busy hours without extra staff
  • Connect Slack and OpenAI so people never leave chat
  • Cut context switching and improve focus for the whole team

How do you set it up?

  1. Import the template into n8n: Create a new workflow in n8n > Click the three dots menu > Select 'Import from File' > Choose the downloaded JSON file.
  2. You'll need accounts with Slack and OpenAI. See the Tools Required section above for links to create accounts with these services.
  3. In your Slack API dashboard, create a new app. Add a Slash Commands feature. Set the Request URL to the public URL from the n8n Webhook node. Pick a command name such as /ask and save.
  4. In Slack app settings, add the chat:write scope for the bot. Install the app to your workspace and confirm the bot is in the target channel.
  5. In n8n, double click the Slack Send a Message node. In the 'Credential to connect with' dropdown, click 'Create new credential' and follow the on screen steps to connect your Slack account.
  6. Open the OpenAI Chat Model node. In the credential dropdown, click 'Create new credential'. Go to the OpenAI API page, create an API key, and paste it into n8n. Name the credential clearly.
  7. Verify the Webhook node method is POST and keep the response code at 204 so Slack gets an instant acknowledgement.
  8. Open the Switch node and add a rule for your command keyword such as ask. You can add more rules for other commands later.
  9. Open the Basic LLM Chain node and confirm the Text field maps to {{$json.body.text}} so the AI reads the user input. Adjust the prompt if you want a certain tone or format.
  10. In the Slack node, set the Channel to use the expression for the incoming channel id from the webhook. Keep the message text set to the AI output variable.
  11. Test in Slack by typing your slash command with a question. Check n8n execution logs if nothing posts. If Slack reports a timeout, make sure your n8n URL is public and that the webhook returns 204 quickly. If the AI call fails, verify your OpenAI key and model name.

Tools Required

$24 / mo or $20 / mo billed annually to use n8n in the cloud. However, the local or self-hosted n8n Community Edition is free.

OpenAI

Sign up

Pay-as-you-go: GPT-5 at $1.25 per 1M input tokens and $10 per 1M output tokens

Slack

Sign up

Free plan: $0 / mo; limited to 10 apps (third-party or custom) and usable via Slack API

Credits:
YouTube video

Similar Templates

Join Futurise to access 1,200+ automation templates

Get instant access to ready-made automation workflows for n8n, Make.com, AI agents, and more. Download, customise, and deploy in minutes.