Slack SDK Integration

It is easy to request access and use your organization's workflow and approval logic via Sym's Slack Integration.

Add a Slack Integration

📘

You probably already have the Slack Integration configured

If you followed our Getting Started docs and/or configured your first flows via symflow init, this first step will already be done.

To add Slack to your Sym configuration, create a sym_integration and include it in your sym_environment.

resource "sym_integration" "slack" {
  type = "slack"
  name = "prod"

  # your slack workspace id
  external_id = "T012345678"
}

resource "sym_environment" "prod" {
  name = "prod"

  integrations = {
    slack_id     = sym_integration.slack.id
    # other integrations
  }
}

Using Slack in Python

For more information on the supported methods in the slack module, please visit the Sym SDK Slack Docs.

Route a request to a channel

This example returns a Slack channel in the get_request_notifications reducer of a sym:approval Flow, which sends a request to a channel.

from sym.sdk.annotations import hook, reducer
from sym.sdk.integrations import slack
from sym.sdk.notifications import Notification

@reducer
def get_request_notifications(event):
    if event.payload.fields["urgency"] == "High":
      	return [Notification(destinations=[slack.channel("#break-glass")])]
  	return [Notification(destinations=[slack.channel("#ops")])]

Route a request to a DM

This example uses the PagerDuty Integration to selectively DM a Slack user.

from sym.sdk.annotations import hook, reducer
from sym.sdk.integrations import pagerduty, slack
from sym.sdk.notifications import Notification

@reducer
def get_request_notifications(event):
    # The `pagerduty` import uses the credentials from the pagerduty sym_integration.
    # It knows how to take in a User and check if that User is 
    # on call for a given schedule.
    if pagerduty.is_on_call(event.user, escalation_policy_name="sre"):
        # This is a in a DM
      	return [Notification(destinations=[slack.user(event.user)])]

Route a request to a group DM

This example returns a group of users to DM with an access request.

🚧

Slack's group DM feature only supports up to 9 users per group. Since the Sym App counts as one, only 8 additional users may be specified.

from sym.sdk.annotations import hook, reducer
from sym.sdk.integrations import pagerduty, slack
from sym.sdk.notifications import Notification

@reducer
def get_request_notifications(evt):
    on_call_mgrs = pagerduty.users_on_call(schedule_id="PXUGCWM")
  	return [Notification(destinations=[slack.group(on_call_mgrs[:7])])]