Skip to content

Commit 54f05e6

Browse files
authored
fix-issue-1145 (#1290)
1 parent 2f926a6 commit 54f05e6

3 files changed

Lines changed: 13 additions & 61 deletions

File tree

docs-src/real_time_messaging.rst

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ RTM Client
88
Real Time Messaging (RTM)
99
---------------------------------------
1010

11+
.. parsed-literal ::
12+
**rtm.start method has been deprecated for apps created after Nov 30th, 2021.** See details `here <https://api.slack.com/changelog/2021-10-rtm-start-to-stop>`_
13+
1114
The `Real Time Messaging (RTM) API`_ is a WebSocket-based API that allows you to receive events from Slack in real time and send messages as users.
1215

1316
If you prefer events to be pushed to your app, we recommend using the HTTP-based `Events API <https://api.slack.com/events-api>`_ along with `Socket Mode <https://api.slack.com/socket-mode>`_ instead. The Events API contains some events that aren't supported in the RTM API (like `app_home_opened event <https://api.slack.com/events/app_home_opened>`_), and it supports most of the event types in the RTM API. If you'd like to use the Events API, you can use the `Python Slack Events Adaptor <https://github.com/slackapi/python-slack-events-api>`_.
@@ -50,7 +53,7 @@ Note that the import here is not ``from slack_sdk.rtm import RTMClient`` but ``f
5053
thread_ts=thread_ts
5154
)
5255
53-
rtm.start()
56+
rtm.connect()
5457
5558
5659
**Connecting to the RTM API (v1 client)**
@@ -80,40 +83,14 @@ Below is a code snippet that uses the legacy version of ``RTMClient``. For new a
8083
8184
slack_token = os.environ["SLACK_BOT_TOKEN"]
8285
rtm_client = RTMClient(token=slack_token)
83-
rtm_client.start()
86+
rtm_client.connect()
8487
8588
**rtm.start vs rtm.connect (v1 client)**
8689

87-
By default, the RTM client uses ``rtm.connect`` to establish a WebSocket connection with Slack. The response contains basic information about the team and WebSocket url.
88-
89-
If you'd rather use ``rtm.start`` to establish the connection, which provides more information about the conversations and users on the team, you can set the ``connect_method`` option to ``rtm.start`` when instantiating the RTM Client. Note that on larger teams, use of ``rtm.start`` can be slow and unreliable.
90-
91-
.. code-block:: python
92-
93-
import os
94-
from slack_sdk.rtm import RTMClient
95-
96-
@RTMClient.run_on(event="message")
97-
def say_hello(**payload):
98-
data = payload['data']
99-
web_client = payload['web_client']
100-
if 'text' in data and 'Hello' in data['text']:
101-
channel_id = data['channel']
102-
thread_ts = data['ts']
103-
user = data['user'] # This is not username but user ID (the format is either U*** or W***)
104-
105-
web_client.chat_postMessage(
106-
channel=channel_id,
107-
text=f"Hi <@{user}>!",
108-
thread_ts=thread_ts
109-
)
90+
.. parsed-literal ::
91+
**rtm.start method has been deprecated for apps created after Nov 30th, 2021.** See details `here <https://api.slack.com/changelog/2021-10-rtm-start-to-stop>`_
11092
111-
slack_token = os.environ["SLACK_BOT_TOKEN"]
112-
rtm_client = RTMClient(
113-
token=slack_token,
114-
connect_method='rtm.start'
115-
)
116-
rtm_client.start()
93+
By default, the RTM client uses ``rtm.connect`` to establish a WebSocket connection with Slack. The response contains basic information about the team and WebSocket url.
11794

11895
Read the `rtm.connect docs <https://api.slack.com/methods/rtm.connect>`_ and the `rtm.start docs <https://api.slack.com/methods/rtm.start>`_ for more details. Also, note that ``slack.rtm_v2.RTMClient`` does not support ``rtm.start``.
11996

docs/real_time_messaging.html

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@
215215
<span id="real-time-messaging"></span><h1>RTM Client<a class="headerlink" href="#rtm-client" title="Permalink to this heading"></a></h1>
216216
<section id="real-time-messaging-rtm">
217217
<h2>Real Time Messaging (RTM)<a class="headerlink" href="#real-time-messaging-rtm" title="Permalink to this heading"></a></h2>
218+
<pre class="literal-block"><strong>rtm.start method deprecation after Nov 30th, 2021.</strong> see details <a class="reference external" href="https://api.slack.com/changelog/2021-10-rtm-start-to-stop">here</a></pre>
218219
<p>The <a class="reference external" href="https://api.slack.com/rtm">Real Time Messaging (RTM) API</a> is a WebSocket-based API that allows you to receive events from Slack in real time and send messages as users.</p>
219220
<p>If you prefer events to be pushed to your app, we recommend using the HTTP-based <a class="reference external" href="https://api.slack.com/events-api">Events API</a> along with <a class="reference external" href="https://api.slack.com/socket-mode">Socket Mode</a> instead. The Events API contains some events that aren’t supported in the RTM API (like <a class="reference external" href="https://api.slack.com/events/app_home_opened">app_home_opened event</a>), and it supports most of the event types in the RTM API. If you’d like to use the Events API, you can use the <a class="reference external" href="https://github.com/slackapi/python-slack-events-api">Python Slack Events Adaptor</a>.</p>
220221
<p>The RTMClient allows apps to communicate with the Slack Platform’s RTM API.</p>
@@ -244,7 +245,7 @@ <h2>Real Time Messaging (RTM)<a class="headerlink" href="#real-time-messaging-rt
244245
<span class="n">thread_ts</span><span class="o">=</span><span class="n">thread_ts</span>
245246
<span class="p">)</span>
246247

