Navigation
  • Rules >
  • Slack Service Rules

Slack Service Rules

To use the Slack Service, you must specify rules to enable its actions. The rules must evaluate to true for the action to be enabled. An empty document ({}) always evaluates to true.

Specify a Rule

  1. Select the action(s) for which the rule applies.

  2. Specify the rule in valid JSON that evaluates to a boolean. You can specify MongoDB query expression operators with the exception of the $text and geospatial operators:

    {
      <field1>: <value1|expression1>,
      <field2>: <value2|expression2>,
      ...
    }
    

    You can specify rules based on an argument to the action. For details and examples, see Slack Service Arguments.

Slack Service Arguments

To specify a rule based on arguments:

{
  "%%args.<argument1>": <value1|expression1>,
  "%%args.<argument2>": <value1|expression2>,
  ...
}

Or, you can omit the %%args prefix if you do not specify any expansion prefixes for the fields.

{
  "<argument1>": <value1|expression1>,
  "<argument2>": <value1|expression2>,
  ...
}

However, you cannot mix arguments with prefixes and arguments without prefixes in the same rule. For example, the following rule is invalid:

{
  "%%args.to": "text@example.com",
  "from": "someone@example.com",
  ...
}

You can use the following arguments in Slack service rules.

channel

The channel argument is a string that corresponds to the Slack channel you wish to post to.

username

The username argument is a string that corresponds to the username under which the Slack message appears.

text

The text argument is a string that corresponds to the body of the Slack message.

iconUrl

The iconUrl argument is a string that specifies a URL which points to an icon for a Slack user.

iconEmoji

The iconEmoji argument is a string that represents an emoji.

Example

Actions When
post
{
  "channel" : "general",
  "username": "fred"
}

The rule ensures that applications can only perform a post action when:

  • channel is general, and
  • username is fred.