Slack

Send your event data from RudderStack to Slack.

Slack is a popular business communication platform that lets you organize all your business-related chats by specific topics, groups, or direct messaging.

Find the open source transformer code for this destination in the GitHub repository.

Getting started

RudderStack supports sending event data to Slack via the following connection modes:

Connection ModeWebMobileServer
Device mode---
Cloud modeSupportedSupportedSupported

Once you have confirmed that the source platform supports sending events to Slack, follow these steps:

  1. From your RudderStack dashboard, add a source. Then, from the list of destinations, select Slack.
  2. Assign a name to the destination and click Continue.

Connection settings

Use the following settings to send an event to a particular Slack channel:

  • Type of incoming webhooks: Select the API from the dropdown that RudderStack uses to send data to the particular Slack channel.

    • Legacy: RudderStack maps the channel based on the Event Channel Name setting. Note that this method may be deprecated soon.
    • Modern: RudderStack maps the channel based on the Event Channel Webhook setting.
  • Event Name: Enter the event name or the regex to match the RudderStack event name.

  • Event Channel Webhook: Enter the webhook URL of the Slack channel where RudderStack sends the above event.

warning

To get the URL for Event Channel Webhook setting, make sure you have:

  1. Created a Slack app with Incoming Webhooks feature enabled.
  2. Authorized the app to post to your specified Slack channel.

See Sending messages using Incoming Webhooks for more information.

  • Event Channel Name: Enter the Slack channel’s name where RudderStack should send the above event using the legacy method. You can specify #channel_name or @user_name. If not specified, RudderStack sends the events to the Slack channel associated with the incoming webhook URL (Webhook URL setting below).
  • Regex Matching: Enable this setting if the event name in the first parameter is a regular expression.
info
RudderStack adds the global g parameter implicitly. Hence, you need not add it with the regex.

Identify Template: Specify the template used to transform the identify event before sending it to Slack. RudderStack uses the following default template:

Identified {{name}} <traits_key1>:<traits_value1> <traits_key2>:<traits_value2> ....

Here, the traits key and value are the key-value pairs in the traits object of the identify event payload.

The name field in the template is determined from either of the following:

  • traits.name
  • traits.firstName + traits.lastName
  • traits.username
  • properties.email
  • traits.email
  • User userId
  • Anonymous user anonymousId
warning
Only the traits listed in the Allowlisted Traits setting are considered to be a part of the identify template. The rest are not sent to Slack.

Use the following settings to transform an event before sending it to Slack:

  • Event Name: Enter the event name or the regex to match the RudderStack event name.
  • Event Template: Specify the template used to transform the above event. RudderStack uses the following default template. Note that RudderStack determines name similar to the Identify Template setting described above.
{{name}} did {{event}}
  • Regex Matching: Enable this setting if the event name is a regex in the first parameter.
  • Webhook URL: Enter your Slack’s incoming webhook URL. For more information on obtaining this URL, refer to the FAQ section below.
info
By default, RudderStack sends all the events to the channel associated with the incoming webhook URL.
  • Allowlisted Traits: Specify the user traits to be allowlisted. If not specified, RudderStack sends all the user traits to Slack.
  • Denylisted Events: Enter the events to add to your denylist. RudderStack will drop these events.
  • OneTrust cookie categories: Use this setting to associate OneTrust cookie consent groups to Slack.

Handlebar expressions

RudderStack supports Handlebar expression by leveraging the handlebars.js library for including the variables into your dynamic Slack messages.

Accessible Variables

The following table lists the variables you can select in your template messages:

Handlebar expressionOutput
{{name}}Identity name of the user in the priority order listed above.
{{event}}Event name, for example, Product Viewed or user login.
{{key_1}}
{{properties.key_1}}
The property values from the event’s properties object.
{{propertiesList}}JSON stringified version of your properties object.
{{traits}}JSON stringified version of your traits object.
{{traitsList.key_1}}The trait values from the event’s traits object.

Escaped content

The values returned by {{variable}} are HTML-escaped. For example, if a variable has a & in its value then it will be returned as &amp;. To avoid this behavior, you can use the triple curly braces instead of double, like {{{variable}}} instead of {{variable}}. This will stop the handlebars from escaping a value if there is one, as shown in the following example:

ExpressionVariableResult
{{variable}}"Marcia & Jan""Marcia &amp; Jan"
{{{variable}}}"Marcia & Jan""Marcia & Jan"

For more information on the escaped content, refer to the Handlebar guide.

Identify

The identify call lets you identify a visiting user and associate them to their actions. It also lets you record the traits about them like their name, email address, etc.

A sample identify call for a template, like Identified {{name}} with {{traits}}, is shown below:

rudderanalytics.identify("1hKOmRA4el9Zt1WSfVJIVo4GRlm", {
  name: "Alex Keener",
  email: "alex@example.com",
  country: "USA",
});

For the above event, you will see the message Identified Alex Keener with name: Alex Keener email: alex@example.com country: USA in your configured Slack channel.

Track

The track call lets you record the user events, that is, the actions your users perform, along with any properties associated with these actions.

A sample track call for a template {{name}} performed {{event}} with {{properties.key1}} {{properties.key2}} after the user is identified is as follows:

rudderanalytics.track("test_event", {
  "key1": "test_val1",
  "key2": "test_val2",
  "key3": "test_val3"
})

For the above snippet, you will see the message Alex Keener performed test_event with test_val1 test_val2 test_val3 in your configured Slack channel.

FAQ

How do I obtain the incoming webhook URL?

To obtain the webhook URL, follow the below steps:

  1. Click your Slack workspace name, then go to Administration > Manage Apps.
  2. Search for Incoming webhooks in the Slack app directory and add it to Slack by clicking on Add to Slack.
  3. Select a channel where you want to post the messages forwarded by the webhook and click Add Incoming webhooks integration.
Slack connection settings
  1. Finally, copy the webhook URL and enter it in the RudderStack dashboard.
Slack connection settings

Why am I getting Slack messages for all the incoming events in one channel?

By default, RudderStack sends all the events to the Slack channel associated with the incoming webhook URL (Webhook URL setting in the RudderStack dashboard).

To get specific events in a particular channel, make sure you specify the mappings using the Event Name and Event Channel settings.


Questions? Contact us by email or on Slack