Reducers

Reducers are an SDK feature that "reduce" event input to a single value for use in a Flow.

Overview

Reducers run at specific points in the flow defined by the Sym processor, and provide critical context for Flow execution.

Reducer

Required

Function

get_approvers

yes

The only required reducer. Accepts an Event with a user and a target, and returns either a single User-like object, or a list of User-like objects.

Examples

get_approvers

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

# Reducers can be mandatory, and provide dynamic config values

@reducer 
def get_approvers(evt):
    """Returns a set of approvers, given a user and a target."""
   
    # The import here uses credentials defined in an Integration in Terraform
    if pagerduty.is_on_call(evt.user, schedule="id_of_eng_on_call"):
        # This is a self-approval in a DM
        return slack.user(evt.user)

    if evt.payload.fields["urgency"] == "High":
        # This is a self-approval in a channel
        return slack.channel("#break-glass", allow_self=True)

    on_call_mgrs = okta.group("OnCallManagers").members()
    # This would create a group DM for on-call managers
    return slack.group(on_call_mgrs)

Did this page help you?