sym.sdk.integrations.slack

Helpers for interacting with a Slack workspace.

Functions

channel(name[, allow_self])

A reference to a Slack channel.

fallback(*channels)

An instruction to try a series of slack.channel, slack.user, and slack.group until one succeeds.

get_user_info(user)

Get information about a Slack user.

group(users[, allow_self])

A reference to a Slack group.

list_users(self[, active_only])

Returns a list of all users in the workspace.

mention(identifier)

Returns a string that mentions a Slack user given their identifier.

send_message(destination, message)

Sends a simple message to a destination in Slack.

user(identifier)

A reference to a Slack user.

Classes

SlackChannel

SlackLookupType

An enumeration.

class sym.sdk.integrations.slack.SlackChannel(lookup_type: sym.sdk.integrations.slack.SlackLookupType, lookup_keys: List[Union[str, sym.sdk.user.User]], allow_self: bool = True)

Bases: object

class sym.sdk.integrations.slack.SlackLookupType(value)

Bases: str, enum.Enum

An enumeration.

sym.sdk.integrations.slack.channel(name: str, allow_self: bool = False) sym.sdk.integrations.slack.SlackChannel

A reference to a Slack channel.

Parameters
  • name – The channel name to send the message to.

  • allow_self – Whether to allow the current user to approve their own request.

sym.sdk.integrations.slack.fallback(*channels: sym.sdk.integrations.slack.SlackChannel) sym.sdk.integrations.slack.SlackChannel

An instruction to try a series of slack.channel, slack.user, and slack.group until one succeeds.

e.g. slack.fallback(slack.channel(“#missing”), slack.user(“@david”))

Parameters

channels – any number of channel, group and user.

sym.sdk.integrations.slack.get_user_info(user: sym.sdk.user.User) dict

Get information about a Slack user.

Refer to Slack’s users.info API documentation for the details on the response format: https://api.slack.com/methods/users.info

Parameters

user – The Sym user to get info about.

sym.sdk.integrations.slack.group(users: Sequence[Union[str, sym.sdk.user.User]], allow_self: bool = False) sym.sdk.integrations.slack.SlackChannel

A reference to a Slack group.

Parameters

users (Sequence[Union[str, User]]) – A list of either Sym User objects or emails.

sym.sdk.integrations.slack.list_users(self, active_only: bool = True) list

Returns a list of all users in the workspace.

Refer to Slack’s users.info API documentation for the details on the response format: https://api.slack.com/methods/users.list

Parameters

active_only – A boolean indicating whether or not to exclude deactivated and deleted users.

sym.sdk.integrations.slack.mention(identifier: Union[str, sym.sdk.user.User]) str

Returns a string that mentions a Slack user given their identifier.

Users can be specified with a Slack user ID, email, a string version of an @mention e.g. @Jane Austen, or Sym User instance.

sym.sdk.integrations.slack.send_message(destination: Union[sym.sdk.user.User, sym.sdk.integrations.slack.SlackChannel], message: str) None

Sends a simple message to a destination in Slack. Accepts either a User or a SlackChannel, which may represent a user, group, or channel in Slack.

For example:

# To send to #general:
slack.send_message(slack.channel("#general"), "Hello, world!")

# To DM a specific user:
slack.send_message(slack.user("me@symops.io"), "It works!")

# To DM the user who triggered an event:
slack.send_message(event.user, "You did a thing!")
Parameters
  • destination – where the message should go.

  • message – the text contents of the message to send.

sym.sdk.integrations.slack.user(identifier: Union[str, sym.sdk.user.User]) sym.sdk.integrations.slack.SlackChannel

A reference to a Slack user.

Users can be specified with a Slack user ID, email, a string version of an @mention e.g. @Jane Austen, or Sym User instance.