Event triggers

Invoke a workflow when a specific event happens in Slack

Event triggers are a type of automatic trigger, as they don't require manual activation. Instead, they're automatically invoked when a certain event happens.

Supported events

Your app needs to have the proper scopes to use event triggers. Include these scopes within your app's manifest. Your app also needs to be a member of any channel where you want to listen for events.

Supported event How to reference Description Required scopes
app_mentioned TriggerEventTypes.AppMentioned Subscribe to only the message events that mention your app or bot app_mentions:read
channel_archived TriggerEventTypes.ChannelArchived A channel was archived channels:read
channel_created TriggerEventTypes.ChannelCreated A channel was created channels:read
channel_deleted TriggerEventTypes.ChannelDeleted A channel was deleted channels:read
channel_renamed TriggerEventTypes.ChannelRenamed A channel was renamed channels:read
channel_shared TriggerEventTypes.ChannelShared A channel has been shared with an external workspace channels:read groups:read
channel_unarchived TriggerEventTypes.ChannelUnarchived A channel was unarchived channels:read
channel_unshared TriggerEventTypes.ChannelUnshared A channel has been unshared with an external workspace channels:read groups:read
dnd_updated TriggerEventTypes.DndUpdated Do not Disturb settings changed for a member dnd:read
emoji_changed TriggerEventTypes.EmojiChanged A custom emoji has been added or changed emoji:read
message_posted TriggerEventTypes.MessagePosted A message was sent to a channel. Note: a filter is required to listen for this event. channels:history groups:history im:read mpim:read
message_metadata_posted TriggerEventTypes.MessageMetadataPosted Message metadata was posted metadata.message:read
pin_added TriggerEventTypes.PinAdded A pin was added to a channel pins:read
pin_removed TriggerEventTypes.PinRemoved A pin was removed from a channel pins:read
reaction_added TriggerEventTypes.ReactionAdded A member has added an emoji reaction to an item reactions:read
reaction_removed TriggerEventTypes.ReactionRemoved A member removed an emoji reaction reactions:read
shared_channel_invite_accepted TriggerEventTypes.SharedChannelInviteAccepted A shared channel invite was accepted conversations.connect:manage
shared_channel_invite_approved TriggerEventTypes.SharedChannelInviteApproved A shared channel invite was approved conversations.connect:manage
shared_channel_invite_declined TriggerEventTypes.SharedChannelInviteDeclined A shared channel invite was declined conversations.connect:manage
shared_channel_invite_received TriggerEventTypes.SharedChannelInviteReceived A shared channel invite was sent to a Slack user conversations.connect:read
user_joined_channel TriggerEventTypes.UserJoinedChannel A user joined a public or private channel channels:read groups:read
user_joined_team TriggerEventTypes.UserJoinedTeam A new member has joined users:read
user_left_channel TriggerEventTypes.UserLeftChannel A user left a public or private channel channels:read groups:read
We'll continue to add more triggerable events in the future. Stay tuned!

Events can activate multiple triggers

When an event happens, all event triggers listening for that event will be invoked at roughly the same time. If you want to control which workflow runs first, you have two options:

  • Combine the functions of both workflows into a single workflow, invoked with a single event trigger
  • Have the second workflow be invoked by the first workflow, instead of the original event trigger

Avoid infinite loops

Your app can respond to events and be the cause of events. This can create situations where your app gets stuck in a loop.

For example, if your app listens for all message_posted events in a channel and then posts its own message in response, it'll keep posting messages forever! That's why the message_posted event requires a filter.

Carefully construct a filter to prevent boundless behavior. If your app does get stuck in an infinite loop, you can delete the trigger and the behavior will cease.

Create an event trigger

Triggers can be added to workflows in two ways:

  • You can add triggers with the CLI. These static triggers are created only once. You create them with the Slack CLI, attach them to your app's workflow, and that's that. The trigger is defined within a trigger file.

  • You can add triggers at runtime. These dynamic triggers are created at any step of a workflow so they can incorporate data acquired from other workflow steps. The trigger is defined within a function file.

Slack CLI built-in documentation
Use slack trigger --help to easily access information on the trigger command's flags and subcommands.

The triggers you create when running locally (with the slack run command) will not work when you deploy your app in production (with the slack deploy command). You'll need to create any triggers again with the CLI.

