errbot.backends.slack module

class errbot.backends.slack.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]
exception errbot.backends.slack.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.SlackBackend(config)[source]

Bases: errbot.core.ErrBot

__init__(config)[source]
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.

api_call(method, data=None, raise_errors=True)[source]

Make an API call to the Slack API and return response data.

This is a thin wrapper around SlackClient.server.api_call.

Parameters:
Returns:

A dictionary containing the (JSON-decoded) API response

Raises:

SlackAPIResponseError if raise_errors is True and the API responds with {"ok": false}

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]
change_presence(status: str = 'online', message: str = '') → None[source]
channelid_to_channelname(id_)[source]

Convert a Slack channel ID to its channel name

channelname_to_channelid(name)[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]
mode
prefix_groupchat_reply(message, identifier)[source]
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]
send_message(msg)[source]
send_stream_request(identifier, fsource, name='file', size=None, stream_type=None)[source]

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

serve_once()[source]
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.

userid_to_username(id_)[source]

Convert a Slack user ID to their user name

username_to_userid(name)[source]

Convert a Slack user name to their user ID

class errbot.backends.slack.SlackBot(sc, bot_id, bot_username)[source]

Bases: errbot.backends.slack.SlackPerson

This class describes a bot on Slack's network.

__init__(sc, bot_id, bot_username)[source]
aclattr
fullname
nick
username
class errbot.backends.slack.SlackPerson(sc, userid=None, channelid=None)[source]

Bases: errbot.backends.base.Person

This class describes a person on Slack's network.

__init__(sc, userid=None, channelid=None)[source]
aclattr
channelid
channelname

Convert a Slack channel ID to its channel name

client
domain
fullname

Convert a Slack user ID to their user name

nick

Convert a Slack user ID to their user name

person
userid
username

Convert a Slack user ID to their user name

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

Bases: errbot.backends.base.Room

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

Return the ID of this room

create(private=False)[source]
destroy()[source]
exists
id

Return the ID of this room

invite(*args)[source]
join(username=None, password=None)[source]
joined
leave(reason=None)[source]
name

Return the name of this room

occupants
private

Return True if the room is a private group

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

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

This class represents a bot inside a MUC.

__init__(sc, bot_id, bot_username, channelid, bot)[source]
room
class errbot.backends.slack.SlackRoomOccupant(sc, userid, channelid, bot)[source]

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

This class represents a person inside a MUC.

__init__(sc, userid, channelid, bot)[source]
room
errbot.backends.slack.slack_markdown_converter(compact_output=False)[source]

This is a Markdown converter for use with Slack.