python-slackclient Documentation

55
python-slackclient Documentation Release 1.0.1 Ryan Huber, Jeff Ammons Sep 21, 2021

Transcript of python-slackclient Documentation

Page 1: python-slackclient Documentation

python-slackclient DocumentationRelease 1.0.1

Ryan Huber, Jeff Ammons

Sep 21, 2021

Page 2: python-slackclient Documentation
Page 3: python-slackclient Documentation

Contents

1 Keeping tokens safe 1

2 Single Workspace Install 3

3 Multiple Workspace Install 5

4 Basic Usage 94.1 Sending a message . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94.2 Formatting with Block Kit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104.3 Threading Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114.4 Updating a message . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114.5 Deleting a message . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124.6 Opening a modal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124.7 Updating and pushing modals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144.8 Emoji reactions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144.9 Listing public channels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154.10 Getting a channel’s info . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154.11 Joining a channel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154.12 Leaving a channel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164.13 Listing team members . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164.14 Uploading files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164.15 Calling any API methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 164.16 Web API Rate Limits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17

5 Conversations API 195.1 Direct messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195.2 Creating channels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205.3 Getting more information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205.4 Listing conversations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205.5 Leaving a conversation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215.6 Getting members . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

6 Real Time Messaging (RTM) 236.1 Configuring the RTM API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236.2 Connecting to the RTM API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236.3 rtm.start vs rtm.connect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 246.4 RTM Events . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25

i

Page 4: python-slackclient Documentation

7 Frequently Asked Questions 277.1 I cannot install slackclient. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277.2 Should I go with run_async? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277.3 I found a bug! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287.4 There’s a feature missing! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287.5 How do I contribute? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 287.6 How do I compile the documentation? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28

8 Changelog 298.1 v3.0.0 (2020-11-09) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298.2 v2.9.3 (2020-10-20) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298.3 v2.9.2 (2020-10-09) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298.4 v2.9.1 (2020-09-23) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308.5 v2.9.0 (2020-09-17) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308.6 v2.8.2 (2020-09-04) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308.7 v2.8.1 (2020-08-28) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 308.8 v2.8.0 (2020-08-06) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318.9 v2.7.3 (2020-07-20) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318.10 v2.7.2 (2020-06-23) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 318.11 v2.7.1 (2020-06-04) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328.12 v2.7.0 (2020-06-02) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328.13 v2.6.2 (2020-05-28) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328.14 v2.6.1 (2020-05-24) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 328.15 v2.6.0 (2020-05-21) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338.16 v2.5.0 (2019-12-09) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338.17 v2.4.0 (2019-11-27) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 338.18 v2.3.1 (2019-10-29) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348.19 v2.3.0 (2019-10-22) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348.20 v2.2.1 (2019-10-08) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348.21 v2.2.0 (2019-09-25) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 348.22 v2.1.0 (2019-07-01) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358.23 v2.0.0 (2019-04-29) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 358.24 v1.3.1 (2019-02-28) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368.25 v1.3.0 (2018-09-11) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368.26 v1.2.1 (2018-03-26) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368.27 v1.2.0 (2018-03-20) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368.28 v1.1.3 (2018-03-01) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368.29 v1.1.2 (2018-01-31) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 368.30 v1.1.1 (2018-01-30) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378.31 v1.1.0 (2017-11-21) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378.32 v1.0.9 (2017-08-31) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378.33 v1.0.8 (2017-08-31) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378.34 v1.0.7 (2017-08-02) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378.35 v1.0.6 (2017-06-12) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 378.36 v1.0.5 (2017-01-23) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 388.37 v1.0.4 (2016-12-15) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 388.38 v1.0.3 (2016-12-13) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 388.39 v1.0.2 (2016-09-22) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 388.40 v1.0.1 (2016-03-25) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 388.41 v1.0.0 (2016-02-28) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 388.42 v0.18.0 (2016-02-21) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 398.43 v0.17.0 (2016-02-15) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

9 About 41

ii

Page 5: python-slackclient Documentation

9.1 slackclient (Legacy Python Slack SDK) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

10 Important Notice 4310.1 slackclient (Legacy Python Slack SDK) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

11 Slack Platform Basics 45

12 Installation 47

13 Getting Help 49

iii

Page 6: python-slackclient Documentation

iv

Page 7: python-slackclient Documentation

CHAPTER 1

Keeping tokens safe

The OAuth token you use to call the Slack API has access to the data on the workspace where it is installed. Dependingon the scopes granted to the token, it potentially has the ability to read and write data. Treat these tokens just as youwould a password – don’t publish them, don’t check them into source code, don’t share them with others.

Avoid this:

token = 'xoxb-111-222-xxxxx'

We recommend you pass tokens in as environment variables, or persist them in a database that is accessed at runtime.You can add a token to the environment by starting your app as:

SLACK_BOT_TOKEN="xoxb-111-222-xxxxx" python myapp.py

Then retrieve the key with:

import osSLACK_BOT_TOKEN = os.environ["SLACK_BOT_TOKEN"]

For additional information, please see our Safely Storing Credentials page.

1

Page 8: python-slackclient Documentation

python-slackclient Documentation, Release 1.0.1

2 Chapter 1. Keeping tokens safe

Page 9: python-slackclient Documentation

CHAPTER 2

Single Workspace Install

If you’re building an application for a single Slack workspace, there’s no need to build out the entire OAuth flow.

Once you’ve setup your features, click on the Install App to Team button found on the Install App page. If youadd new permission scopes or Slack app features after an app has been installed, you must reinstall the app to yourworkspace for changes to take effect.

For additional information, see the Installing Apps of our Building Slack apps page.

3

Page 10: python-slackclient Documentation

python-slackclient Documentation, Release 1.0.1

4 Chapter 2. Single Workspace Install

Page 11: python-slackclient Documentation

CHAPTER 3

Multiple Workspace Install

If you intend for an app to be installed on multiple Slack workspaces, you will need to handle this installation via theindustry-standard OAuth protocol. You can read more about how Slack handles Oauth.

(The OAuth exchange is facilitated via HTTP and requires a webserver; in this example, we’ll use Flask.)

To configure your app for OAuth, you’ll need a client ID, a client secret, and a set of one or more scopes that will beapplied to the token once it is granted. The client ID and client secret are available from your app’s configuration page.The scopes are determined by the functionality of the app – every method you wish to access has a correspondingscope and your app will need to request that scope in order to be able to access the method. Review Slack’s full list ofOAuth scopes.

import osfrom slack import WebClientfrom flask import Flask, request

client_id = os.environ["SLACK_CLIENT_ID"]client_secret = os.environ["SLACK_CLIENT_SECRET"]oauth_scope = os.environ["SLACK_SCOPES"]

app = Flask(__name__)

The OAuth initiation link

To begin the OAuth flow that will install your app on a workspace, you’ll need to provide the user with a link toSlack’s OAuth page. This can be a simple link to https://slack.com/oauth/v2/authorize with scopeand client_id query parameters, or you can use our pre-built Add to Slack button to do all the work for you.

This link directs the user to Slack’s OAuth acceptance page, where the user will review and accept or refuse thepermissions your app is requesting as defined by the scope(s).

@app.route("/slack/install", methods=["GET"])def pre_install():state = "randomly-generated-one-time-value"return '<a href="https://slack.com/oauth/v2/authorize?' \

(continues on next page)

5

Page 12: python-slackclient Documentation

python-slackclient Documentation, Release 1.0.1

(continued from previous page)

f'scope={oauth_scope}&client_id={client_id}&state={state}">' \'Add to Slack</a>'

The OAuth completion page

Once the user has agreed to the permissions you’ve requested, Slack will redirect the user to your auth completionpage, which includes a code query string param. You’ll use the code param to call the oauth.v2.accessendpoint that will finally grant you the token.

@app.route("/slack/oauth_redirect", methods=["GET"])def post_install():# Verify the "state" parameter

# Retrieve the auth code from the request paramscode_param = request.args['code']

# An empty string is a valid token for this requestclient = WebClient()

# Request the auth tokens from Slackresponse = client.oauth_v2_access(client_id=client_id,client_secret=client_secret,code=code_param

)

A successful request to oauth.v2.access will yield a JSON payload with at least one token, a bot token thatbegins with xoxb.

@app.route("/slack/oauth_redirect", methods=["GET"])def post_install():# Verify the "state" parameter

# Retrieve the auth code from the request paramscode_param = request.args['code']

# An empty string is a valid token for this requestclient = WebClient()

# Request the auth tokens from Slackresponse = client.oauth_v2_access(client_id=client_id,client_secret=client_secret,code=code_param

)print(response)

# Save the bot token to an environmental variable or to your data store# for later useos.environ["SLACK_BOT_TOKEN"] = response['access_token']

# Don't forget to let the user know that OAuth has succeeded!return "Installation is completed!"

if __name__ == "__main__":app.run("localhost", 3000)

6 Chapter 3. Multiple Workspace Install

Page 13: python-slackclient Documentation

python-slackclient Documentation, Release 1.0.1

Once your user has completed the OAuth flow, you’ll be able to use the provided tokens to call any of Slack’s APImethods that require an access token.

See the Basic Usage section of this documentation for usage examples.

7

Page 14: python-slackclient Documentation

python-slackclient Documentation, Release 1.0.1

8 Chapter 3. Multiple Workspace Install

Page 15: python-slackclient Documentation

CHAPTER 4

Basic Usage

The Slack Web API allows you to build applications that interact with Slack in more complex ways than the integra-tions we provide out of the box.

Access Slack’s API methods requires an OAuth token – see the Tokens & Authentication section for more on howSlack uses OAuth tokens as well as best practices.

Each of these API methods is fully documented on our developer site at api.slack.com

4.1 Sending a message

One of the primary uses of Slack is posting messages to a channel using the channel ID or as a DM to another personusing their user ID. This method will handle either a channel ID or a user ID passed to the channel parameter.

import logginglogging.basicConfig(level=logging.DEBUG)

import osfrom slack import WebClientfrom slack.errors import SlackApiError

slack_token = os.environ["SLACK_API_TOKEN"]client = WebClient(token=slack_token)

try:response = client.chat_postMessage(channel="C0XXXXXX",text="Hello from your app! :tada:"

)except SlackApiError as e:# You will get a SlackApiError if "ok" is Falseassert e.response["error"] # str like 'invalid_auth', 'channel_not_found'

9

Page 16: python-slackclient Documentation

python-slackclient Documentation, Release 1.0.1

Sending an ephemeral message, which is only visible to an assigned user in a specified channel, is nearly the same assending a regular message, but with an additional user parameter.

import osfrom slack import WebClient

slack_token = os.environ["SLACK_API_TOKEN"]client = WebClient(token=slack_token)

response = client.chat_postEphemeral(channel="C0XXXXXX",text="Hello silently from your app! :tada:",user="U0XXXXXXX"

)

See chat.postEphemeral for more info.

4.2 Formatting with Block Kit

Messages posted from apps can contain more than just text, though. They can include full user interfaces composedof blocks.

The chat.postMessage method takes an optional blocks argument that allows you to customize the layout of a message.Blocks specified in a single object literal, so just add additional keys for any optional argument.

To send a message to a channel, use the channel’s ID. For IMs, use the user’s ID.

client.chat_postMessage(channel="C0XXXXXX",blocks=[{

"type": "section","text": {

"type": "mrkdwn","text": "Danny Torrence left the following review for your property:"

}},{

"type": "section","text": {

"type": "mrkdwn","text": "<https://example.com|Overlook Hotel> \n :star: \n Doors had too many

→˓axe holes, guest in room " +"237 was far too rowdy, whole place felt stuck in the 1920s."

},"accessory": {

"type": "image","image_url": "https://images.pexels.com/photos/750319/pexels-photo-750319.jpeg

→˓","alt_text": "Haunted hotel image"

}},{

"type": "section",

(continues on next page)

10 Chapter 4. Basic Usage

Page 17: python-slackclient Documentation

python-slackclient Documentation, Release 1.0.1

(continued from previous page)

"fields": [{"type": "mrkdwn","text": "*Average Rating*\n1.0"

}]

}]

)

Note: You can use the Block Kit Builder to prototype your message’s look and feel.

4.3 Threading Messages

Threaded messages are a way of grouping messages together to provide greater context. You can reply to a threador start a new threaded conversation by simply passing the original message’s ts ID in the thread_ts attributewhen posting a message. If you’re replying to a threaded message, you’ll pass the thread_ts ID of the message you’rereplying to.

A channel or DM conversation is a nearly linear timeline of messages exchanged between people, bots, and apps.When one of these messages is replied to, it becomes the parent of a thread. By default, threaded replies do not appeardirectly in the channel, instead relegated to a kind of forked timeline descending from the parent message.

response = client.chat_postMessage(channel="C0XXXXXX",thread_ts="1476746830.000003",text="Hello from your app! :tada:"

)

By default, reply_broadcast is set to False. To indicate your reply is germane to all members of a channel,and therefore a notification of the reply should be posted in-channel, set the reply_broadcast to True.

response = client.chat_postMessage(channel="C0XXXXXX",thread_ts="1476746830.000003",text="Hello from your app! :tada:",reply_broadcast=True

)

Note: While threaded messages may contain attachments and message buttons, when your reply is broadcast to thechannel, it’ll actually be a reference to your reply, not the reply itself. So, when appearing in the channel, it won’tcontain any attachments or message buttons. Also note that updates and deletion of threaded replies works the sameas regular messages.

See the Threading messages together article for more information.

4.4 Updating a message

Let’s say you have a bot which posts the status of a request. When that request changes, you’ll want to update themessage to reflect it’s state.

4.3. Threading Messages 11

Page 18: python-slackclient Documentation

python-slackclient Documentation, Release 1.0.1

response = client.chat_update(channel="C0XXXXXX",ts="1476746830.000003",text="updates from your app! :tada:"

)