Create the trigger file

To create an event trigger with the CLI, you'll need to create a trigger file. The trigger file contains the payload you used to define your trigger.

Create a TypeScript trigger file within your app's folder with the following form:

import { Trigger } from "deno-slack-api/types.ts";
import { TriggerEventTypes, TriggerTypes, TriggerContextData } from "deno-slack-api/mod.ts";

const trigger: Trigger<typeof ExampleWorkflow.definition> = {
  // your TypeScript payload
};

export default trigger;

Your TypeScript payload consists of the parameters needed for your own use case. The following is a trigger file with a payload creating an event trigger that listens for a reaction_added event in a specific channel:

import { Trigger } from "deno-slack-api/types.ts";
import { TriggerEventTypes, TriggerTypes, TriggerContextData } from "deno-slack-api/mod.ts";

const trigger: Trigger<typeof ExampleWorkflow.definition> = {
  type: TriggerTypes.Event,
  name: "Reactji response",
  description: "responds to a specific reactji",
  workflow: "#/workflows/myWorkflow",
  event: {
    event_type: TriggerEventTypes.ReactionAdded,
    channel_ids: ["C123ABC456"],
    filter: {
      version: 1,
      root: {
        statement: "{{data.reaction}} == sunglasses"
      }
    }
  },
  inputs: {
    stringtoSend: {
      value: "how cool is that",
    },
    channel: {
      value: "C123ABC456",
    },
  },
};

export default trigger;

Use the trigger create command

Once you have created a trigger file, use the following command to create the event trigger:

slack trigger create --trigger-def "path/to/trigger.ts"

If you have not used slack triggers create to create a trigger prior to running slack run, you will receive a prompt in the CLI to do so.

Your app needs to have the triggers:write scope to use a trigger at runtime. Include the scope within your app's manifest.

The logic of a runtime trigger lies within a function's TypeScript code. Within your functions folder, you'll have the functions that are the steps making up your workflow. Within this folder is where you can create a trigger within the relevant <function>.ts file.

When you create a runtime trigger, you can leverage inputs acquired from functions within the workflow. Provide the workflow definition to get additional typing for the workflow and inputs fields.

Create an event trigger at runtime using the client.workflows.triggers.create method within the relevant function file.

const triggerResponse = await client.workflows.triggers.create<typeof ExampleWorkflow.definition>({
  // your TypeScript payload
});

Your TypeScript payload consists of the parameters needed for your own use case. Below is a function file with an example TypeScript payload for an event trigger. This specific TypeScript payload is for creating an event trigger that listens for a reaction_added event in a specific channel:

// functions/example_function.ts
import { DefineFunction, Schema, SlackFunction } from "deno-slack-sdk/mod.ts";
import { ExampleWorkflow } from "../workflows/example_workflow.ts";
import { TriggerEventTypes, TriggerTypes } from "deno-slack-api/mod.ts";

export const ExampleFunctionDefinition = DefineFunction({
  callback_id: "example_function_def",
  title: "Example function",
  source_file: "functions/example_function.ts",
});

