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
usingtag_user
and sending the message withsend_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) asdesc
. 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 noSLACK_TOKENS['LLAMA']
is defined. Ifrecover=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 intag_user
. Returns the API dict straight fromslack.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 ofqueries
. Case-insensitive for every field except the ID. Will only return users who are notdeleted
.
- 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 theirid
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
tochannel
(default: first channel registered fororganization
) inorganization
. Returns the responsedict
from slack. Ifrecover=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 Slackorganization
. Stick this text somewhere in your message body to tag people and alert them. Same interface assearch_users
, but you can optionally recover from a failure to find matching users by specifyingrecover=True
.