See chat.update for formatting options and some special considerations when calling this with a bot user.

4.5 Deleting a message

Sometimes you need to delete things.

response = client.chat_delete(channel="C0XXXXXX",ts="1476745373.000002"

)

See chat.delete for more info.

4.6 Opening a modal

Modals allow you to collect data from users and display dynamic information in a focused surface.

Modals use the same blocks that compose messages with the addition of an input block.

# This module is available since v2.6from slack.signature import SignatureVerifiersignature_verifier = SignatureVerifier(os.environ["SLACK_SIGNING_SECRET"])

from flask import Flask, request, make_responseapp = Flask(__name__)

@app.route("/slack/events", methods=["POST"])def slack_app():if not signature_verifier.is_valid_request(request.get_data(), request.headers):return make_response("invalid request", 403)

if "payload" in request.form:payload = json.loads(request.form["payload"])

if payload["type"] == "shortcut" \and payload["callback_id"] == "open-modal-shortcut":# Open a new modal by a global shortcuttry:

api_response = client.views_open(trigger_id=payload["trigger_id"],view={

"type": "modal","callback_id": "modal-id","title": {

(continues on next page)

12 Chapter 4. Basic Usage

Page 19: python-slackclient Documentation

python-slackclient Documentation, Release 1.0.1

(continued from previous page)

"type": "plain_text","text": "Awesome Modal"

},"submit": {"type": "plain_text","text": "Submit"

},"close": {"type": "plain_text","text": "Cancel"

},"blocks": [{"type": "input","block_id": "b-id","label": {"type": "plain_text","text": "Input label",

},"element": {"action_id": "a-id","type": "plain_text_input",

}}

]}

)return make_response("", 200)

except SlackApiError as e:code = e.response["error"]return make_response(f"Failed to open a modal due to {code}", 200)

if payload["type"] == "view_submission" \and payload["view"]["callback_id"] == "modal-id":# Handle a data submission request from the modalsubmitted_data = payload["view"]["state"]["values"]print(submitted_data) # {'b-id': {'a-id': {'type': 'plain_text_input', 'value

→˓': 'your input'}}}return make_response("", 200)

return make_response("", 404)

if __name__ == "__main__":# export SLACK_SIGNING_SECRET=***# export SLACK_API_TOKEN=xoxb-***# export FLASK_ENV=development# python3 app.pyapp.run("localhost", 3000)

See views.open more details and additional parameters.

Also, to run the above example, the following Slack app configurations are required.

• Enable Interactivity with a valid Request URL: https://{your-public-domain}/slack/events

• Add a global shortcut with the Callback ID: open-modal-shortcut

4.6. Opening a modal 13

Page 20: python-slackclient Documentation

python-slackclient Documentation, Release 1.0.1

4.7 Updating and pushing modals

You can dynamically update a view inside of a modal by calling views.update and passing the view ID returned in theprevious views.open call.

private_metadata = "any str data you want to store"response = client.views_update(

view_id=payload["view"]["id"],hash=payload["view"]["hash"],view={"type": "modal","callback_id": "modal-id","private_metadata": private_metadata,"title": {

"type": "plain_text","text": "Awesome Modal"

},"submit": {

"type": "plain_text","text": "Submit"

},"close": {

"type": "plain_text","text": "Cancel"

},"blocks": [

{"type": "input","block_id": "b-id","label": {"type": "plain_text","text": "Input label",

},"element": {"action_id": "a-id","type": "plain_text_input",

}}

]}

)

See views.update for more info.

If you want to push a new view onto the modal instead of updating an existing view, reference the views.push docu-mentation.

4.8 Emoji reactions

You can quickly respond to any message on Slack with an emoji reaction. Reactions can be used for any purpose:voting, checking off to-do items, showing excitement -— or just for fun.

This method adds a reaction (emoji) to an item (file, file comment, channel message, group message,or direct message). One of file, file_comment, or the combination of channel and timestamp must be specified.

14 Chapter 4. Basic Usage

Page 21: python-slackclient Documentation

python-slackclient Documentation, Release 1.0.1

response = client.reactions_add(channel="C0XXXXXXX",name="thumbsup",timestamp="1234567890.123456"

)

Removing an emoji reaction is basically the same format, but you’ll use reactions.remove instead ofreactions.add

response = client.reactions_remove(channel="C0XXXXXXX",name="thumbsup",timestamp="1234567890.123456"

)

See reactions.add and reactions.remove for more info.

4.9 Listing public channels

At some point, you’ll want to find out what channels are available to your app. This is how you get that list.

response = client.conversations_list(types="public_channel")

Archived channels are included by default. You can exclude them by passing exclude_archived=1 to yourrequest.

response = client.conversations_list(exclude_archived=1)

See conversations.list for more info.

4.10 Getting a channel’s info

Once you have the ID for a specific channel, you can fetch information about that channel.

response = client.conversations_info(channel="C0XXXXXXX")

See conversations.info for more info.

4.11 Joining a channel

Channels are the social hub of most Slack teams. Here’s how you hop into one:

response = client.conversations_join(channel="C0XXXXXXY")

4.9. Listing public channels 15

Page 22: python-slackclient Documentation

python-slackclient Documentation, Release 1.0.1

If you are already in the channel, the response is slightly different. already_in_channel will be true, and alimited channel object will be returned. Bot users cannot join a channel on their own, they need to be invited byanother user.

See conversations.join for more info.

4.12 Leaving a channel

Maybe you’ve finished up all the business you had in a channel, or maybe you joined one by accident. This is howyou leave a channel.

response = client.conversations_leave(channel="C0XXXXXXX")

See conversations.leave for more info.

4.13 Listing team members

response = client.users_list()users = response["members"]user_ids = list(map(lambda u: u["id"], users))

See users.list for more info.

4.14 Uploading files

response = client.files_upload(channels="C3UKJTQAC",file="files.pdf",title="Test upload"

)

See files.upload for more info.

4.15 Calling any API methods

This library covers all the public endpoints as the methods in WebClient. That said, you may see a bit delay of thelibrary release. When you’re in a hurry, you can directly use api_call method as below.

16 Chapter 4. Basic Usage

Page 23: python-slackclient Documentation

python-slackclient Documentation, Release 1.0.1

import osfrom slack import WebClient

client = WebClient(token=os.environ['SLACK_API_TOKEN'])response = client.api_call(

api_method='chat.postMessage',json={'channel': '#random','text': "Hello world!"}

)assert response["message"]["text"] == "Hello world!"

4.16 Web API Rate Limits

When posting messages to a channel, Slack allows applications to send no more than one message per channel persecond. We allow bursts over that limit for short periods. However, if your app continues to exceed the limit over alonger period of time it will be rate limited. Different API methods have other rate limits – be sure to check the limitsand test that your application has a graceful fallback if it should hit those limits.

If you go over these limits, Slack will start returning a HTTP 429 Too Many Requests error, a JSON object containingthe number of calls you have been making, and a Retry-After header containing the number of seconds until you canretry.

