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_approvers reducer of a sym:approval Flow, which results in a request being sent to a channel.

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

@reducer
def get_approvers(event):
    if event.payload.fields["urgency"] == "High":
        # This is a self-approval in a channel
        return slack.channel("#break-glass", allow_self=True)
    return 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

@reducer
def get_approvers(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 self-approval in a DM
        return slack.user(evt.user, allow_self=True)

Route a request to a group DM

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

🚧

Slack's conversations.open endpoint for direct messages only accepts up to 8 users.

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

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