Classes & Methods

class slackclient.SlackClient(token)

The SlackClient makes API Calls to the Slack Web API as well as managing connections to the Real-time Messaging API via websocket

It also manages some of the Client state for Channels that the associated token (User or Bot) is associated with.

For more information, check out the Slack API Docs

Init:
Args:token (str): Your Slack Authentication token. You can find or generate a test token here Note: Be careful with your token
api_call(method, **kwargs)

Call the Slack Web API as documented here: https://api.slack.com/web

Args:

method (str): The API Method to call. See the full list here

Kwargs:

(optional) kwargs: any arguments passed here will be bundled and sent to the api requester as post_data and will be passed along to the API.

Example:

sc.server.api_call(
    "channels.setPurpose",
    channel="CABC12345",
    purpose="Writing some code!"
)
Returns:

str – returns the text of the HTTP response.

Examples:

u'{"ok":true,"purpose":"Testing bots"}'
or
u'{"ok":false,"error":"channel_not_found"}'

See here for more information on responses: https://api.slack.com/web

process_changes(data)

Internal method which processes RTM events and modifies the local data store accordingly.

Stores new channels when joining a group (Multi-party DM), IM (DM) or channel.

Stores user data on a team join event.

rtm_connect()

Connects to the RTM Websocket

Args:None
Returns:False on exceptions
rtm_read()

Reads from the RTM Websocket stream then calls self.process_changes(item) for each line in the returned data.

Multiple events may be returned, always returns a list [], which is empty if there are no incoming messages.

Args:

None

Returns:

data (json) - The server response. For example:

[{u'presence': u'active', u'type': u'presence_change', u'user': u'UABC1234'}]
Raises:

SlackNotConnected if self.server is not defined.

rtm_send_message(channel, message)

Sends a message to a given channel.

Args:channel (str) - the string identifier for a channel or channel name (e.g. ‘C1234ABC’, ‘bot-test’ or ‘#bot-test’) message (message) - the string you’d like to send to the channel
Returns:None
class slackclient._server.Server(token, connect=True)

The Server object owns the websocket connection and all attached channel information.

api_call(method, **kwargs)

Call the Slack Web API as documented here: https://api.slack.com/web

Args:

method (str): The API Method to call. See here for a list: https://api.slack.com/methods

Kwargs:

(optional) kwargs: any arguments passed here will be bundled and sent to the api requester as post_data

and will be passed along to the API.

Example:

sc.server.api_call(
    "channels.setPurpose",
    channel="CABC12345",
    purpose="Writing some code!"
)
Returns:

str – returns the text of the HTTP response.

Examples:

u'{"ok":true,"purpose":"Testing bots"}'
or
u'{"ok":false,"error":"channel_not_found"}'

See here for more information on responses: https://api.slack.com/web

join_channel(name)

Join a channel by name.

Note: this action is not allowed by bots, they must be invited to channels.

send_to_websocket(data)

Send a JSON message directly to the websocket. See RTM documentation <https://api.slack.com/rtm for allowed types.

Args:data (dict) the key/values to send the websocket.
websocket_safe_read()

Returns data if available, otherwise ‘’. Newlines indicate multiple messages

class slackclient._channel.Channel(server, name, channel_id, members=None)

A Channel represents a public or private Slack Channel instance

send_message(message)

Sends a message to a this Channel.

Args:message (message) - the string you’d like to send to the channel
Returns:None