GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — python-slackclient/docs/basic_usage.html at master · playjbook/python-slackclient Expand file tree/ Copy pathbasic_usage.htmlMore file actions 379 lines (336 loc) · 30.4 KB / Copy pathbasic_usage.htmlFile metadata and controls379 lines (336 loc) · 30.4 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Basic Usage — Slack Developer Kit for Python</title> <link rel="stylesheet" href="https://a.slack-edge.com/b143/style/plastic_helpers.css" type="text/css"/> <link rel="stylesheet" href="https://a.slack-edge.com/58b24/style/plastic_typography.css" type="text/css" /> <link rel="stylesheet" href="https://a.slack-edge.com/b900/style/plastic_layout.css" type="text/css" /> <link rel="stylesheet" href="https://a.slack-edge.com/2133/style/plastic_grid.css" type="text/css" /> <link rel="stylesheet" href="https://a.slack-edge.com/be9e/style/plastic_buttons.css" type="text/css" /> <link rel="stylesheet" href="https://a.slack-edge.com/1d9c/style/libs/lato-1-compressed.css" type="text/css" /> <link rel="stylesheet" href="./_static/default.css" type="text/css" /> <link rel="stylesheet" href="./_static/pygments.css" type="text/css" /> <link id="favicon" rel="shortcut icon" href="https://a.slack-edge.com/66f9/img/icons/favicon-32.png" type="image/png" /> <link rel="top" title="Slack Developer Kit for Python 1.0.1 documentation" href="index.html" /> </head> <body class="api light_theme"> <header> <a id="menu_toggle" class="no_transition show_on_mobile"> <span class="menu_icon"></span> <span class="vert_divider"></span> </a> <a href="https://api.slack.com/" id="header_logo" class="api hide_on_mobile" style="float:left; display: inline-block;"> <img alt="Slack API" src="https://a.slack-edge.com/ae57/img/slack_api_logo.png" style="width: 225px; padding-right: 25px; border-right: 1px solid #DDD;"/> </a> <span style="display: inline-block; padding-left: 20px; margin-top: 20px; font-weight: bold;"> <a style="color: #555459;" href="./index.html">Slack Developer Kit for Python</a> </span> <div class="header_nav"> <a href="https://github.com/SlackAPI/python-slackclient" class="btn header_btn float_right" data-qa="go_to_slack">Go to GitHub</a> </div> </header> <div id="page"> <div id="page_contents" class="clearfix"> <!-- Sidebar Content --> <nav id="api_nav" class="col span_1_of_4"> <div id="api_sections"> <ul class="current"> <li class="toctree-l1"><a class="reference internal" href="index.html">Slack Developer Kit for Python</a></li> <li class="toctree-l1"><a class="reference internal" href="auth.html">Tokens & Authentication</a><ul> <li class="toctree-l2"><a class="reference internal" href="auth.html#handling-tokens-and-other-sensitive-data">Handling tokens and other sensitive data</a></li> <li class="toctree-l2"><a class="reference internal" href="auth.html#test-tokens">Test Tokens</a></li> <li class="toctree-l2"><a class="reference internal" href="auth.html#the-oauth-flow">The OAuth flow</a></li> </ul> </li> <li class="toctree-l1 current"><a class="current reference internal" href="#">Basic Usage</a><ul> <li class="toctree-l2"><a class="reference internal" href="#sending-a-message">Sending a message</a></li> <li class="toctree-l2"><a class="reference internal" href="#replying-to-messages-and-creating-threads">Replying to messages and creating threads</a></li> <li class="toctree-l2"><a class="reference internal" href="#updating-the-content-of-a-message">Updating the content of a message</a></li> <li class="toctree-l2"><a class="reference internal" href="#deleting-a-message">Deleting a message</a></li> <li class="toctree-l2"><a class="reference internal" href="#adding-or-removing-an-emoji-reaction">Adding or removing an emoji reaction</a></li> <li class="toctree-l2"><a class="reference internal" href="#getting-a-list-of-channels">Getting a list of channels</a></li> <li class="toctree-l2"><a class="reference internal" href="#getting-a-channel-s-info">Getting a channel’s info</a></li> <li class="toctree-l2"><a class="reference internal" href="#joining-a-channel">Joining a channel</a></li> <li class="toctree-l2"><a class="reference internal" href="#leaving-a-channel">Leaving a channel</a></li> <li class="toctree-l2"><a class="reference internal" href="#get-a-list-of-team-members">Get a list of team members</a></li> </ul> </li> <li class="toctree-l1"><a class="reference internal" href="real_time_messaging.html">Real Time Messaging</a><ul> <li class="toctree-l2"><a class="reference internal" href="real_time_messaging.html#connecting-to-the-real-time-messaging-api">Connecting to the Real Time Messaging API</a></li> <li class="toctree-l2"><a class="reference internal" href="real_time_messaging.html#rtm-events">RTM Events</a></li> <li class="toctree-l2"><a class="reference internal" href="real_time_messaging.html#sending-messages-via-the-rtm-api">Sending messages via the RTM API</a></li> </ul> </li> <li class="toctree-l1"><a class="reference internal" href="faq.html">Frequently Asked Questions</a><ul> <li class="toctree-l2"><a class="reference internal" href="faq.html#what-even-is-product-name-and-why-should-i-care">What even is Slack Developer Kit for Python and why should I care?</a></li> <li class="toctree-l2"><a class="reference internal" href="faq.html#omg-i-found-a-bug">OMG I found a bug!</a></li> <li class="toctree-l2"><a class="reference internal" href="faq.html#hey-there-s-a-feature-missing">Hey, there’s a feature missing!</a></li> <li class="toctree-l2"><a class="reference internal" href="faq.html#i-d-like-to-contribute-but-how">I’d like to contribute...but how?</a></li> <li class="toctree-l2"><a class="reference internal" href="faq.html#how-do-i-compile-the-documentation">How do I compile the documentation?</a></li> </ul> </li> <li class="toctree-l1"><a class="reference internal" href="changelog.html">Changelog</a><ul> <li class="toctree-l2"><a class="reference internal" href="changelog.html#v1-0-5-2017-1-23">v1.0.5 (2017-1-23)</a></li> <li class="toctree-l2"><a class="reference internal" href="changelog.html#v1-0-4-2016-12-15">v1.0.4 (2016-12-15)</a></li> <li class="toctree-l2"><a class="reference internal" href="changelog.html#v1-0-3-2016-12-13">v1.0.3 (2016-12-13)</a></li> <li class="toctree-l2"><a class="reference internal" href="changelog.html#v1-0-2-2016-09-22">v1.0.2 (2016-09-22)</a></li> <li class="toctree-l2"><a class="reference internal" href="changelog.html#v1-0-1-2016-03-25">v1.0.1 (2016-03-25)</a></li> <li class="toctree-l2"><a class="reference internal" href="changelog.html#v1-0-0-2016-02-28">v1.0.0 (2016-02-28)</a></li> <li class="toctree-l2"><a class="reference internal" href="changelog.html#v0-18-0-2016-02-21">v0.18.0 (2016-02-21)</a></li> <li class="toctree-l2"><a class="reference internal" href="changelog.html#v0-17-2016-02-15">v0.17 (2016-02-15)</a></li> </ul> </li> <li class="toctree-l1"><a class="reference internal" href="about.html">About</a><ul> <li class="toctree-l2"><a class="reference internal" href="about.html#product-name">Slack Developer Kit for Python</a></li> </ul> </li> </ul> <div id="footer"> <ul id="footer_nav"> <li><a href="https://github.com/SlackAPI/python-slackclient/blob/master/LICENSE">License</a></li> <li><a href="https://github.com/SlackAPI/python-slackclient/blob/master/CODE_OF_CONDUCT.md">Code of Conduct</a></li> <li><a href="https://github.com/SlackAPI/python-slackclient/blob/master/CONTRIBUTING.md">Contributing</a></li> <li><a href="https://docs.google.com/a/slack-corp.com/forms/d/e/1FAIpQLSfzjVoCM7ohBnjWf7eDYQxzti1EPpinsIJQA5RAUBwJKRUQHg/viewform">Contributor License Agreement</a></li> </ul> <p id="footer_signature">Made with <i class="ts_icon ts_icon_heart"></i> by Slack<br/>and our Lovely Community </p> </div> </div> </nav> <!-- /Sidebar Content --> <!-- Body Content --> <div class="col span_3_of_4"> <div class="section-title">Basic Usage</div> <div class="card"> <div class="section" id="basic-usage"> <span id="web-api-examples"></span><h1>Basic Usage<a class="headerlink" href="#basic-usage" title="Permalink to this headline">¶</a></h1> <p>The Slack Web API allows you to build applications that interact with Slack in more complex ways than the integrations we provide out of the box.</p> <p>This package is a modular wrapper designed to make Slack <a class="reference external" href="https://api.slack.com/web">Web API</a> calls simpler and easier for your app. Provided below are examples of how to interact with commonly used API endpoints, but this is by no means a complete list. Review the full list of available methods <a class="reference external" href="https://api.slack.com/methods">here</a>.</p> <p>See <a class="reference internal" href="auth.html#handling-tokens"><span class="std std-ref">Tokens & Authentication</span></a> for API token handling best practices.</p> <hr class="docutils" /> <div class="section" id="sending-a-message"> <h2>Sending a message<a class="headerlink" href="#sending-a-message" title="Permalink to this headline">¶</a></h2> <p>The primary use of Slack is sending messages. Whether you’re sending a message to a user or to a channel, this method handles both.</p> <p>To send a message to a channel, use the channel’s ID. For IMs, use the user’s ID.</p> <div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">slackclient</span> <span class="kn">import</span> <span class="n">SlackClient</span> <span class="n">slack_token</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s2">"SLACK_API_TOKEN"</span><span class="p">]</span> <span class="n">sc</span> <span class="o">=</span> <span class="n">SlackClient</span><span class="p">(</span><span class="n">slack_token</span><span class="p">)</span> <span class="n">sc</span><span class="o">.</span><span class="n">api_call</span><span class="p">(</span> <span class="s2">"chat.postMessage"</span><span class="p">,</span> <span class="n">channel</span><span class="o">=</span><span class="s2">"#python"</span><span class="p">,</span> <span class="n">text</span><span class="o">=</span><span class="s2">"Hello from Python! :tada:"</span> <span class="p">)</span> </pre></div> </div> <p>There are some unique options specific to sending IMs, so be sure to read the <strong>channels</strong> section of the <a class="reference external" href="https://api.slack.com/methods/chat.postMessage#channels">chat.postMessage</a> page for a full list of formatting and authorship options.</p> </div> <hr class="docutils" /> <div class="section" id="replying-to-messages-and-creating-threads"> <h2>Replying to messages and creating threads<a class="headerlink" href="#replying-to-messages-and-creating-threads" title="Permalink to this headline">¶</a></h2> <p>Threaded messages are just like regular messages, except thread replies are grouped together to provide greater context to the user. You can reply to a thread or start a new threaded conversation by simply passing the original message’s <code class="docutils literal"><span class="pre">ts</span></code> ID in the <code class="docutils literal"><span class="pre">thread_ts</span></code> attribute when posting a message. If you’re replying to a threaded message, you’ll pass the <cite>thread_ts</cite> ID of the message you’re replying to.</p> <p>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 appear directly in the channel, instead relegated to a kind of forked timeline descending from the parent message.</p> <div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">slackclient</span> <span class="kn">import</span> <span class="n">SlackClient</span> <span class="n">slack_token</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s2">"SLACK_API_TOKEN"</span><span class="p">]</span> <span class="n">sc</span> <span class="o">=</span> <span class="n">SlackClient</span><span class="p">(</span><span class="n">slack_token</span><span class="p">)</span> <span class="n">sc</span><span class="o">.</span><span class="n">api_call</span><span class="p">(</span> <span class="s2">"chat.postMessage"</span><span class="p">,</span> <span class="n">channel</span><span class="o">=</span><span class="s2">"#python"</span><span class="p">,</span> <span class="n">text</span><span class="o">=</span><span class="s2">"Hello from Python! :tada:"</span><span class="p">,</span> <span class="n">thread_ts</span><span class="o">=</span><span class="s2">"1476746830.000003"</span> <span class="p">)</span> </pre></div> </div> <p>By default, <code class="docutils literal"><span class="pre">reply_broadcast</span></code> is set to <code class="docutils literal"><span class="pre">False</span></code>. To indicate your reply is germane to all members of a channel, set the <code class="docutils literal"><span class="pre">reply_broadcast</span></code> boolean parameter to <code class="docutils literal"><span class="pre">True</span></code>.</p> <div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">slackclient</span> <span class="kn">import</span> <span class="n">SlackClient</span> <span class="n">slack_token</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s2">"SLACK_API_TOKEN"</span><span class="p">]</span> <span class="n">sc</span> <span class="o">=</span> <span class="n">SlackClient</span><span class="p">(</span><span class="n">slack_token</span><span class="p">)</span> <span class="n">sc</span><span class="o">.</span><span class="n">api_call</span><span class="p">(</span> <span class="s2">"chat.postMessage"</span><span class="p">,</span> <span class="n">channel</span><span class="o">=</span><span class="s2">"#python"</span><span class="p">,</span> <span class="n">text</span><span class="o">=</span><span class="s2">"Hello from Python! :tada:"</span><span class="p">,</span> <span class="n">thread_ts</span><span class="o">=</span><span class="s2">"1476746830.000003"</span><span class="p">,</span> <span class="n">reply_broadcast</span><span class="o">=</span><span class="bp">True</span> <span class="p">)</span> </pre></div> </div> <p><strong>Note:</strong> While threaded messages may contain attachments and message buttons, when your reply is broadcast to the channel, it’ll actually be a reference to your reply, not the reply itself. So, when appearing in the channel, it won’t contain any attachments or message buttons. Also note that updates and deletion of threaded replies works the same as regular messages.</p> <p>See the <a class="reference external" href="https://api.slack.com/docs/message-threading#forking_conversations">Threading messages together</a> article for more information.</p> </div> <hr class="docutils" /> <div class="section" id="updating-the-content-of-a-message"> <h2>Updating the content of a message<a class="headerlink" href="#updating-the-content-of-a-message" title="Permalink to this headline">¶</a></h2> <p>Let’s say you have a bot which posts the status of a request. When that request is updated, you’ll want to update the message to reflect it’s state. Or your user might want to fix a typo or change some wording. This is how you’ll make those changes.</p> <div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">slackclient</span> <span class="kn">import</span> <span class="n">SlackClient</span> <span class="n">slack_token</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s2">"SLACK_API_TOKEN"</span><span class="p">]</span> <span class="n">sc</span> <span class="o">=</span> <span class="n">SlackClient</span><span class="p">(</span><span class="n">slack_token</span><span class="p">)</span> <span class="n">sc</span><span class="o">.</span><span class="n">api_call</span><span class="p">(</span> <span class="s2">"chat.update"</span><span class="p">,</span> <span class="n">ts</span><span class="o">=</span><span class="s2">"1476746830.000003"</span><span class="p">,</span> <span class="n">channel</span><span class="o">=</span><span class="s2">"C0XXXXXX"</span><span class="p">,</span> <span class="n">text</span><span class="o">=</span><span class="s2">"Hello from Python! :tada:"</span> <span class="p">)</span> </pre></div> </div> <p>See <a class="reference external" href="https://api.slack.com/methods/chat.update">chat.update</a> for formatting options and some special considerations when calling this with a bot user.</p> </div> <hr class="docutils" /> <div class="section" id="deleting-a-message"> <h2>Deleting a message<a class="headerlink" href="#deleting-a-message" title="Permalink to this headline">¶</a></h2> <p>Sometimes you need to delete things.</p> <div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">slackclient</span> <span class="kn">import</span> <span class="n">SlackClient</span> <span class="n">slack_token</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s2">"SLACK_API_TOKEN"</span><span class="p">]</span> <span class="n">sc</span> <span class="o">=</span> <span class="n">SlackClient</span><span class="p">(</span><span class="n">slack_token</span><span class="p">)</span> <span class="n">sc</span><span class="o">.</span><span class="n">api_call</span><span class="p">(</span> <span class="s2">"chat.delete"</span><span class="p">,</span> <span class="n">channel</span><span class="o">=</span><span class="s2">"C0XXXXXX"</span><span class="p">,</span> <span class="n">ts</span><span class="o">=</span><span class="s2">"1476745373.000002"</span> <span class="p">)</span> </pre></div> </div> <p>See <a class="reference external" href="https://api.slack.com/methods/chat.delete">chat.delete</a> for more info.</p> </div> <hr class="docutils" /> <div class="section" id="adding-or-removing-an-emoji-reaction"> <h2>Adding or removing an emoji reaction<a class="headerlink" href="#adding-or-removing-an-emoji-reaction" title="Permalink to this headline">¶</a></h2> <p>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 — and just for fun.</p> <p>This method adds a reaction (emoji) to an item (<code class="docutils literal"><span class="pre">file</span></code>, <code class="docutils literal"><span class="pre">file</span> <span class="pre">comment</span></code>, <code class="docutils literal"><span class="pre">channel</span> <span class="pre">message</span></code>, <code class="docutils literal"><span class="pre">group</span> <span class="pre">message</span></code>, or <code class="docutils literal"><span class="pre">direct</span> <span class="pre">message</span></code>). One of file, file_comment, or the combination of channel and timestamp must be specified.</p> <div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">slackclient</span> <span class="kn">import</span> <span class="n">SlackClient</span> <span class="n">slack_token</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s2">"SLACK_API_TOKEN"</span><span class="p">]</span> <span class="n">sc</span> <span class="o">=</span> <span class="n">SlackClient</span><span class="p">(</span><span class="n">slack_token</span><span class="p">)</span> <span class="n">sc</span><span class="o">.</span><span class="n">api_call</span><span class="p">(</span> <span class="s2">"reactions.add"</span><span class="p">,</span> <span class="n">channel</span><span class="o">=</span><span class="s2">"C0XXXXXXX"</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s2">"thumbsup"</span><span class="p">,</span> <span class="n">timestamp</span><span class="o">=</span><span class="s2">"1234567890.123456"</span> <span class="p">)</span> </pre></div> </div> <p>Removing an emoji reaction is basically the same format, but you’ll use <code class="docutils literal"><span class="pre">reactions.remove</span></code> instead of <code class="docutils literal"><span class="pre">reactions.add</span></code></p> <div class="highlight-python"><div class="highlight"><pre><span></span><span class="n">sc</span><span class="o">.</span><span class="n">api_call</span><span class="p">(</span> <span class="s2">"reactions.remove"</span><span class="p">,</span> <span class="n">channel</span><span class="o">=</span><span class="s2">"C0XXXXXXX"</span><span class="p">,</span> <span class="n">name</span><span class="o">=</span><span class="s2">"thumbsup"</span><span class="p">,</span> <span class="n">timestamp</span><span class="o">=</span><span class="s2">"1234567890.123456"</span> <span class="p">)</span> </pre></div> </div> <p>See <a class="reference external" href="https://api.slack.com/methods/reactions.add">reactions.add</a> and <a class="reference external" href="https://api.slack.com/methods/reactions.remove">reactions.remove</a> for more info.</p> </div> <hr class="docutils" /> <div class="section" id="getting-a-list-of-channels"> <h2>Getting a list of channels<a class="headerlink" href="#getting-a-list-of-channels" title="Permalink to this headline">¶</a></h2> <p>At some point, you’ll want to find out what channels are available to your app. This is how you get that list.</p> <p><strong>Note:</strong> This call requires the <code class="docutils literal"><span class="pre">channels:read</span></code> scope.</p> <div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">slackclient</span> <span class="kn">import</span> <span class="n">SlackClient</span> <span class="n">slack_token</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s2">"SLACK_API_TOKEN"</span><span class="p">]</span> <span class="n">sc</span> <span class="o">=</span> <span class="n">SlackClient</span><span class="p">(</span><span class="n">slack_token</span><span class="p">)</span> <span class="n">sc</span><span class="o">.</span><span class="n">api_call</span><span class="p">(</span><span class="s2">"channels.list"</span><span class="p">)</span> </pre></div> </div> <p>Archived channels are included by default. You can exclude them by passing <code class="docutils literal"><span class="pre">exclude_archived=1</span></code> to your request.</p> <div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">slackclient</span> <span class="kn">import</span> <span class="n">SlackClient</span> <span class="n">slack_token</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s2">"SLACK_API_TOKEN"</span><span class="p">]</span> <span class="n">sc</span> <span class="o">=</span> <span class="n">SlackClient</span><span class="p">(</span><span class="n">slack_token</span><span class="p">)</span> <span class="n">sc</span><span class="o">.</span><span class="n">api_call</span><span class="p">(</span> <span class="s2">"channels.list"</span><span class="p">,</span> <span class="n">exclude_archived</span><span class="o">=</span><span class="mi">1</span> <span class="p">)</span> </pre></div> </div> <p>See <a class="reference external" href="https://api.slack.com/methods/channels.list">channels.list</a> for more info.</p> </div> <hr class="docutils" /> <div class="section" id="getting-a-channel-s-info"> <h2>Getting a channel’s info<a class="headerlink" href="#getting-a-channel-s-info" title="Permalink to this headline">¶</a></h2> <p>Once you have the ID for a specific channel, you can fetch information about that channel.</p> <div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">slackclient</span> <span class="kn">import</span> <span class="n">SlackClient</span> <span class="n">slack_token</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s2">"SLACK_API_TOKEN"</span><span class="p">]</span> <span class="n">sc</span> <span class="o">=</span> <span class="n">SlackClient</span><span class="p">(</span><span class="n">slack_token</span><span class="p">)</span> <span class="n">sc</span><span class="o">.</span><span class="n">api_call</span><span class="p">(</span> <span class="s2">"channels.info"</span><span class="p">,</span> <span class="n">channel</span><span class="o">=</span><span class="s2">"C0XXXXXXX"</span> <span class="p">)</span> </pre></div> </div> <p>See <a class="reference external" href="https://api.slack.com/methods/channels.info">channels.info</a> for more info.</p> </div> <hr class="docutils" /> <div class="section" id="joining-a-channel"> <h2>Joining a channel<a class="headerlink" href="#joining-a-channel" title="Permalink to this headline">¶</a></h2> <p>Channels are the social hub of most Slack teams. Here’s how you hop into one:</p> <div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">slackclient</span> <span class="kn">import</span> <span class="n">SlackClient</span> <span class="n">slack_token</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s2">"SLACK_API_TOKEN"</span><span class="p">]</span> <span class="n">sc</span> <span class="o">=</span> <span class="n">SlackClient</span><span class="p">(</span><span class="n">slack_token</span><span class="p">)</span> <span class="n">sc</span><span class="o">.</span><span class="n">api_call</span><span class="p">(</span> <span class="s2">"channels.join"</span><span class="p">,</span> <span class="n">channel</span><span class="o">=</span><span class="s2">"C0XXXXXXY"</span> <span class="p">)</span> </pre></div> </div> <p>If you are already in the channel, the response is slightly different. <code class="docutils literal"><span class="pre">already_in_channel</span></code> will be true, and a limited <code class="docutils literal"><span class="pre">channel</span></code> object will be returned. Bot users cannot join a channel on their own, they need to be invited by another user.</p> <p>See <a class="reference external" href="https://api.slack.com/methods/channels.join">channels.join</a> for more info.</p> </div> <hr class="docutils" /> <div class="section" id="leaving-a-channel"> <h2>Leaving a channel<a class="headerlink" href="#leaving-a-channel" title="Permalink to this headline">¶</a></h2> <p>Maybe you’ve finished up all the business you had in a channel, or maybe you joined one by accident. This is how you leave a channel.</p> <div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">slackclient</span> <span class="kn">import</span> <span class="n">SlackClient</span> <span class="n">slack_token</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s2">"SLACK_API_TOKEN"</span><span class="p">]</span> <span class="n">sc</span> <span class="o">=</span> <span class="n">SlackClient</span><span class="p">(</span><span class="n">slack_token</span><span class="p">)</span> <span class="n">sc</span><span class="o">.</span><span class="n">api_call</span><span class="p">(</span> <span class="s2">"channels.leave"</span><span class="p">,</span> <span class="n">channel</span><span class="o">=</span><span class="s2">"C0XXXXXXX"</span> <span class="p">)</span> </pre></div> </div> <p>See <a class="reference external" href="https://api.slack.com/methods/channels.leave">channels.leave</a> for more info.</p> </div> <hr class="docutils" /> <div class="section" id="get-a-list-of-team-members"> <h2>Get a list of team members<a class="headerlink" href="#get-a-list-of-team-members" title="Permalink to this headline">¶</a></h2> <div class="highlight-python"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">slackclient</span> <span class="kn">import</span> <span class="n">SlackClient</span> <span class="n">slack_token</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">environ</span><span class="p">[</span><span class="s2">"SLACK_API_TOKEN"</span><span class="p">]</span> <span class="n">sc</span> <span class="o">=</span> <span class="n">SlackClient</span><span class="p">(</span><span class="n">slack_token</span><span class="p">)</span> <span class="n">sc</span><span class="o">.</span><span class="n">api_call</span><span class="p">(</span><span class="s2">"users.list"</span><span class="p">)</span> </pre></div> </div> <p>See <a class="reference external" href="https://api.slack.com/methods/users.list">users.list</a> for more info.</p> </div> </div> <div class="clear_both large_bottom_margin"></div> </div> </div> <!-- /Body Content --> </div> </div> <footer> <p class="light tiny align_center">Copyright © 2015–2016 Slack Technologies, Inc. and contributors</p> </footer> <script type="text/javascript" src="https://a.slack-edge.com/1504/js/rollup-core_required_libs.js" crossorigin="anonymous"></script> <script type="text/javascript" src="https://a.slack-edge.com/125e0/js/rollup-core_web.js" crossorigin="anonymous"></script> </body> </html> |
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |