llama.com.slack package

Utilities for interacting with slack. Used for slack upload filehandlers as well as various slack-based logging utilities.

llama.com.slack.alert_maintainers(msg, desc=None, recover=True)

Shortcut to send a message to the LLAMA maintainer of LLAMA functionality on the default LLAMA channel, tagging MAINTAINERS using tag_user and sending the message with send_message. Import this in other parts of the code to have a Slack-based logging/alert tool. Optionally provide the name of the calling module (or some other description) as desc. Since this is meant to be used elsewhere in the code (including parts of the code that may run on non-production servers), it will fail if no SLACK_TOKENS['LLAMA'] is defined. If recover=True, suppress and log errors due to message sending failures; otherwise, raise errors as usual.

llama.com.slack.client(token)

Return a SlackClient instance for interacting with Slack’s API. Will default to the LLAMA slack organization (which will fail if you have not configured an auth token via environmental variables).

llama.com.slack.get_users(organization)

Get list of users for an organization. Particularly useful because each user’s id value can be used to tag users, as is done in tag_user. Returns the API dict straight from slack.WebClient.

llama.com.slack.search_users(organization, queries)

Fuzzy search for Slack users.

Parameters
  • organization (str) – The Slack organization name to search for users.

  • queries (list) – A list of string queries, each of which should match one unique user. Matches existing users for organization based on display names, real names, or Slack IDs that match the values of queries. Case-insensitive for every field except the ID. Will only return users who are not deleted.

Returns

users – A list of Slack API user dictionaries matching queries, which can be used to tag them in messages using the values corresponding to their id keys.

Return type

list

Raises
  • slack.errors.SlackApiError – If you are not authenticated or else there is some other error while calling get_users.

  • ValueError – If your query returns multiple users or no users, or if some of the queries correspond to the same user.

llama.com.slack.send_message(organization, message, channel=None, recover=False)

Send a simple text message to channel (default: first channel registered for organization) in organization. Returns the response dict from slack. If recover=True, suppress and log errors due to message sending failures; otherwise, raise errors as usual.

llama.com.slack.tag_users(organization, queries, recover=True)

Get a string of text that can be used to tag users for a specific Slack organization. Stick this text somewhere in your message body to tag people and alert them. Same interface as search_users, but you can optionally recover from a failure to find matching users by specifying recover=True.