Here’s a very basic example of how one might deal with rate limited requests.

import osimport timefrom slack import WebClientfrom slack.errors import SlackApiError

client = WebClient(token=os.environ["SLACK_API_TOKEN"])

# Simple wrapper for sending a Slack messagedef send_slack_message(channel, message):return client.chat_postMessage(channel=channel,text=message

)

# Make the API call and save results to `response`channel = "#random"message = "Hello, from Python!"# Do until being rate limitedwhile True:

try:response = send_slack_message(channel, message)

except SlackApiError as e:if e.response.status_code == 429:

# The `Retry-After` header will tell you how long to wait before retryingdelay = int(e.response.headers['Retry-After'])print(f"Rate limited. Retrying in {delay} seconds")time.sleep(delay)response = send_slack_message(channel, message)

else:# other errorsraise e

4.16. Web API Rate Limits 17

Page 24: python-slackclient Documentation

python-slackclient Documentation, Release 1.0.1

See the documentation on Rate Limiting for more info.

18 Chapter 4. Basic Usage

Page 25: python-slackclient Documentation

CHAPTER 5

Conversations API

The Slack Conversations API provides your app with a unified interface to work with all the channel-like thingsencountered in Slack; public channels, private channels, direct messages, group direct messages, and our newestchannel type, Shared Channels.

See Conversations API docs for more info.

5.1 Direct messages

The conversations_open method opens either a 1:1 direct message with a single user or a a multi-person directmessage, depending on the number of users supplied to the users parameter.

For public or private channels, use the ‘‘conversations_create‘‘ method.

Provide a users parameter as an array with 1 to 8 user IDs to open or resume a conversation. Providing only 1 IDwill create a direct message. Providing more will create a new multi-party DM or resume an existing conversation.

Subsequent calls to conversations_open with the same set of users will return the already existing conversation.

import osfrom slack import WebClient

client = WebClient(token=os.environ["SLACK_API_TOKEN"])response = client.conversations_open(users=["W123456789", "U987654321"])

See conversations.open additional info.

19

Page 26: python-slackclient Documentation

python-slackclient Documentation, Release 1.0.1

5.2 Creating channels

Creates a new channel, either public or private. The name parameter is required, may contain numbers, letters,hyphens, and underscores, and must contain fewer than 80 characters. To make the channel private, set the optionis_private parameter to True.

import osfrom slack import WebClientfrom time import time

client = WebClient(token=os.environ["SLACK_API_TOKEN"])channel_name = f"my-private-channel-{round(time())}"response = client.conversations_create(

name=channel_name,is_private=True

)channel_id = response["channel"]["id"]response = client.conversations_archive(channel=channel_id)

See conversations.create additional info.

5.3 Getting more information

To retrieve a set of metadata about a channel (public, private, DM, or multi-party DM), use conversations_info.The channel parameter is required and must be a valid channel ID. The optional include_locale booleanparameter will return locale data, which may be useful if you wish to return localized responses. Theinclude_num_members boolean parameter will return the number of people in a channel.

import osfrom slack import WebClient

client = WebClient(token=os.environ["SLACK_API_TOKEN"])response = client.conversations_info(

channel="C031415926",include_num_members=1

)

See conversations.info for more info.

5.4 Listing conversations

To get a list of all the conversations in a workspace, use conversations_list. By default, only public conversa-tions are returned; use the types parameter specify which types of conversations you’re interested in (Note: typesis a string of comma-separated values)

import osfrom slack import WebClient

client = WebClient(token=os.environ["SLACK_API_TOKEN"])

(continues on next page)

20 Chapter 5. Conversations API

Page 27: python-slackclient Documentation

python-slackclient Documentation, Release 1.0.1

(continued from previous page)

response = client.conversations_list()conversations = response["channels"]

Use the types parameter to request additional channels, including public_channel, private_channel,mpim, and im. This parameter is a string of comma-separated values.

import osfrom slack import WebClient

client = WebClient(token=os.environ["SLACK_API_TOKEN"])response = client.conversations_list(

types="public_channel, private_channel")

See conversations.list for more info.

5.5 Leaving a conversation

To leave a conversation, use conversations_leave with the required channel param containing the ID of thechannel to leave.

import osfrom slack import WebClient

client = WebClient(token=os.environ["SLACK_API_TOKEN"])response = client.conversations_leave(channel="C27182818")

See conversations.leave for more info.

5.6 Getting members

To get a list of the members of a conversation, use conversations_members with the required channel pa-rameter.

import osfrom slack import WebClient

client = WebClient(token=os.environ["SLACK_API_TOKEN"])response = client.conversations_members(channel="C16180339")user_ids = response["members"]

See conversations.members for more info.

5.5. Leaving a conversation 21

Page 28: python-slackclient Documentation

python-slackclient Documentation, Release 1.0.1

22 Chapter 5. Conversations API

Page 29: python-slackclient Documentation

CHAPTER 6

Real Time Messaging (RTM)

The Real Time Messaging (RTM) API is a WebSocket-based API that allows you to receive events from Slack in realtime and send messages as users.

If you prefer events to be pushed to your app, we recommend using the HTTP-based Events API instead. The EventsAPI contains some events that aren’t supported in the RTM API (like app_home_opened event), and it supports mostof the event types in the RTM API. If you’d like to use the Events API, you can use the Python Slack Events Adaptor.

The RTMClient allows apps to communicate with the Slack Platform’s RTM API.

The event-driven architecture of this client allows you to simply link callbacks to their corresponding events. Whenan event occurs this client executes your callback while passing along any information it receives. We also give youthe ability to call our web client from inside your callbacks.

In our example below, we watch for a message event that contains “Hello” and if its received, we call thesay_hello() function. We then issue a call to the web client to post back to the channel saying “Hi” to theuser.

6.1 Configuring the RTM API

Events using the RTM API must use a classic Slack app (with a plain bot scope).

If you already have a classic Slack app, you can use those credentials. If you don’t and need to use the RTM API, youcan create a classic Slack app. You can learn more in the API documentation.

Also, even if the Slack app configuration pages encourage you to upgrade to the newer permission model, don’tupgrade it and keep using the “classic” bot permission.

6.2 Connecting to the RTM API

23

Page 30: python-slackclient Documentation

python-slackclient Documentation, Release 1.0.1

import osfrom slack import RTMClient

@RTMClient.run_on(event="message")def say_hello(**payload):data = payload['data']web_client = payload['web_client']

if 'Hello' in data['text']:channel_id = data['channel']thread_ts = data['ts']user = data['user'] # This is not username but user ID (the format is either U***

→˓or W***)

web_client.chat_postMessage(channel=channel_id,text=f"Hi <@{user}>!",thread_ts=thread_ts

)

slack_token = os.environ["SLACK_API_TOKEN"]rtm_client = RTMClient(token=slack_token)rtm_client.start()

6.3 rtm.start vs rtm.connect

By default, the RTM client uses rtm.connect to establish a WebSocket connection with Slack. The responsecontains basic information about the team and WebSocket url.

