errbot.backends.slack_rtm module

class errbot.backends.slack_rtm.LinkPreProcessor(markdown_instance=None)[source]

Bases: markdown.preprocessors.Preprocessor

This preprocessor converts markdown URL notation into Slack URL notation as described at https://api.slack.com/docs/formatting, section “Linking to URLs”.

run(lines)[source]

Each subclass of Preprocessor should override the run method, which takes the document as a list of strings split by newlines and returns the (possibly modified) list of lines.

exception errbot.backends.slack_rtm.SlackAPIResponseError(*args, error='', **kwargs)[source]

Bases: RuntimeError

Slack API returned a non-OK response

__init__(*args, error='', **kwargs)[source]
Parameters:error (str) – The ‘error’ key from the API response data
class errbot.backends.slack_rtm.SlackBot(webclient: slack.web.client.WebClient, bot_id, bot_username)[source]

Bases: errbot.backends.slack_rtm.SlackPerson

This class describes a bot on Slack’s network.

__init__(webclient: slack.web.client.WebClient, bot_id, bot_username)[source]

Initialize self. See help(type(self)) for accurate signature.

aclattr
Returns:returns the unique identifier that will be used for ACL matches.
fullname

Convert a Slack user ID to their full name

nick

Convert a Slack user ID to their user name

username

Convert a Slack user ID to their user name

class errbot.backends.slack_rtm.SlackPerson(webclient: slack.web.client.WebClient, userid=None, channelid=None)[source]

Bases: errbot.backends.base.Person

This class describes a person on Slack’s network.

__init__(webclient: slack.web.client.WebClient, userid=None, channelid=None)[source]

Initialize self. See help(type(self)) for accurate signature.

aclattr
Returns:returns the unique identifier that will be used for ACL matches.
channelid
channelname

Convert a Slack channel ID to its channel name

client
domain
fullname

Convert a Slack user ID to their full name

nick

Convert a Slack user ID to their user name

person
Returns:a backend specific unique identifier representing the person you are talking to.
userid
username

Convert a Slack user ID to their user name

class errbot.backends.slack_rtm.SlackRTMBackend(config)[source]

Bases: errbot.core.ErrBot

__init__(config)[source]

Those arguments will be directly those put in BOT_IDENTITY

add_reaction(msg: errbot.backends.base.Message, reaction: str) → None[source]

Add the specified reaction to the Message if you haven’t already. :type reaction: str :type msg: Message :param msg: A Message. :param reaction: A str giving an emoji, without colons before and after. :raises: ValueError if the emoji doesn’t exist.

build_identifier(txtrep)[source]

Build a SlackIdentifier from the given string txtrep.

Supports strings with the formats accepted by extract_identifiers_from_string().

build_reply(msg, text=None, private=False, threaded=False)[source]

Should be implemented by the backend

change_presence(status: str = 'online', message: str = '') → None[source]

Signal a presence change for the bot. Should be overridden by backends with a super().send_message() call.

channelid_to_channelname(webclient: slack.web.client.WebClient, id_: str)[source]

Convert a Slack channel ID to its channel name

channelname_to_channelid(webclient: slack.web.client.WebClient, name: str)[source]

Convert a Slack channel name to its channel ID

channels(exclude_archived=True, joined_only=False)[source]

Get all channels and groups and return information about them.

Parameters:
  • exclude_archived (bool) – Exclude archived channels/groups
  • joined_only (bool) – Filter out channels the bot hasn’t joined
Returns:

