Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added rtm.connect support and fixed rtm_send_message #215

Merged
merged 20 commits into from
Aug 31, 2017
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions docs-src/real_time_messaging.rst
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,32 @@ If there was a problem connecting an error will be returned, including a descrip
}
}

rtm.start vs rtm.connect
---------------------------

If you expect your app to be used on large teams, we recommend starting the RTM client with `rtm.connect` rather than the default connection method for this client, `rtm.start`.
`rtm.connect` provides a lighter initial connection payload, without the team's channel and user information included. You'll need to request channel and user info via
the Web API separately.

To do this, simply pass `with_team_state=False` into the `rtm_connect` call, like so:
::

from slackclient import SlackClient

slack_token = os.environ["SLACK_API_TOKEN"]
sc = SlackClient(slack_token)

if sc.rtm_connect(with_team_state=False):
while True:
print sc.rtm_read()
time.sleep(1)
else:
print "Connection Failed"


See the `rtm.start docs <https://api.slack.com/methods/rtm.start>`_ and the `rtm.connect docs<https://api.slack.com/methods/rtm.connect>`_
for more details.


RTM Events
-------------
Expand Down
1 change: 1 addition & 0 deletions docs/genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
</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-start-vs-rtm-connect">rtm.start vs rtm.connect</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>
Expand Down
1 change: 1 addition & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
</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-start-vs-rtm-connect">rtm.start vs rtm.connect</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>
Expand Down
23 changes: 23 additions & 0 deletions docs/real_time_messaging.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
</li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">Real Time Messaging</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#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="#rtm-start-vs-rtm-connect">rtm.start vs rtm.connect</a></li>
<li class="toctree-l2"><a class="reference internal" href="#rtm-events">RTM Events</a></li>
<li class="toctree-l2"><a class="reference internal" href="#sending-messages-via-the-rtm-api">Sending messages via the RTM API</a></li>
</ul>
Expand Down Expand Up @@ -159,6 +160,28 @@ <h2>Connecting to the Real Time Messaging API<a class="headerlink" href="#connec
</pre></div>
</div>
</div>
<div class="section" id="rtm-start-vs-rtm-connect">
<h2>rtm.start vs rtm.connect<a class="headerlink" href="#rtm-start-vs-rtm-connect" title="Permalink to this headline">¶</a></h2>
<p>If you expect your app to be used on large teams, we recommend starting the RTM client with <cite>rtm.connect</cite> rather than the default connection method for this client, <cite>rtm.start</cite>.
<cite>rtm.connect</cite> provides a lighter initial connection payload, without the team’s channel and user information included. You’ll need to request channel and user info via
the Web API separately.</p>
<p>To do this, simply pass <cite>with_team_state=False</cite> into the <cite>rtm_connect</cite> call, like so:</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">&quot;SLACK_API_TOKEN&quot;</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="k">if</span> <span class="n">sc</span><span class="o">.</span><span class="n">rtm_connect</span><span class="p">(</span><span class="n">with_team_state</span><span class="o">=</span><span class="bp">False</span><span class="p">):</span>
<span class="k">while</span> <span class="bp">True</span><span class="p">:</span>
<span class="k">print</span> <span class="n">sc</span><span class="o">.</span><span class="n">rtm_read</span><span class="p">()</span>
<span class="n">time</span><span class="o">.</span><span class="n">sleep</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="k">else</span><span class="p">:</span>
<span class="k">print</span> <span class="s2">&quot;Connection Failed&quot;</span>
</pre></div>
</div>
<p>See the <a class="reference external" href="https://api.slack.com/methods/rtm.start">rtm.start docs</a> and the <a href="#id3"><span class="problematic" id="id4">`rtm.connect docs&lt;https://api.slack.com/methods/rtm.connect&gt;`_</span></a>
for more details.</p>
</div>
<div class="section" id="rtm-events">
<h2>RTM Events<a class="headerlink" href="#rtm-events" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python"><div class="highlight"><pre><span></span><span class="p">{</span>
Expand Down
1 change: 1 addition & 0 deletions docs/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
</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-start-vs-rtm-connect">rtm.start vs rtm.connect</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>
Expand Down
Loading