If you’d rather use rtm.start to establish the connection, which provides more information about the conversationsand users on the team, you can set the connect_method option to rtm.startwhen instantiating the RTM Client.Note that on larger teams, use of rtm.start can be slow and unreliable.

import osfrom slack import RTMClient

@RTMClient.run_on(event="message")def say_hello(**payload):data = payload['data']web_client = payload['web_client']if 'text' in data and 'Hello' in data['text']:channel_id = data['channel']thread_ts = data['ts']user = data['user'] # This is not username but user ID (the format is either U***

→˓or W***)

web_client.chat_postMessage(channel=channel_id,text=f"Hi <@{user}>!",thread_ts=thread_ts

)

slack_token = os.environ["SLACK_API_TOKEN"]rtm_client = RTMClient(

token=slack_token,

(continues on next page)

24 Chapter 6. Real Time Messaging (RTM)

Page 31: python-slackclient Documentation

python-slackclient Documentation, Release 1.0.1

(continued from previous page)

connect_method='rtm.start')rtm_client.start()

Read the rtm.connect docs and the rtm.start docs for more details.

6.4 RTM Events

{'type': 'message','ts': '1358878749.000002','user': 'U023BECGF','text': 'Hello'

}

See RTM Events for a complete list of events.

6.4. RTM Events 25

Page 32: python-slackclient Documentation

python-slackclient Documentation, Release 1.0.1

26 Chapter 6. Real Time Messaging (RTM)

Page 33: python-slackclient Documentation

CHAPTER 7

Frequently Asked Questions

7.1 I cannot install slackclient. . .

We recommend using virtualenv (venv) to set up your Python runtime.

# Create a dedicated virtual env for running your Python scriptspython -m venv env

# Run env\Scripts\activate on Windows OSsource env/bin/activate

# Install slackclient PyPI packagepip install "slackclient>=2.0"

# Set your token as an env variable (`set` command for Windows OS)export SLACK_API_TOKEN=xoxb-***

Then, verify the following code works on the Python REPL (you can start it by just python).

import osimport loggingfrom slack import WebClientlogging.basicConfig(level=logging.DEBUG)client = WebClient(token=os.environ["SLACK_API_TOKEN"])res = client.api_test()

If you encounter an error saying AttributeError: module 'slack' has no attribute'WebClient', run pip list. If you find both slackclient and slack in the output, try removingslack by pip uninstall slack and reinstalling slackclient.

7.2 Should I go with run_async?

For most cases, we recommend going with run_async=False mode. So, the default is False.

27

Page 34: python-slackclient Documentation

python-slackclient Documentation, Release 1.0.1

If your application turns run_async on, the app should follow right and efficient ways to use asyncio’s non-blockingevent loops and aiohttp. Also, consider using async frameworks and their appropriate runtime. Running event loopsalong with Flask or similar may not be a good fit.

If you have to simultaneously run WebClient with run_async=True outside an event loop for some reason,sharing a single WebClient instance doesn’t work for you. Create an instance every time you run the code. Therun_async=False mode doesn’t have such issues.

7.3 I found a bug!

That’s great! Thank you. Let us know on the Issue Tracker. If you’re feeling particularly ambitious, why not submit apull request with a bug fix?

7.4 There’s a feature missing!

There’s always something more that could be added! You can let us know in the Issue Tracker to start a discussionaround the proposed feature, that’s a good start. If you’re feeling particularly ambitious, why not write the featureyourself, and submit a pull request! We love feedback and we love help and we don’t bite. Much.

7.5 How do I contribute?

What an excellent question. First of all, please have a look at our general contributing guidelines.

All done? Great! While we’re super excited to incorporate your new feature, there are a couple of things we want tomake sure you’ve given thought to.

• Please write unit tests for your new code. But don’t just aim to increase the test coverage, rather, we expectyou to have written thoughtful tests that ensure your new feature will continue to work as expected, and to helpfuture contributors to ensure they don’t break it!

• Please document your new feature. Think about concrete use cases for your feature, and add a section to theappropriate document, including a complete sample program that demonstrates your feature. Don’t forget toupdate the changelog in changelog.rst!

Including these two items with your pull request will totally make our day—and, more importantly, your future users’days!

On that note. . .

7.6 How do I compile the documentation?

This project’s documentation is generated with Sphinx. If you are editing one of the many reStructuredText files inthe docs-src folder, you’ll need to rebuild the documentation. It is recommended to run the following steps insidea virtualenv environment.

tox -e docs

Do be sure to add the docs folder and its contents to your pull request!

28 Chapter 7. Frequently Asked Questions

Page 35: python-slackclient Documentation

CHAPTER 8

Changelog

8.1 v3.0.0 (2020-11-09)

This is the first stable version of slack_sdk v3. The remarkable updates in this major version are:

• Newly added OAuth flow support

• Better Async/sync separation for WebClient and WebhookClient

• Renamed packages (from slack to slack_sdk) with deprecation warnings

Refer to v3.0.0 milestone and the website for details. If you’re a slackclient user, the migration guide for slackclientv2.x users is available at https://slack.dev/python-slack-sdk/v3-migration/

8.2 v2.9.3 (2020-10-20)

Refer to v2.9.3 milestone to know the complete list of the issues resolved by this release.

Updates

1. [Block Kit] #851 #852 Set default_type for HeaderBlock text - Thanks @fwump38

2. [Block Kit] #853 #854 Enable to use input blocks in Home tab views - Thanks @fwump38

3. [RTMClient] #857 #846 RTMClient does not pass timeout value to WebClient - Thanks @Luden @seratch

8.3 v2.9.2 (2020-10-09)

Refer to v2.9.2 milestone to know the complete list of the issues resolved by this release.

Updates

1. [Block Kit] #841 Dispatch Action in Input blocks - Thanks @seratch

29

Page 36: python-slackclient Documentation

python-slackclient Documentation, Release 1.0.1

2. [WebClient] #838 Add apps.event.authorizations.list and other APIs - Thanks @seratch

3. [WebClient][WebhookClient] #829 Improve error body parser to handle no charset responses - Thanks @adam-chainz @seratch

4. [Block Kit] #824 Correct text field validation in Header blocks - Thanks @seratch

8.4 v2.9.1 (2020-09-23)

Refer to v2.9.1 milestone to know the complete list of the issues resolved by this release.

Updates

1. [WebClient][WebhookClient] #820 #821 #822 The proxy option in WebClient/WebhookClient no longer works- Thanks @seratch

8.5 v2.9.0 (2020-09-17)

Refer to v2.9.0 milestone to know the complete list of the issues resolved by this release.

Updates

1. [WebClient] #811 Add workflows.* API support - Thanks @misscoded

2. [WebClient] #810 #809 Only set default filename in files_upload if file is an instance of str - Thanks @csaska

8.6 v2.8.2 (2020-09-04)

Refer to v2.8.2 milestone to know the complete list of the issues resolved by this release.

Updates

1. [WebClient] #795 #794 Add admin.conversations.* API methods in WebClient/AsyncWebClient - Thanks @ru-berVulpes

