IntegrationsIntermediate

How to Build a Slack Slash Command AI Bot with an n8n Webhook

Wire a Slack slash command to an n8n webhook, run the text through a model, and post the answer back in channel.

11 minIntermediate

A Slack slash command sends a webhook to any URL you choose. Point it at n8n, run the typed text through a model, and your team gets an AI assistant inside Slack with no extra app to install. This guide builds a /ask command end to end.

What you need

  • A Slack workspace where you can create an app
  • An n8n instance reachable over HTTPS
  • A chat model credential in n8n

Step 1: Create the n8n webhook

Add a Webhook node with POST and path slack-ask. Slack sends slash command data as form-encoded fields, so the typed text lands in body.text and the response URL in body.response_url.

n8n - webhook for Slack
Node: Webhook
Method: POST Path: slack-ask
Incoming fields:
body.text -> the user's question
body.response_url -> where to post the answer
body.user_name -> who asked
Slack posts application/x-www-form-urlencoded fields to this path.

Step 2: Acknowledge within 3 seconds

Slack requires a reply within three seconds or it shows a timeout error. Add a Respond to Webhook node right away that returns a short acknowledgement, then do the AI work afterward and post the real answer to response_url.

Respond to Webhook - quick ack
{
  "response_type": "ephemeral",
  "text": "Thinking..."
}

Step 3: Run the model and post back

Connect the webhook to an AI Agent node fed by body.text. Then add an HTTP Request node that POSTs the result to the captured response_url.

HTTP Request to response_url - body
{
  "response_type": "in_channel",
  "text": "{{ $json.output }}"
}
in_channel vs ephemeral
Set response_type to in_channel so everyone sees the answer, or ephemeral if only the person who ran the command should see it.

Step 4: Register the slash command in Slack

In your Slack app at api.slack.com, open Slash Commands, add /ask, and set the Request URL to your production webhook https://your-n8n.example.com/webhook/slack-ask. Install the app to the workspace.

slack - in a channel
$/ask what is HMAC in plain english?
Thinking...
HMAC is a way to prove a message came from someone who knows a shared secret, using a hash.
$

Result: anyone in the workspace can type /ask followed by a question and get an AI answer posted right in the channel.

Watch related tutorials

Tags
#n8n#slack#webhooks#ai-agent