247-
<span class="n">rtm</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
248+
<span class="n">rtm</span><span class="o">.</span><span class="n">connect</span><span class="p">()</span>
248249
</pre></div>
249250
</div>
250251
<p><strong>Connecting to the RTM API (v1 client)</strong></p>
@@ -270,38 +271,12 @@ <h2>Real Time Messaging (RTM)<a class="headerlink" href="#real-time-messaging-rt
270271

271272
<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">&quot;SLACK_BOT_TOKEN&quot;</span><span class="p">]</span>
272273
<span class="n">rtm_client</span> <span class="o">=</span> <span class="n">RTMClient</span><span class="p">(</span><span class="n">token</span><span class="o">=</span><span class="n">slack_token</span><span class="p">)</span>
273-
<span class="n">rtm_client</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
274+
<span class="n">rtm_client</span><span class="o">.</span><span class="n">connect</span><span class="p">()</span>
274275
</pre></div>
275276
</div>
276277
<p><strong>rtm.start vs rtm.connect (v1 client)</strong></p>
278+
<pre class="literal-block"><strong>rtm.start method deprecation after Nov 30th, 2021.</strong> see details <a class="reference external" href="https://api.slack.com/changelog/2021-10-rtm-start-to-stop">here</a></pre>
277279
<p>By default, the RTM client uses <code class="docutils literal notranslate"><span class="pre">rtm.connect</span></code> to establish a WebSocket connection with Slack. The response contains basic information about the team and WebSocket url.</p>
278-
<p>If you’d rather use <code class="docutils literal notranslate"><span class="pre">rtm.start</span></code> to establish the connection, which provides more information about the conversations and users on the team, you can set the <code class="docutils literal notranslate"><span class="pre">connect_method</span></code> option to <code class="docutils literal notranslate"><span class="pre">rtm.start</span></code> when instantiating the RTM Client. Note that on larger teams, use of <code class="docutils literal notranslate"><span class="pre">rtm.start</span></code> can be slow and unreliable.</p>
279-
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">os</span>
280-
<span class="kn">from</span> <span class="nn">slack_sdk.rtm</span> <span class="kn">import</span> <span class="n">RTMClient</span>
281-
282-
<span class="nd">@RTMClient</span><span class="o">.</span><span class="n">run_on</span><span class="p">(</span><span class="n">event</span><span class="o">=</span><span class="s2">&quot;message&quot;</span><span class="p">)</span>
283-
<span class="k">def</span> <span class="nf">say_hello</span><span class="p">(</span><span class="o">**</span><span class="n">payload</span><span class="p">):</span>
284-
<span class="n">data</span> <span class="o">=</span> <span class="n">payload</span><span class="p">[</span><span class="s1">&#39;data&#39;</span><span class="p">]</span>
285-
<span class="n">web_client</span> <span class="o">=</span> <span class="n">payload</span><span class="p">[</span><span class="s1">&#39;web_client&#39;</span><span class="p">]</span>
286-
<span class="k">if</span> <span class="s1">&#39;text&#39;</span> <span class="ow">in</span> <span class="n">data</span> <span class="ow">and</span> <span class="s1">&#39;Hello&#39;</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;text&#39;</span><span class="p">]:</span>
287-
<span class="n">channel_id</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;channel&#39;</span><span class="p">]</span>
288-
<span class="n">thread_ts</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;ts&#39;</span><span class="p">]</span>
289-
<span class="n">user</span> <span class="o">=</span> <span class="n">data</span><span class="p">[</span><span class="s1">&#39;user&#39;</span><span class="p">]</span> <span class="c1"># This is not username but user ID (the format is either U*** or W***)</span>
290-
291-
<span class="n">web_client</span><span class="o">.</span><span class="n">chat_postMessage</span><span class="p">(</span>
292-
<span class="n">channel</span><span class="o">=</span><span class="n">channel_id</span><span class="p">,</span>
293-
<span class="n">text</span><span class="o">=</span><span class="sa">f</span><span class="s2">&quot;Hi &lt;@</span><span class="si">{</span><span class="n">user</span><span class="si">}</span><span class="s2">&gt;!&quot;</span><span class="p">,</span>
294-
<span class="n">thread_ts</span><span class="o">=</span><span class="n">thread_ts</span>
295-
<span class="p">)</span>
296-
297-
<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">&quot;SLACK_BOT_TOKEN&quot;</span><span class="p">]</span>
298-
<span class="n">rtm_client</span> <span class="o">=</span> <span class="n">RTMClient</span><span class="p">(</span>
299-
<span class="n">token</span><span class="o">=</span><span class="n">slack_token</span><span class="p">,</span>
300-
<span class="n">connect_method</span><span class="o">=</span><span class="s1">&#39;rtm.start&#39;</span>
301-
<span class="p">)</span>
302-
<span class="n">rtm_client</span><span class="o">.</span><span class="n">start</span><span class="p">()</span>
303-
</pre></div>
304-
</div>
305280
<p>Read the <a class="reference external" href="https://api.slack.com/methods/rtm.connect">rtm.connect docs</a> and the <a class="reference external" href="https://api.slack.com/methods/rtm.start">rtm.start docs</a> for more details. Also, note that <code class="docutils literal notranslate"><span class="pre">slack.rtm_v2.RTMClient</span></code> does not support <code class="docutils literal notranslate"><span class="pre">rtm.start</span></code>.</p>
306281
<p><strong>RTM Events</strong></p>
307282
<div class="highlight-javascript notranslate"><div class="highlight"><pre><span></span><span class="p">{</span><span class="w"></span>

0 commit comments

Comments
 (0)