|
52 | 52 | </li> |
53 | 53 | <li class="toctree-l1 current"><a class="current reference internal" href="#">Basic Usage</a><ul> |
54 | 54 | <li class="toctree-l2"><a class="reference internal" href="#sending-a-message">Sending a message</a></li> |
| 55 | +<li class="toctree-l2"><a class="reference internal" href="#replying-to-messages-and-creating-threads">Replying to messages and creating threads</a></li> |
55 | 56 | <li class="toctree-l2"><a class="reference internal" href="#updating-the-content-of-a-message">Updating the content of a message</a></li> |
56 | 57 | <li class="toctree-l2"><a class="reference internal" href="#deleting-a-message">Deleting a message</a></li> |
57 | 58 | <li class="toctree-l2"><a class="reference internal" href="#adding-or-removing-an-emoji-reaction">Adding or removing an emoji reaction</a></li> |
@@ -146,6 +147,52 @@ <h2>Sending a message<a class="headerlink" href="#sending-a-message" title="Perm |
146 | 147 | page for a full list of formatting and authorship options.</p> |
147 | 148 | </div> |
148 | 149 | <hr class="docutils" /> |
| 150 | +<div class="section" id="replying-to-messages-and-creating-threads"> |
| 151 | +<h2>Replying to messages and creating threads<a class="headerlink" href="#replying-to-messages-and-creating-threads" title="Permalink to this headline">¶</a></h2> |
| 152 | +<p>Threaded messages are just like regular messages, except thread replies are grouped together to provide greater context |
| 153 | +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> |
| 154 | +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> |
| 155 | +ID of the message you’re replying to.</p> |
| 156 | +<p>A channel or DM conversation is a nearly linear timeline of messages exchanged between people, bots, and apps. |
| 157 | +When one of these messages is replied to, it becomes the parent of a thread. By default, threaded replies do not |
| 158 | +appear directly in the channel, instead relegated to a kind of forked timeline descending from the parent message.</p> |
| 159 | +<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> |
| 160 | + |
| 161 | +<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> |
| 162 | +<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> |
| 163 | + |
| 164 | +<span class="n">sc</span><span class="o">.</span><span class="n">api_call</span><span class="p">(</span> |
| 165 | + <span class="s2">"chat.postMessage"</span><span class="p">,</span> |
| 166 | + <span class="n">channel</span><span class="o">=</span><span class="s2">"#python"</span><span class="p">,</span> |
| 167 | + <span class="n">text</span><span class="o">=</span><span class="s2">"Hello from Python! :tada:"</span><span class="p">,</span> |
| 168 | + <span class="n">thread_ts</span><span class="o">=</span><span class="s2">"1476746830.000003"</span> |
| 169 | +<span class="p">)</span> |
| 170 | +</pre></div> |
| 171 | +</div> |
| 172 | +<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, |
| 173 | +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> |
| 174 | +<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> |
| 175 | + |
| 176 | +<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> |
| 177 | +<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> |
| 178 | + |
| 179 | +<span class="n">sc</span><span class="o">.</span><span class="n">api_call</span><span class="p">(</span> |
| 180 | + <span class="s2">"chat.postMessage"</span><span class="p">,</span> |
| 181 | + <span class="n">channel</span><span class="o">=</span><span class="s2">"#python"</span><span class="p">,</span> |
| 182 | + <span class="n">text</span><span class="o">=</span><span class="s2">"Hello from Python! :tada:"</span><span class="p">,</span> |
| 183 | + <span class="n">thread_ts</span><span class="o">=</span><span class="s2">"1476746830.000003"</span><span class="p">,</span> |
| 184 | + <span class="n">reply_broadcast</span><span class="o">=</span><span class="bp">True</span> |
| 185 | +<span class="p">)</span> |
| 186 | +</pre></div> |
| 187 | +</div> |
| 188 | +<p><strong>Note:</strong> While threaded messages may contain attachments and message buttons, when your reply is broadcast to the |
| 189 | +channel, it’ll actually be a reference to your reply, not the reply itself. |
| 190 | +So, when appearing in the channel, it won’t contain any attachments or message buttons. Also note that updates and |
| 191 | +deletion of threaded replies works the same as regular messages.</p> |
| 192 | +<p>See the <a class="reference external" href="https://api.slack.com/docs/message-threading#forking_conversations">Threading messages together</a> |
| 193 | +article for more information.</p> |
| 194 | +</div> |
| 195 | +<hr class="docutils" /> |
149 | 196 | <div class="section" id="updating-the-content-of-a-message"> |
150 | 197 | <h2>Updating the content of a message<a class="headerlink" href="#updating-the-content-of-a-message" title="Permalink to this headline">¶</a></h2> |
151 | 198 | <p>Let’s say you have a bot which posts the status of a request. When that request |
|
0 commit comments