Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

How to Build a Slack Bot with n8n

· 5 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

This guide walks you through creating a Slack bot that can respond to messages, post updates, and trigger workflows automatically—all using n8n, a workflow automation tool. You'll learn how to set up the Slack app, connect it to n8n, and build a simple bot that replies to commands. No coding required, but basic familiarity with n8n's interface helps.

What You'll Need

  • An n8n instance (cloud or self-hosted) with admin access.
  • A Slack workspace where you can create apps (admin or member with app creation permissions).
  • Basic understanding of n8n workflows (nodes, triggers, and webhooks).

Step-by-Step

  1. Create a Slack App Go to api.slack.com/apps and click Create New App. Choose From scratch, give it a name (e.g., "My n8n Bot"), and select your workspace. Click Create App.
  2. Set Up Bot Permissions In the left sidebar, go to OAuth & Permissions. Scroll to Scopes and click Add an OAuth Scope. Add at least: chat:write (post messages), app_mentions:read (read mentions), and reactions:write (optional, for reactions). Also add commands if you plan to use slash commands.
  3. Install the App to Your Workspace Under OAuth & Permissions, click Install to Workspace. Review the permissions and click Allow. Copy the Bot User OAuth Token (starts with xoxb-)—you'll need it later.
  4. Enable Event Subscriptions Go to Event Subscriptions and toggle Enable Events to ON. Set the Request URL to your n8n webhook URL (you'll create this in n8n in the next step). Initially, Slack will fail to verify the URL until you set up the n8n webhook—that's okay.
  5. Subscribe to Bot Events Under Subscribe to bot events, click Add Bot User Event and add app_mention. This allows the bot to respond when mentioned. You can also add message.channels for listening to all messages in channels (use with caution).
  6. Create an n8n Workflow Log into n8n and create a new workflow. Add a Webhook node as the trigger. Set the HTTP Method to POST and copy the webhook URL (it looks like https://your-n8n.com/webhook/random-id).
  7. Connect Slack to n8n Go back to Slack's Event Subscriptions page and paste the webhook URL into the Request URL field. Slack will send a URL verification challenge. In n8n, add a Respond to Webhook node that returns the challenge parameter—or better, use the Webhook node's auto-response feature. Once verified, save the Slack app.
  8. Add Slack Credentials in n8n In n8n, go to Credentials and add a new Slack credential. Paste the Bot User OAuth Token from step 3. Name it something like "My Slack Bot".
  9. Build the Bot Logic After the Webhook node, add a Switch node to check if the event is an app_mention . Use the expression and check for app_mention . Then add a Slack node (action: Post message ). Configure it to use your Slack credential, set the channel to the one from the event ( ), and set the message text to something like "Hello!
  10. Handle Slash Commands (Optional) If you want a slash command like /hello, go to Slack's Slash Commands page, create a new command, and set the Request URL to the same webhook. In n8n, add another Switch branch checking for url_verification and command payloads.
  11. Test Your Bot Activate the workflow in n8n (toggle the switch). In Slack, invite the bot to a channel and mention it (e.g., @my-bot hello). You should see a reply. If not, check the n8n execution log for errors.
  12. Deploy and Monitor Once working, keep the workflow active. You can add error handling with an Error Trigger to notify you if something fails.

Common Mistakes

  • Wrong OAuth token—using the app token instead of the bot token. Always use the token starting with xoxb-.
  • Not enabling events—forgetting to subscribe to app_mention means the bot won't receive mentions.
  • Webhook URL not public—if your n8n instance is behind a firewall or localhost, Slack can't reach it. Use a public URL or a tunneling service like ngrok for testing.
  • Ignoring the URL verification—Slack sends a challenge token; if your webhook doesn't respond correctly, the URL won't be saved.
  • Not parsing the event payload —the event data is nested under event ; always use , not .

Tips

  • Use n8n's IF node instead of Switch for simple conditions—it's easier to read.
  • Store your Slack token in n8n credentials, not as a plain text node.
  • Test with a private channel first to avoid spamming your team.
  • Add a Rate Limit node if you expect high traffic to avoid hitting Slack's API limits.
  • Use the Code node for complex message formatting (e.g., Block Kit).

Troubleshooting

  • Slack shows "URL verification failed"—Make sure your webhook node is active and set to respond with the challenge parameter. In n8n, you can add a Set node to return { challenge: $json.challenge } and then a Respond to Webhook node.
  • Bot doesn't reply to mentions—Check that the bot is in the channel (invite it) and that the event subscription is enabled. Also verify the n8n workflow is active.
  • Error "invalid_auth"—Your token is wrong or revoked. Regenerate the token in Slack and update the n8n credential.
  • Messages appear but not from the bot—Make sure you're using the Post message action, not Post ephemeral (which only shows to one user).
  • Webhook receives requests but n8n doesn't process—Check the execution log for errors. The webhook node might be missing a response, causing Slack to retry.

Frequently Asked Questions

Do I need a paid Slack plan?

No, you can build a bot on the free plan. However, some features like custom slash commands are available on all plans.

Can I use n8n's built-in Slack nodes instead of webhooks?

Yes, n8n has Slack trigger nodes (e.g., Slack Trigger) that handle the webhook setup for you, but they require a public endpoint and may be simpler for beginners.

How do I make the bot respond to any message, not just mentions?

Subscribe to message.channels in Slack and filter in n8n for the desired channel or user. Be careful about privacy and spam.

Can I deploy this to a serverless platform?

n8n can be self-hosted on a VPS, or you can use n8n Cloud. For serverless, you'd need to run n8n in a container on AWS Lambda or similar, which is advanced.

What if I want to send messages proactively (not just replies)?

Use the Slack node with the Post message action in a workflow triggered by a schedule or another event. You'll need the channel ID.

Is it possible to use Block Kit for rich messages?

Yes, in the Slack node's message field, you can use JSON for blocks. Alternatively, use a Code node to build the blocks and pass them to the Slack node.