A list of channel (https://api.slack.com/types/channel) and group (https://api.slack.com/types/group) types.

See also:
static extract_identifiers_from_string(text)[source]

Parse a string for Slack user/channel IDs.

Supports strings with the following formats:

<#C12345>
<@U12345>
<@U12345|user>
@user
#channel/user
#channel

Returns the tuple (username, userid, channelname, channelid). Some elements may come back as None.

get_im_channel[source]

Open a direct message channel to a user

is_from_self(msg: errbot.backends.base.Message) → bool[source]

Needs to be overridden to check if the incoming message is from the bot itself.

Return type:bool
Parameters:msg (Message) – The incoming message.
Returns:True if the message is coming from the bot.
mode
prefix_groupchat_reply(message, identifier)[source]

Patches message with the conventional prefix to ping the specific contact For example: @gbin, you forgot the milk !

static prepare_message_body(body, size_limit)[source]

Returns the parts of a message chunked and ready for sending.

This is a staticmethod for easier testing.

Args:
body (str) size_limit (int): chunk the body into sizes capped at this maximum
Returns:
[str]
process_mentions(text)[source]

Process mentions in a given string :returns:

A formatted string of the original message and a list of SlackPerson instances.
query_room(room)[source]

Room can either be a name or a channelid

remove_reaction(msg: errbot.backends.base.Message, reaction: str) → None[source]

Remove the specified reaction from the Message if it is currently there. :type reaction: str :type msg: Message :param msg: A Message. :param reaction: A str giving an emoji, without colons before and after. :raises: ValueError if the emoji doesn’t exist.

rooms()[source]

Return a list of rooms the bot is currently in.

Returns:A list of SlackRoom instances.
static sanitize_uris(text)[source]

Sanitizes URI’s present within a slack message. e.g. <mailto:example@example.org|example@example.org>, <http://example.org|example.org> <http://example.org>

Returns:string
send_card(card: errbot.backends.base.Card)[source]

Sends a card, this can be overriden by the backends without a super() call.

Parameters:card (Card) – the card to send.
Returns:None
send_message(msg)[source]

This needs to be overridden by the backends with a super() call.

Parameters:msg – the message to send.
Returns:None
send_stream_request(user: errbot.backends.base.Identifier, fsource: BinaryIO, name: str = None, size: int = None, stream_type: str = None) → errbot.backends.base.Stream[source]

Starts a file transfer. For Slack, the size and stream_type are unsupported

Return type:

Stream

Parameters:
  • user (Identifier) – is the identifier of the person you want to send it to.
  • fsource (BinaryIO) – is a file object you want to send.
  • name (str) – is an optional filename for it.
  • size (int) – not supported in Slack backend
  • stream_type (str) – not supported in Slack backend
Return Stream:

object on which you can monitor the progress of it.

serve_forever()[source]

Connect the back-end to the server and serve forever.

Back-ends MAY choose to re-implement this method, in which case they are responsible for implementing reconnection logic themselves.

Back-ends SHOULD trigger connect_callback() and disconnect_callback() themselves after connection/disconnection.

shutdown()[source]
update_alternate_prefixes()[source]

Converts BOT_ALT_PREFIXES to use the slack ID instead of name

Slack only acknowledges direct callouts @username in chat if referred by using the ID of that user.

static userid_to_username(webclient: slack.web.client.WebClient, id_: str)[source]

Convert a Slack user ID to their user name

static username_to_userid(webclient: slack.web.client.WebClient, name: str)[source]

Convert a Slack user name to their user ID

class errbot.backends.slack_rtm.SlackRoom(name=None, channelid=None, bot=None)[source]

Bases: errbot.backends.base.Room

__init__(name=None, channelid=None, bot=None)[source]

Initialize self. See help(type(self)) for accurate signature.

channelid

Return the ID of this room

channelname
create(private=False)[source]

Create the room.

Calling this on an already existing room is a no-op.

destroy()[source]

Destroy the room.

Calling this on a non-existing room is a no-op.

exists

Boolean indicating whether this room already exists or not.

Getter:Returns True if the room exists, False otherwise.
id

Return the ID of this room

invite(*args)[source]

Invite one or more people into the room.

*argsargs:One or more identifiers to invite into the room.
join(username=None, password=None)[source]

Join the room.

If the room does not exist yet, this will automatically call create() on it first.

joined

Boolean indicating whether this room has already been joined.

Getter:Returns True if the room has been joined, False otherwise.
leave(reason=None)[source]

Leave the room.

Parameters:reason – An optional string explaining the reason for leaving the room.
name

Return the name of this room

occupants

The room’s occupants.

Getter:Returns a list of occupant identities.
Raises:MUCNotJoinedError if the room has not yet been joined.
private

Return True if the room is a private group

purpose
topic

The room topic.

Getter:

Returns the topic (a string) if one is set, None if no topic has been set at all.

Note

Back-ends may return an empty string rather than None when no topic has been set as a network may not differentiate between no topic and an empty topic.

Raises:

MUCNotJoinedError if the room has not yet been joined.

class errbot.backends.slack_rtm.SlackRoomBot(sc, bot_id, bot_username, channelid, bot)[source]

Bases: errbot.backends.base.RoomOccupant, errbot.backends.slack_rtm.SlackBot

This class represents a bot inside a MUC.

__init__(sc, bot_id, bot_username, channelid, bot)[source]

Initialize self. See help(type(self)) for accurate signature.

room

Some backends have the full name of a user.

Returns:the fullname of this user if available.
class errbot.backends.slack_rtm.SlackRoomOccupant(webclient: slack.web.client.WebClient, userid, channelid, bot)[source]

Bases: errbot.backends.base.RoomOccupant, errbot.backends.slack_rtm.SlackPerson

This class represents a person inside a MUC.

__init__(webclient: slack.web.client.WebClient, userid, channelid, bot)[source]

Initialize self. See help(type(self)) for accurate signature.

room

Some backends have the full name of a user.

Returns:the fullname of this user if available.
errbot.backends.slack_rtm.slack_markdown_converter(compact_output=False)[source]

This is a Markdown converter for use with Slack.