2. [WebClient] #796 Fix a link to the Static options documentation - Thanks @Jamim

8.7 v2.8.1 (2020-08-28)

Refer to v2.8.1 milestone to know the complete list of the issues resolved by this release.

Updates

1. [WebClient] #778 #779 Adding support for View objects for views.push/update/publish - Thanks @ruberVulpes

2. [WebClient] #786 Fix admin.conversations.restrictAccess.* methods to match documentation - Thanks @ru-berVulpes

30 Chapter 8. Changelog

Page 37: python-slackclient Documentation

python-slackclient Documentation, Release 1.0.1

8.8 v2.8.0 (2020-08-06)

Refer to v2.8.0 milestone to know the complete list of the issues resolved by this release.

New Features

1. [WebClient] #765 #766 Introduce AsyncWebClient/AsyncWebhookClient providing coroutines - Thanks @ser-atch

2. [Block Kit] #767 #768 Add “header” block support - Thanks @mwbrooks

Updates

1. [WebClient] #738 Add HTTP_PROXY, HTTPS_PROXY env variable support in async WebClient - Thanks@iamtofr @seratch

2. [WebClient] #769 #773 Enable User-Agent to have additional info part - Thanks @seratch

3. [WebClient] #770 #771 Fix a bug where files.upload’s file param doesn’t accept bytes data - Thanks@seratch

8.9 v2.7.3 (2020-07-20)

Refer to v2.7.3 milestone to know the complete list of the issues resolved by this release.

Updates

1. [WebClient] #754 Fix #729 Add admin.conversations.restrictAccess.*, conversations.mark API - Thanks @ru-berVulpes @kian2attari

2. [WebClient] #758 Fix #757 Add admin.usergroups.addTeams, calls.participants.remove API - Thanks @seratch

3. [WebClient] #727 Fix #645 Unclosed client session - Thanks @NoAnyLove @jourdanrodrigues

4. [WebClient] #745 Fix #744 a validation logic bug in DatePickerElement - Thanks @dzudi941

5. [WebClient] #752 Fix #733 Better error handling when getting TimeoutError in RTMClient#start() - Thanks@liorblob @seratch

6. [WebClient] #751 Fix #718 by handling unexpected response body format - Thanks @jeffbuswell @seratch

8.10 v2.7.2 (2020-06-23)

Refer to v2.7.2 milestone to know the complete list of the issues resolved by this release.

Updates

1. [WebClient] Fix #728 by adding bytearray support in files_upload (sync mode) - Thanks @sofya-salmanova@seratch

2. [WebClient] #726 Fix InputBlock.hint validation failure - Thanks @jourdanrodrigues

3. [WebClient] #723 Correct the default value of InputBlock.label, hint - Thanks @jourdanrodrigues

8.8. v2.8.0 (2020-08-06) 31

Page 38: python-slackclient Documentation

python-slackclient Documentation, Release 1.0.1

8.11 v2.7.1 (2020-06-04)

This release includes the fixes for regression bugs in WebClient since v2.6.0. Refer to v2.7.1 milestone to know thecomplete list of the issues resolved by this release.

Updates

1. [WebClient] #716 #712 Support timeout in sync sync web clients - Thanks @DanialErfanian @seratch

2. [WebClient] #713 Support custom SSL context in sync sync web clients - Thanks @austinbutler

3. [WebClient] #715 #714 Support proxy in sync sync web clients - Thanks @austinbutler @seratch

8.12 v2.7.0 (2020-06-02)

Refer to v2.7.0 milestone to know the complete list of the issues resolved by this release.

New Features

1. [WebhookClient] #707 #270 #531 Add WebhookClient for Incoming Webhooks & response_url - Thanks @ser-atch @chubz @Ambro17

Updates

1. [WebClient] #704 #695 Add calls_* methods to WebClient and CallBlock in Block Kit classes - Thanks @ser-atch

2. [WebClient] #710 #536 Allow Tokens to be specified per request - Thanks @seratch

3. [WebClient] #709 #708 Add default_to_current_conversation in conversations_select elements - Thanks @ser-atch

8.13 v2.6.2 (2020-05-28)

Refer to v2.6.2 milestone to know the complete details of this release.

Updates

1. [WebClient] #705 WebClient’s paginated API calls may fail with no params - Thanks @seratch

8.14 v2.6.1 (2020-05-24)

This patch release is a quick fix for #701, a major issue that affected RTMClient users in v2.6.0. The malfunctionwas introduced by #667 trying to address #558 #619. Those issues were reopened and will be resolved by anotherapproach. Refer to v2.6.1 milestone to know the complete list of the issues resolved by this release.

Updates

1. [RTMClient] #701 RTMClient drops some messages when they come in rapid succession - Thanks @pbrackin@seratch

32 Chapter 8. Changelog

Page 39: python-slackclient Documentation

python-slackclient Documentation, Release 1.0.1

8.15 v2.6.0 (2020-05-21)

Refer to v2.6.0 milestone to know the complete list of the issues resolved by this release.

New Features

1. [Block Kit] #659 Add complete supports for Block Kit components and fixed a few existing bugs as well(#500 #519 #623 #632 #635 #639 #676 #699) - Thanks @seratch @diurnalist @ruberVulpes @jeremyschulman@e271828- @RodneyU215

2. [Signature] #686 Add slack.signature.SignatureVerifier for request verification - Thanks @seratch

3. [WebClient] #682 Add missing Grid admin APIs (admin.usergroups.*, admin.users.*, admin.apps.*) - Thanks@stevengill @seratch

Updates

