Slack web client to build a python slack bot.
Slackbotis a simple wrapper around basic API calls to slack API. Instantiation needs an environment variable storing the connexion token. When initiating a
Slackbotinstance, the bot id is read from slack API and stored as attribute.
token (str) – name for environment variable storing slack application token
- client – the slack web client instance with which API calls are made
- mention_regex – a regex to identify a direct mention in a text
- id – the bot’s id
closing_time(closing_hour: str, rtm_client=None) → None¶
Close an RTM client if the current hour is later than the given closing hour.
- closing_hour (str) – hour after which RTM client must be stopped.
Must be in
- rtm_client (
slack.RTMClient()) – The RTM client to stop (see above to see usage)
- closing_hour (str) – hour after which RTM client must be stopped. Must be in
parse_mention(message_text, regex) → tuple¶
From a message, find and extract a mention and the related text.
Result is a length-two tuple of the form
(user_id, text). If no mention is found in the message, the result is
- message_text (str) – the body of a message
- regex (regex) – the regex identifying a mention. Using
SlackBot.mention_regexwill usually suffice
send_message(channel, message) → None¶
Immediate wrap around
users_list() → list¶
Get the list of non-deleted users.
A wrapper around
slack.WebClient.users_list. It returns a flat list of dictionaries, with keys
idis used to tag people in messages with the syntax
<@%s> % id.