export default SlackFunction(
  ExampleFunctionDefinition,
  ({ inputs, client }) => {

  const triggerResponse = await client.workflows.triggers.create<typeof ExampleWorkflow.definition>({
    type: TriggerTypes.Event,
    name: "Reactji response",
    description: "responds to a specific reactji",
    workflow: `#/workflows/${ExampleWorkflow.definition.callback_id}`,
    event: {
      event_type: TriggerEventTypes.ReactionAdded,
      channel_ids: ["C123ABC456"],
      filter: {
        version: 1,
        root: {
          statement: "{{data.reaction}} == sunglasses"
        }
      }
    },
    inputs: {
      stringtoSend: {
        value: "how cool is that",
      },
      channel: {
        value: "C123ABC456",
      },
    }
  });

  // ...

Event trigger parameters

Field Description
type The type of trigger: TriggerTypes.Event
name The name of the trigger
workflow Path to workflow that the trigger initiates
description (Optional) The description of the trigger
inputs (Optional) The inputs provided to the workflow. Can use with the event response object
event (Optional) Contains the event object

Interactivity, and thus the interactivity parameter, is not supported with event triggers. Use a link trigger to take advantage of interactivity.

The Event object

Field Description
event_type The type of event; use one of the properties of TriggerEventTypes
channel_ids An array of event-related channel ID strings
filter (Optional) See trigger filters
team_ids (Required for Enterprise Grid) An array of event-related team ID strings

The event response object

An event's response object will contain additional information about that specific event instance.

Property Description
team_id A unique identifier for the workspace/team where this event occurred.
enterprise_id A unique identifier for the enterprise where this event occurred.
event_id A unique identifier for this specific event, globally unique across all workspaces.
event_timestamp A Unix timestamp in seconds indicating when this event was dispatched.
type An identifier showing the event type
data Contains additional information dependent on event type. See below.

Each type of event has unique sub-properties within the data property. You can pass these values on to your workflows. See the example below the event types.

Event types
{
  "team_id": "T0123ABC",
  "enterprise_id": "E0123ABC",
  "event_id": "Ev0123ABC",
  "event_timestamp": 1643810217.088700,
  "type": "event",
  "data": {
    "app_id": "A1234ABC",
    "channel_id": "C0123ABC",
    "channel_name": "cool-channel",
    "channel_type": "public/private/im/mpim",
    "event_type": "slack#/events/app_mentioned",
    "message_ts": "164432432542.2353",
    "text": "<@U0LAN0Z89> is it everything a river should be?",
    "user_id:": "U0123ABC",
  }
}
{
  "team_id": "T0123ABC",
  "enterprise_id": "E0123ABC",
  "event_id": "Ev0123ABC",
  "event_timestamp": 1630623713,
  "type": "event",
  "data": {
    "channel_id": "C0123ABC",
    "channel_name": "cool-channel",
    "channel_type": "public/private/im/mpim",
    "event_type": "slack#/events/channel_archived",
    "user_id": "U0123ABC",
  }
}
{
  "team_id": "T0123ABC",
  "enterprise_id": "E0123ABC",
  "event_id": "Ev0123ABC",
  "event_timestamp": 1630623713,
  "type": "event",
  "data": {
    "channel_id": "C0123ABC",
    "channel_name": "fun",
    "channel_type": "public",
    "created": 1360782804,
    "creator_id": "U0123ABC",
    "event_type": "slack#/events/channel_created",
  }
}
{
  "team_id": "T0123ABC",
  "enterprise_id": "E0123ABC",
  "event_id": "Ev0123ABC",
  "event_timestamp": 1643810217.088700,
  "type": "event",
  "data": {
    "channel_id": "C0123ABC",
    "channel_name": "project_planning",
    "channel_type": "public/private/im/mpim",
    "event_type": "slack#/events/channel_deleted",
    "user_id": "U0123ABC",
  }
}
{
  "team_id": "T0123ABC",
  "enterprise_id": "E0123ABC",
  "event_id": "Ev0123ABC",
  "event_timestamp": 1643810217.088700,
  "type": "event",
  "data": {
    "channel_id": "C0123ABC",
    "channel_name": "project_planning",
    "channel_type": "public/private/im/mpim",
    "event_type": "slack#/events/channel_renamed",
    "user_id": "U0123ABC",
  }
}
{
  "team_id": "T0123ABC",
  "enterprise_id": "E0123ABC",
  "event_id": "Ev0123ABC",
  "event_timestamp": 1643810217.088700,
  "type": "event",
  "data": {
    "channel_id": "C0123ABC",
    "channel_name": "cool-channel",
    "channel_type": "public/private/im/mpim",
    "connected_team_id": "E0123ABC",
    "event_type": "slack#/events/channel_shared",
  }
}
{
  "team_id": "T0123ABC",
  "enterprise_id": "E0123ABC",
  "event_id": "Ev0123ABC",
  "event_timestamp": 1643810217.088700,
  "type": "event",
  "data": {
    "channel_id": "C0123ABC",
    "channel_name": "cool-channel",
    "channel_type": "public/private/im/mpim",
    "event_type": "slack#/events/channel_unarchived",
    "user_id": "U0123ABC",
  }
}
{
  "team_id": "T0123ABC",
  "enterprise_id": "E0123ABC",
  "event_id": "Ev0123ABC",
  "event_timestamp": 1643810217.088700,
  "type": "event",
  "data": {
    "channel_id": "C0123ABC",
    "channel_name": "cool-channel",
    "channel_type": "public/private/im/mpim",
    "disconnected_team_id": "E0123ABC",
    "event_type": "slack#/events/channel_unshared",
    "is_ext_shared": false,
  }
}
{
  "team_id": "T0123ABC",
  "enterprise_id": "E0123ABC",
  "event_id": "Ev0123ABC",
  "event_timestamp": 1630623713,
  "type": "event",
  "data": {
    "dnd_status": {
      "dnd_enabled": true,
    },
    "event_type": "slack#/events/user_updated_dnd",
    "user_id": "U0123ABC",
  }
}
Emoji added
{
  "team_id": "T0123ABC",
  "enterprise_id": "E0123ABC",
  "event_id": "Ev0123ABC",
  "event_timestamp": 1630623713,
  "type": "event",
  "data": {
    "event_type": "slack#/events/emoji_changed",
    "name": "picard_facepalm",
    "subtype": "add",
    "value": "https://my.slack.com/emoji/picard_facepalm/abc123.gif"
  }
}
Emoji removed
{
  "team_id": "T0123ABC",
  "enterprise_id": "E0123ABC",
  "event_id": "Ev0123ABC",
  "event_timestamp": 1630623713,
  "type": "event",
  "data": {
    "event_type": "slack#/events/emoji_changed",
    "names": ["picard_facepalm"],
    "subtype": "remove",
  }
}
Emoji renamed
{
  "team_id": "T0123ABC",
  "enterprise_id": "E0123ABC",
  "event_id": "Ev0123ABC",
  "event_timestamp": 1630623713,
  "type": "event",
  "data": {
    "event_type": "slack#/events/emoji_changed",
    "new_name": "captain_picard_facepalm",
    "old_name": "picard_facepalm",
    "subtype": "rename",
    "value": "https://my.slack.com/emoji/picard_facepalm/abc123.gif"
  }
}
{
  "team_id": "T0123ABC",
  "enterprise_id": "E0123ABC",
  "event_id": "Ev0123ABC",
  "event_timestamp": 1630623713,
  "type": "event",
  "data": {
    "channel_id": "C0123ABC",
    "channel_type" : "public/private/im/mpim",
    "event_type": "slack#/events/user_joined_channel",
    "inviter_id": "U0123ABC",
    "user_id": "U0123ABC",
  }
}
{
  "team_id": "T0123ABC",
  "enterprise_id": "E0123ABC",
  "event_id": "Ev0123ABC",
  "event_timestamp": 1630623713,
  "type": "event",
  "data": {
    "channel_id": "C0123ABC",
    "channel_type" : "public/private/im/mpim",
    "event_type": "slack#/events/user_left_channel",
    "user_id": "W0123ABC",
  }
}
{
  "team_id": "T0123ABC",
  "enterprise_id": "E0123ABC",
  "event_id": "Ev0123ABC",
  "event_timestamp": 1630623713,
  "type": "event",
  "data": {
    "channel_id": "C0123ABC",
    "channel_type": "public/private/im/mpim",
    "event_type": "slack#/events/message_posted",
    "message_ts": "1355517523.000005",
    "text": "Hello world",
    "thread_ts": "1355517523.000006", // Nullable
    "user_id": "U0123ABC",
  }
}
{
  "team_id": "T0123ABC",
  "enterprise_id": "E0123ABC",
  "event_id": "Ev0123ABC",
  "event_timestamp": 1630623713,
  "type": "event",
  "data": {
    "app_id": "A0123ABC",
    "channel_id": "C0123ABC",
    "event_type": "slack#/events/message_metadata_posted",
    "message_ts": "1630708981.000001",
    "metadata": {
      "event_type": "incident_created",
      "event_payload": {
        "incident": {
          "id": 123,
          "summary": "Someone tripped over",
          "sev": 1
        }
      }
    },
    "user_id": "U0123ABC",
  }
}
{
  "team_id": "T0123ABC",
  "enterprise_id": "E0123ABC",
  "event_id": "Ev0123ABC",
  "event_timestamp": 1643810217.088700,
  "type": "event",
  "data": {
    "channel_id": "C0123ABC",
    "channel_type": "public/private/im/mpim",
    "channel_name": "project_planning",
    "event_type": "slack#/events/pin_added",
    "message_ts": "1360782804.083113",
    "user_id": "U0123ABC",
  }
}
{
  "team_id": "T0123ABC",
  "enterprise_id": "E0123ABC",
  "event_id": "Ev0123ABC",
  "event_timestamp": 1643810217.088700,
  "type": "event",
  "data": {
    "channel_id": "C0123ABC",
    "channel_name": "project_planning",
    "channel_type": "public/private/im/mpim",
    "event_type": "slack#/events/pin_removed",
    "message_ts": "1360782804.083113",
    "user_id": "U0123ABC",
  }
}
{
  "team_id": "T0123ABC",
  "enterprise_id": "E0123ABC",
  "event_id": "Ev0123ABC",
  "event_timestamp": 1630623713,
  "type": "event",
  "data": {
    "channel_id": "C0123ABC",
    "event_type": "slack#/events/reaction_added",
    "message_context": {
      "message_ts": "1535430114.000100",
      "channel_id": "C0123ABC",
    },
    "message_ts": "1535430114.000100",
    "reaction": "joy",
    "user_id": "U0123ABC",
  }
}
{
  "team_id": "T0123ABC",
  "enterprise_id": "E0123ABC",
  "event_id": "Ev0123ABC",
  "event_timestamp": 12345,
  "type": "event",
  "data": {
    "channel_id": "C0123ABC",
    "event_type": "slack#/events/reaction_removed",
    "message_ts": "1535430114.000100",
    "reaction": "thumbsup",
    "user_id": "U0123ABC",
  }
}
{
  "team_id": "T0123ABC",
  "enterprise_id": "E0123ABC",
  "event_id": "Ev0123ABC",
  "event_timestamp": 1643810217.088700,
  "type": "event",
  "data": {
    "accepting_user": {
      "display_name": "John Doe",
      "id": "U123",
      "is_bot": false,
      "name": "John Doe",
      "real_name": "John Doe",
      "team_id": "T123",
      "timezone": "America/Los_Angeles",
    },
    "approval_required": false,
    "channel_id": "C12345678",
    "channel_name": "test-slack-connect",
    "channel_type": "public/private/im/mpim",
    "event_type": "slack#/events/shared_channel_invite_accepted",
    "invite": {
      "date_created": 1626876000,
      "date_invalid": 1628085600,
      "id": "I028YDERZSQ",
      "inviting_team": {
        "date_created": 1480946400,
        "domain": "corgis",
        "icon": {...},
        "id": "T12345678",
        "is_verified": false,
        "name": "Corgis",
      },
      "inviting_user": {
        "display_name": "John Doe",
        "id": "U123",
        "is_bot": false,
        "name": "John Doe",
        "real_name": "John Doe",
        "team_id": "T123",
        "timezone": "America/Los_Angeles",
      },
      "recipient_email": "golden@doodle.com",
      "recipient_user_id": "U87654321",
    },
    "teams_in_channel": [
      {
        "date_created": 1626789600,
        "domain": "corgis",
        "icon": {...},
        "id": "T12345678",
        "is_verified": false,
        "name": "Corgis",
      }
    ],
  }
}
{
  "team_id": "T0123ABC",
  "enterprise_id": "E0123ABC",
  "event_id": "Ev0123ABC",
  "event_timestamp": 1643810217.0887,
  "type": "event",
  "data": {
    "approving_team_id": "T87654321",
    "approving_user": {
      "display_name": "John Doe",
      "id": "U123",
      "is_bot": false,
      "team_id": "T123",
      "name": "John Doe",
      "real_name": "John Doe",
      "team_id": "T12345",
      "timezone": "America/Los_Angeles",
    },
    "channel_id": "C12345678",
    "channel_name": "test-slack-connect",
    "channel_type": "public/private/im/mpim",
    "event_type": "slack#/events/shared_channel_invite_approved",
    "invite": {
      "date_created": 1626876000,
      "date_invalid": 1628085600,
      "id": "I0123ABC",
      "inviting_team": {
        "date_created": 1480946400,
        "domain": "corgis",
        "icon": {...},
        "id": "T12345678",
        "is_verified": false,
        "name": "Corgis",
      },
      "inviting_user": {
        "display_name": "John Doe",
        "id": "U123",
        "is_bot": false,
        "name": "John Doe",
        "real_name": "John Doe",
        "team_id": "T123",
        "timezone": "America/Los_Angeles",
      },
      "recipient_email": "golden@doodle.com",
      "recipient_user_id": "U87654321"
    },
    "teams_in_channel": [
      {
        "date_created": 1626789600,
        "domain": "corgis",
        "icon": {...},
        "id": "T12345678",
        "is_verified": false,
        "name": "Corgis",
      }
    ],
  }
}
{
  "team_id": "T0123ABC",
  "enterprise_id": "E0123ABC",
  "event_id": "Ev0123ABC",
  "event_timestamp": 1643810217.0887,
  "type": "event",
  "data": {
    "channel_id": "C12345678",
    "channel_type": "public/private/im/mpim",
    "channel_name": "test-slack-connect",
    "declining_team_id": "T87654321",
    "declining_user": {
      "display_name": "John Doe",
      "id": "U123",
      "is_bot": false,
      "name": "John Doe",
      "real_name": "John Doe",
      "team_id": "T123",
      "timezone": "America/Los_Angeles",
    },
    "event_type": "slack#/events/shared_channel_invite_declined",
    "invite": {
      "date_created": 1626876000,
      "date_invalid": 1628085600,
      "id": "I0123ABC",
      "inviting_team": {
        "date_created": 1480946400,
        "domain": "corgis",
        "icon": {...},
        "id": "T12345678",
        "is_verified": false,
        "name": "Corgis",
      },
      "inviting_user": {
        "display_name": "John Doe",
        "id": "U123",
        "is_bot": false,
        "name": "John Doe",
        "real_name": "John Doe",
        "team_id": "T123",
        "timezone": "America/Los_Angeles",
      },
      "recipient_email": "golden@doodle.com",
      "recipient_user_id": "U3472391",
    },
    "teams_in_channel": [
      {
        "date_created": 1626789600,
        "domain": "corgis",
        "icon": {...},
        "id": "T12345678",
        "is_verified": false,
        "name": "Corgis",
      }
    ],
  }
}
{
  "team_id": "T0123ABC",
  "enterprise_id": "E0123ABC",
  "event_id": "Ev0123ABC",
  "event_timestamp": 1643810217.0887,
  "type": "event",
  "data": {
    "channel_id": "C12345678",
    "channel_name": "test-slack-connect",
    "channel_type": "public/private/im/mpim",
    "event_type": "slack#/events/shared_channel_invite_received",
    "invite": {
      "date_created": 1626876000,
      "date_invalid": 1628085600,
      "id": "I0123ABC",
      "inviting_team": {
        "date_created": 1480946400,
        "domain": "corgis",
        "icon": {...},
        "id": "T12345678",
        "is_verified": false,
        "name": "Corgis",
      },
      "inviting_user": {
        "display_name": "John Doe",
        "id": "U123",
        "is_bot": false,
        "name": "John Doe",
        "real_name": "John Doe",
        "team_id": "T123",
        "timezone": "America/Los_Angeles",
      },
      "recipient_email": "golden@doodle.com",
      "recipient_user_id": "U87654321"
    },

  }
}
{
  "team_id": "T0123ABC",
  "enterprise_id": "E0123ABC",
  "event_id": "Ev0123ABC",
  "event_timestamp": 1630623713,
  "type": "event",
  "data": {
    "event_type": "slack#/events/user_joined_team",
    "user": {
      "display_name": "John Doe",
      "id": "U123",
      "is_bot": false,
      "name": "John Doe",
      "real_name": "John Doe",
      "team_id": "T123",
      "timezone": "America/Los_Angeles",
    }
  }
}

*When developing with these event types on Enterprise Grid, you must include the team_ids field when creating workspace-based event triggers.

The data returned in the event response object can be passed along to workflows. In this example, we take the user_id, channel_id, and message_ts from the reaction_added event's response object and pass them along to the joy_workflow in the inputs field, referencing them by their respective enums.

{
  type: TriggerTypes.Event,
  name: "Joy reactji event trigger",
  description: "Joy reactji trigger",
  workflow: "#/workflows/joy_workflow",
  inputs: {
    user: {
      value: TriggerContextData.Event.ReactionAdded.user_id, // Pulled from event response body and passed into the workflow
    },
    channel: {
      value: TriggerContextData.Event.ReactionAdded.channel_id, // Pulled from event response body and passed into the workflow
    },
    message_ts: {
      value: TriggerContextData.Event.ReactionAdded.message_ts // Pulled from event response body and passed into the workflow
    }
  },
  event: {
    event_type: TriggerEventTypes.ReactionAdded,
    channel_ids: ["C123ABC456"]
  }
}

Event trigger filters

Trigger filters allow you to define a set of conditions for a trigger which must be true in order for the trigger to activate.

Filters can also prevent your app from getting stuck in an infinite loop of responses triggered by responding to events it created.

Trigger filters are implemented by inserting a filter payload within your trigger object. The payload takes the form of an object containing blocks of conditional logic. The logical condition within each block can be one of two types:

  • Conditional expressions (e.g. x < y)
  • Boolean logic (e.g. x AND y)

Conditional expressions

Conditional expression blocks need a single statement key with a string containing the comparison block. Values from the inputs payload can be referenced within the comparison block.

Below is an example payload of a reaction_added event trigger that only invokes a workflow if the reaction was the :eyes: reaction.

{
  type: TriggerTypes.Event,
  name: "Reactji response",
  description: "responds to a specific reactji",
  workflow: "#/workflows/myWorkflow",
  event: {
    event_type: TriggerEventTypes.ReactionAdded,
    channel_ids: ["C123ABC456"],
    filter: {
      version: 1,
      root: {
        statement: "{{data.reaction}} == eyes"
      }
    }
  },
  inputs: {
    stringtoSend: {
      value: "how cool is that",
    },
    channel: {
      value: "C123ABC456",
    },
  },
};

The supported operand types are integer, double, boolean, string, and null. The following comparators are supported.

Comparator Supported types
== all types
> int, double
< int, double
>= int, double
<= int, double
CONTAINS string; i.e. {{data.text}} CONTAINS 'hello'

Boolean logic blocks

Boolean logic blocks are made up of two key:value pairs:

  • An operator key with a string containing the comparison operator: AND, OR, or NOT
  • An inputs key with the child blocks

The child blocks then contain additional logic. The following example filters on both the reaction value and the metadata.event_payload.incident_type value:

{
  type: TriggerTypes.Event,
  name: "Reactji response",
  description: "responds to a specific reactji",
  workflow: "#/workflows/myWorkflow",
  event: {
    event_type: TriggerEventTypes.ReactionAdded,
    channel_ids: ["C123ABC456"],
    filter: {
      version: 1,
      root: {
        operator: "OR",
        inputs: [{
          statement: "{{data.reaction}} == sunglasses"
        },
        {
          statement: "{{data.reaction}} == smile"
        }],
      }
    }
  },
  inputs: {
    stringtoSend: {
      value: "how cool is that",
    },
    channel: {
      value: "C123ABC456",
    },
  },
};

Nested logic blocks
You can use the same boolean logic to create nested boolean logic blocks. It's boolean logic all the way down - up to a maximum of 5 nested blocks, that is. The NOT operator, however, must contain only one input. Also, at the moment the boolean logic block does not support short-circuit evaluation, so all arguments will be evaluated.

Trigger filters in sample apps

✨ The Simple Survey App lets users collect feedback on specific messages. The process begins when a user reacts to a message with the :clipboard: reaction. This is done with a reaction_added event trigger filtering for the :clipboard: reaction.

✨ The Daily Topic App can reply to messages in a channel. The message_posted event filters out both messages by apps (to prevent recursive replies) and messages within a thread (to reply only once per thread).

Event trigger response

The response will have a property called ok. If true, then the trigger was created, and the trigger property will be populated.

Your response will include a trigger.id; be sure to store it! You use that to update or delete the trigger if need be. See trigger management.

Onward

➑️ With your trigger created, you can now test your app by running your app locally.

✨ Once your app is active, see trigger management for info on managing your triggers in your workspace.


Have 2 minutes to provide some feedback?

We'd love to hear about your experience building modular Slack apps. Please complete our short survey so we can use your feedback to improve.