Slack Socket Trigger

Triggers workflow when a Slack message matches a regex pattern via Socket Mode

Overview

This node triggers workflows in n8n when specific Slack events occur, using Slack's Socket Mode. It listens for various event types such as messages, mentions, new channels, new users, and reactions added. Additionally, it can filter incoming Slack messages by matching them against a user-defined regular expression pattern, allowing extraction of data via capture groups.

Common scenarios include:

  • Automating responses or actions when your Slack app is mentioned.
  • Monitoring new messages in channels your app is part of, optionally filtering messages with regex.
  • Triggering workflows on Slack workspace changes like new users joining or new public channels being created.
  • Reacting to emoji reactions added to messages.

Practical example:

  • Automatically create a task in a project management tool whenever a message containing a specific keyword or pattern is posted in Slack.
  • Send a welcome email when a new user joins the Slack workspace.
  • Log all reaction-added events for analytics purposes.

Properties

Name Meaning
Trigger On Select one or more Slack event types to listen for:
- Any Event
- Bot / App Mention
- New Message Posted to Channel
- New Public Channel Created
- New User
- Reaction Added
Regex Pattern A regular expression pattern to match against incoming Slack messages. Capture groups can be used to extract data from matched messages. Leave empty to disable regex filtering.
Regex Flags Flags for the regular expression, e.g., g for global matching, i for case-insensitive matching, m for multiline.

Output

The node outputs JSON objects representing the Slack event data that triggered the workflow. Each output item contains:

  • body: The full raw request body received from Slack.
  • payload: The payload object from the Slack event.
  • context: Contextual information provided by the Slack SDK.
  • event: The specific Slack event data (e.g., message details, user info).

If a regex pattern is specified and matches a message event, the matched data can be extracted from the event content.

No binary data output is produced by this node.

Dependencies

  • Requires a Slack app configured with Socket Mode enabled.
  • Needs an API authentication token with appropriate permissions (bot token, signing secret, and app-level token).
  • The node depends on the official Slack Bolt SDK for Node.js to handle Socket Mode connections and event listening.
  • In n8n, the user must provide credentials containing the necessary Slack tokens and secrets.

Troubleshooting

  • No events triggering: Ensure the Slack app is installed in the workspace and has the required event subscriptions enabled. Verify that the app token and bot token are correct and have the necessary scopes.
  • Regex not matching: Double-check the regex pattern and flags for correctness. Remember that regex is only applied to message events.
  • Errors starting the app: Check network connectivity and validity of Slack credentials. Review logs for errors related to token authentication or socket connection issues.
  • Workflow not triggering on expected events: Confirm that the selected "Trigger On" options include the event type you expect. Some events require additional Slack app permissions.

Links and References

Discussion