1. [WebClient][RTMClient] Fixed a bunch of the currency issues this SDK had (#429 #463 #492 #497 #530 #569#605 #613 #626 #630 #631 #633 #669) - Thanks @seratch @aaguilartablada @aoberoi @stevengill @mar-shallino16

2. [WebClient] #681 #560 Enable using bool values for request parameters - Thanks @roman-kachanovsky @ser-atch

3. [WebClient] #661 #678 Improve handling of required “ids” parameters (e.g., channel_ids, users) - Thanks @ser-atch

4. [WebClient] #680 Add non-conversation API deprecation warnings - Thanks @seratch

5. [WebClient] #671 #670 Enable passing None values for request parameters (they used to result in errors) -Thanks @yuji38kwmt @seratch

6. [WebClient] #673 Fix #672 files.upload fails with a filepath containing multi byte chars - Thanks @yuji38kwmt@seratch

7. [WebClient] #656 Fix #594 preview_image for files.remote.add API method is not properly supported - Thanks@Eothred @seratch

8. [Maintenance] #618 Add py.typed file to package distribution - Thanks @JKillian

9. [WebClient] #599 Strip token string parameters of whitespace - Thanks @TheFrozenFire

10. [WebClient] #692 Fix superfluous_charset warnings since v2.4.0 - Thanks @seratch

11. [WebClient] #652 Update oauth_v2_access to include redirect_uri (as optional) - Thanks @tomasreimers

8.16 v2.5.0 (2019-12-09)

New Features

1. [WebClient] Adding new oauth.v2.access Web API method. #577

8.17 v2.4.0 (2019-11-27)

New Features

1. [WebClient] Adding new admin.* Web API methods. #571

8.15. v2.6.0 (2020-05-21) 33

Page 40: python-slackclient Documentation

python-slackclient Documentation, Release 1.0.1

Updates 1. [WebClient] We’re no longer validating token types for Web API methods. Improves compatibility withgranular bot permissions. #568 (Thanks @Smotko) 2. [WebClient] Correcting typos in descriptions #554 (Thanks@phamk) 3. [WebClient] Fixed ‘iteracting’ typo in library file headers #564 (Thanks @acabey) 4. [Message Builders]Remove value from LinkButtonElement #563 (Thanks @pedroma)

8.18 v2.3.1 (2019-10-29)

Updates

1. [WebClient] Fixing a regression that causes the client to close sessions prematurely. #544 (Thanks @fatih-acar!)

2. [WebClient] Adding required missing view param to views.update Web API method. #542

8.19 v2.3.0 (2019-10-22)

New Features

1. [WebClient] Adding new views.publish Web API method. #540

Updates

1. [WebClient] Some server responses don’t return json. Correcting initial assumption. #540

2. [Maintenance] Add py.typed to mark the library to support type hinting #524s

8.20 v2.2.1 (2019-10-08)

Updates

1. [Docs] Fix Indentation of Code Snippets in README.md #525 (Thanks @abhishekjiitr)

2. [WebClient] Fix Web Client custom iterator #521 (Thanks @smaeda-ks)

3. [WebClient] Oauth previously failed to pass along credentials properly. This is fixed now. #527

4. [WebClient] When a SlackApiError occurs we’re now passing the entire SlackResponse into the exception. #527

8.21 v2.2.0 (2019-09-25)

New Features

1. [WebClient] Adding new admin and remote files API methods. #501

2. [WebClient] Adding new view API methods. #517

Updates

1. [Message Builders] Update BlockAttachment to not send invalid JSON due to fields attribute #473 (Thanks@paul-griffith)

2. [Docs] Add RTM section for docs v2 #477 (Thanks @shanedewael)

3. [Docs] Fix typo; recieved -> received #478 (Thanks @joakimnordling)

4. [Docs] Fix block kit link & update docs #484 (Thanks @clavin)

34 Chapter 8. Changelog

Page 41: python-slackclient Documentation

python-slackclient Documentation, Release 1.0.1

5. [RTMClient] Return callback from RTMClient.run_on #490 (Thanks @clavin)

6. [Docs] Fix link to Auth Guide in readme #498 (Thanks @asherf)

7. [Docs] Fix missing word and typo #512 (Thanks @marks)

8. [Message Builders] bugfix for value length in button elements #514 (Thanks @avanderm)

9. [Docs] Fixes formatting #515 (Thanks @vpetersson)

10. [Docs] Improve a code snippet on README #516 (Thanks @seratch)

11. [WebClient] Fixed an OAuth Headers bug and made the token param optional. #517

8.22 v2.1.0 (2019-07-01)

New Features

1. Type-hinted helper classes for building messages in v2 #400 (Thanks @paul-griffith)

Breaking Changes

1. [RTMClient] Converted the RTMClient#typing() function to async #446

Updates

1. [RTMClient] Handle case in which aiohttp closes the websocket due to lack of ping responses. #453 (Thanks@flyte)

2. Modify package identifier in user agent to match v1.x identifier #418 (Thanks @aoberoi)

3. [WebClient] Fixed typo in Scheduled message #428 & #435 (Thanks @splinterific)

4. Transform install_requires of ‘aiodns’ into extras_require. #440 (Thanks @staticdev)

Thank you!! To everyone who’s opened, commented or reacted to an issue; this project is better because of you!Thank you for helping the Slack community!

8.23 v2.0.0 (2019-04-29)

Original RFC

v2 PR

New Features

1. Client Decomposition: We’ve split the client into two.

a. WebClient: A HTTP client focused on Slack’s Web API.

b. RTMClient: A websocket client focused on Slack’s RTM API.

2. RTMClient: Completely redesigned, this client allows you to link your application’s callbacks to correspondingSlack events.

3. WebClient: The WebClient now provides built-in methods for Slack’s Web API. These methods act as helpersenabling you to focus less on how the request is constructed. Here are a few things that this provides:

a. Basic information about each method through the docstring.

b. Easy File Uploads: You can now pass in the location of a file and the library will handle opening and retrievingthe file object to be transmitted.

8.22. v2.1.0 (2019-07-01) 35

Page 42: python-slackclient Documentation

python-slackclient Documentation, Release 1.0.1

c. Token type validation: This gives you better error messaging when you’re attempting to consume an api methodthat your token doesn’t have access to.

d. Constructs requests using Slack’s preferred HTTP methods and content-types.

Breaking Changes: If you’re migrating from v1.x of slackclient to v2.x, Please follow our migration guide to ensureyour app continues working after updating.

Check out the Migration Guide here!

Thank you! This release would not have been possible without the support of our community. Thank you to everyonewho’s contributed to this release.

8.24 v1.3.1 (2019-02-28)

• Lock websocket-client version to < 0.55.0: temp fix for #385

8.25 v1.3.0 (2018-09-11)

## New Features - Adds support for short lived tokens and automatic token refresh #347 (Thanks @roach!)

## Other - update RTM rate limiting comment and error message #308 (Thanks @benoitlavigne!) - Use logginginstead of traceback #309 (Thanks @harlowja!) - Remove Python 3.3 from test environments #346 (Thanks @roach!)- Enforced linting when using VSCode. #347 (Thanks @roach!)

8.26 v1.2.1 (2018-03-26)

• Added rate limit handling for rtm connections (thanks @jayalane!)

8.27 v1.2.0 (2018-03-20)

• You can now tell the RTM client to automatically reconnect by passing auto_reconnect=True

8.28 v1.1.3 (2018-03-01)

• Fixed another API param encoding bug. It encodes things properly now.

8.29 v1.1.2 (2018-01-31)

• Fixed an encoding issue which was encoding some Web API params incorrectly (sorry)

36 Chapter 8. Changelog

Page 43: python-slackclient Documentation

python-slackclient Documentation, Release 1.0.1

8.30 v1.1.1 (2018-01-30)

• Adds HTTP response headers to api_call responses to expose things like rate limit info

• Moves token into auth header rather than request params

8.31 v1.1.0 (2017-11-21)

• Aadds new SlackClientError and ResponseParseError types to describe errors - thanks @aoberoi!

• Fix Build Error (#245) - thanks @stasfilin!

• include email as user property (#173) - thanks @acaire!

• Add http reply into slack login and slack connection error (#216) - thanks @harlowja!

• Removed unused exception class (#233)

• Fix rtm_send_message bug (#225) - thanks @kt5356!

• Allow use of custom parameters on rtm_connect() (#210) - thanks @kamushadenes!

• Fix link to rtm.connect docs (#223) - @sampart!

8.32 v1.0.9 (2017-08-31)

• Fixed rtm_send_message ID bug introduced in 1.0.8

8.33 v1.0.8 (2017-08-31)

• Added rtm.connect support

8.34 v1.0.7 (2017-08-02)

• Fixes an issue where connecting over RTM to large teams may result in “Websocket URL expired” errors

• A load of packaging improvements

8.35 v1.0.6 (2017-06-12)

• Added proxy support (thanks @timfeirg!)

• Tidied up docs (thanks @schlueter!)

• Added tox settings for Python 3 testing (thanks @cclauss!)

8.30. v1.1.1 (2018-01-30) 37

Page 44: python-slackclient Documentation

python-slackclient Documentation, Release 1.0.1

8.36 v1.0.5 (2017-01-23)

• Allow RTM Channel.send_message to reply to a thread

• Index users by ID instead of Name (non-breaking change)

• Added timeout to api calls.

• Fixed a typo about token access in auth.rst, thanks @kelvintaywl!

• Added Message Threads to the docs

8.37 v1.0.4 (2016-12-15)

• fixed the ability to search for a user by ID

8.38 v1.0.3 (2016-12-13)

• fixed an issue causing RTM connections to fail for large teams

8.39 v1.0.2 (2016-09-22)

• removed unused ping counter

• fixed contributor guidelines links

• updated documentation

• Fix bug preventing API calls requiring a file ID

• Removes files from api_calls before JSON encoding, so the request is properly formatted

8.40 v1.0.1 (2016-03-25)

• fix for __eq__ comparison in channels using ‘#’ in channel name

• added copyright info to the LICENSE file

8.41 v1.0.0 (2016-02-28)

• the api_call function now returns a decoded JSON object, rather than a JSON encoded string

• some api_call calls now call actions on the parent server object: - im.open - mpim.open, groups.create, groups.createChild - channels.create, channels.join‘

38 Chapter 8. Changelog

Page 45: python-slackclient Documentation

python-slackclient Documentation, Release 1.0.1

8.42 v0.18.0 (2016-02-21)

• Moves to use semver for versioning

• Adds support for private groups and MPDMs

• Switches to use requests instead of urllib

• Gets Travis CI integration working

• Fixes some formatting issues so the code will work for python 2.6

• Cleans up some unused imports, some PEP-8 fixes and a couple bad default args fixes

8.43 v0.17.0 (2016-02-15)

• Fixes the server so that it doesn’t add duplicate users or channels to its internal lists, https://github.com/slackapi/python-slackclient/commit/0cb4bcd6e887b428e27e8059b6278b86ee661aaa

• README updates: - Updates the URLs pointing to Slack docs for configuring authentication,https://github.com/slackapi/python-slackclient/commit/7d01515cebc80918a29100b0e4793790eb83e7b9- s/channnels/channels, https://github.com/slackapi/python-slackclient/commit/d45285d2f1025899dcd65e259624ee73771f94bb

• Adds users to the local cache when they join the team, https://github.com/slackapi/python-slackclient/commit/f7bb8889580cc34471ba1ddc05afc34d1a5efa23

• Fixes urllib py 2/3 compatibility, https://github.com/slackapi/python-slackclient/commit/1046cc2375a85a22e94573e2aad954ba7287c886

8.42. v0.18.0 (2016-02-21) 39

Page 46: python-slackclient Documentation

python-slackclient Documentation, Release 1.0.1

40 Chapter 8. Changelog

Page 47: python-slackclient Documentation

CHAPTER 9

About

9.1 slackclient (Legacy Python Slack SDK)

Access the Slack Platform from your Python app. slackclient (Legacy Python Slack SDK) lets you build on the SlackWeb APIs pythonically.

slackclient (Legacy Python Slack SDK) is proudly maintained with by the Slack Developer Tools team

• License

• Code of Conduct

• Contributing

• Contributor License Agreement

41

Page 48: python-slackclient Documentation

python-slackclient Documentation, Release 1.0.1

42 Chapter 9. About

Page 49: python-slackclient Documentation

CHAPTER 10

Important Notice

The slackclient PyPI project is in maintenance mode now and slack-sdk project is the successor. The v3 SDK providesmore functionalities such as Socket Mode, OAuth flow module, SCIM API, Audit Logs API, better asyncio support,retry hanlders, and many more.

Refer to the migration guide to learn how to smoothly migrate your existing code.

10.1 slackclient (Legacy Python Slack SDK)

Slack’s APIs allow anyone to build full featured integrations that extend and expand the capabilities of your Slackworkspace. These APIs allow you to build applications that interact with Slack just like the people on your team –they can post messages, respond to events that happen – as well as build complex UIs for getting work done.

To make it easier for Python programmers to build Slack applications, we’ve provided this open source SDK. slack-client (Legacy Python Slack SDK) will let you get started building Python apps as quickly as possible. The currentversion, 2.0, is built for Python 3.6 and higher – if you need to target Python 2.x, you might consider using v1 of theSDK.

43

Page 50: python-slackclient Documentation

python-slackclient Documentation, Release 1.0.1

44 Chapter 10. Important Notice

Page 51: python-slackclient Documentation

CHAPTER 11

Slack Platform Basics

If you’re new to the Slack platform, we have a general purpose guide for building apps that isn’t specific to anylanguage or framework. It’s a great place to learn all about the concepts that go into building a great Slack app.

Before you get started building on the Slack platform, you need to set up your app’s configuration. This is where youdefine things like your app’s permissions and the endpoints that Slack should use for interacting with the backend youwill build with Python.

The app configuration page is also where you will acquire the OAuth token you will use to call Slack’s APIs. Treatthis token with care, just like you would a password, because it has access to workspace and can potentially read andwrite data to and from it.

45

Page 52: python-slackclient Documentation

python-slackclient Documentation, Release 1.0.1

46 Chapter 11. Slack Platform Basics

Page 53: python-slackclient Documentation

CHAPTER 12

Installation

We recommend using PyPI to install slackclient (Legacy Python Slack SDK)

pip install slackclient

Of course, you can always pull the source code directly into your project:

git clone https://github.com/slackapi/python-slackclient.git

And then, save a few lines of code as ./test.py.

# test.pyimport sys# Load the local source directlysys.path.insert(1, "./python-slackclient")# Enable debug loggingimport logginglogging.basicConfig(level=logging.DEBUG)# Verify it worksfrom slack import WebClientclient = WebClient()api_response = client.api_test()

You can run the code this way.

python test.py

It’s also good to try on the Python REPL.

47

Page 54: python-slackclient Documentation

python-slackclient Documentation, Release 1.0.1

48 Chapter 12. Installation

Page 55: python-slackclient Documentation

CHAPTER 13

Getting Help

If you get stuck, we’re here to help. The following are the best ways to get assistance working through your issue:

• Use our Github Issue Tracker for reporting bugs or requesting features.

• Visit the Slack Developer Community for getting help using slackclient (Legacy Python Slack SDK) or justgenerally bond with your fellow Slack developers.

49