Skip to content

Commit 64a995c

Browse files
zimegmwbrooks
andauthored
feat(web-api): add a chat stream method to the web client (#1755)
Co-authored-by: Michael Brooks <[email protected]>
1 parent bd1857f commit 64a995c

17 files changed

+2731
-2
lines changed

docs/reference/index.html

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3056,6 +3056,69 @@ <h2 class="section-title" id="header-classes">Classes</h2>
30563056
kwargs = _remove_none_values(kwargs)
30573057
return self.api_call(&#34;chat.stopStream&#34;, json=kwargs)
30583058

3059+
def chat_stream(
3060+
self,
3061+
*,
3062+
buffer_size: int = 256,
3063+
channel: str,
3064+
thread_ts: str,
3065+
recipient_team_id: Optional[str] = None,
3066+
recipient_user_id: Optional[str] = None,
3067+
**kwargs,
3068+
) -&gt; ChatStream:
3069+
&#34;&#34;&#34;Stream markdown text into a conversation.
3070+
3071+
This method starts a new chat stream in a coversation that can be appended to. After appending an entire message,
3072+
the stream can be stopped with concluding arguments such as &#34;blocks&#34; for gathering feedback.
3073+
3074+
The following methods are used:
3075+
3076+
- chat.startStream: Starts a new streaming conversation.
3077+
[Reference](https://docs.slack.dev/reference/methods/chat.startStream).
3078+
- chat.appendStream: Appends text to an existing streaming conversation.
3079+
[Reference](https://docs.slack.dev/reference/methods/chat.appendStream).
3080+
- chat.stopStream: Stops a streaming conversation.
3081+
[Reference](https://docs.slack.dev/reference/methods/chat.stopStream).
3082+
3083+
Args:
3084+
buffer_size: The length of markdown_text to buffer in-memory before calling a stream method. Increasing this
3085+
value decreases the number of method calls made for the same amount of text, which is useful to avoid rate
3086+
limits. Default: 256.
3087+
channel: An encoded ID that represents a channel, private group, or DM.
3088+
thread_ts: Provide another message&#39;s ts value to reply to. Streamed messages should always be replies to a user
3089+
request.
3090+
recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when
3091+
streaming to channels.
3092+
recipient_user_id: The encoded ID of the user to receive the streaming text. Required when streaming to channels.
3093+
**kwargs: Additional arguments passed to the underlying API calls.
3094+
3095+
Returns:
3096+
ChatStream instance for managing the stream
3097+
3098+
Example:
3099+
```python
3100+
streamer = client.chat_stream(
3101+
channel=&#34;C0123456789&#34;,
3102+
thread_ts=&#34;1700000001.123456&#34;,
3103+
recipient_team_id=&#34;T0123456789&#34;,
3104+
recipient_user_id=&#34;U0123456789&#34;,
3105+
)
3106+
streamer.append(markdown_text=&#34;**hello wo&#34;)
3107+
streamer.append(markdown_text=&#34;rld!**&#34;)
3108+
streamer.stop()
3109+
```
3110+
&#34;&#34;&#34;
3111+
return ChatStream(
3112+
self,
3113+
logger=self._logger,
3114+
channel=channel,
3115+
thread_ts=thread_ts,
3116+
recipient_team_id=recipient_team_id,
3117+
recipient_user_id=recipient_user_id,
3118+
buffer_size=buffer_size,
3119+
**kwargs,
3120+
)
3121+
30593122
def chat_unfurl(
30603123
self,
30613124
*,
@@ -10346,6 +10409,122 @@ <h3>Methods</h3>
1034610409
<div class="desc"><p>Stops a streaming conversation.
1034710410
<a href="https://api.slack.com/methods/chat.stopStream">https://api.slack.com/methods/chat.stopStream</a></p></div>
1034810411
</dd>
10412+
<dt id="slack_sdk.WebClient.chat_stream"><code class="name flex">
10413+
<span>def <span class="ident">chat_stream</span></span>(<span>self,<br>*,<br>buffer_size: int = 256,<br>channel: str,<br>thread_ts: str,<br>recipient_team_id: str | None = None,<br>recipient_user_id: str | None = None,<br>**kwargs) ‑> <a title="slack_sdk.web.chat_stream.ChatStream" href="web/chat_stream.html#slack_sdk.web.chat_stream.ChatStream">ChatStream</a></span>
10414+
</code></dt>
10415+
<dd>
10416+
<details class="source">
10417+
<summary>
10418+
<span>Expand source code</span>
10419+
</summary>
10420+
<pre><code class="python">def chat_stream(
10421+
self,
10422+
*,
10423+
buffer_size: int = 256,
10424+
channel: str,
10425+
thread_ts: str,
10426+
recipient_team_id: Optional[str] = None,
10427+
recipient_user_id: Optional[str] = None,
10428+
**kwargs,
10429+
) -&gt; ChatStream:
10430+
&#34;&#34;&#34;Stream markdown text into a conversation.
10431+
10432+
This method starts a new chat stream in a coversation that can be appended to. After appending an entire message,
10433+
the stream can be stopped with concluding arguments such as &#34;blocks&#34; for gathering feedback.
10434+
10435+
The following methods are used:
10436+
10437+
- chat.startStream: Starts a new streaming conversation.
10438+
[Reference](https://docs.slack.dev/reference/methods/chat.startStream).
10439+
- chat.appendStream: Appends text to an existing streaming conversation.
10440+
[Reference](https://docs.slack.dev/reference/methods/chat.appendStream).
10441+
- chat.stopStream: Stops a streaming conversation.
10442+
[Reference](https://docs.slack.dev/reference/methods/chat.stopStream).
10443+
10444+
Args:
10445+
buffer_size: The length of markdown_text to buffer in-memory before calling a stream method. Increasing this
10446+
value decreases the number of method calls made for the same amount of text, which is useful to avoid rate
10447+
limits. Default: 256.
10448+
channel: An encoded ID that represents a channel, private group, or DM.
10449+
thread_ts: Provide another message&#39;s ts value to reply to. Streamed messages should always be replies to a user
10450+
request.
10451+
recipient_team_id: The encoded ID of the team the user receiving the streaming text belongs to. Required when
10452+
streaming to channels.
10453+
recipient_user_id: The encoded ID of the user to receive the streaming text. Required when streaming to channels.
10454+
**kwargs: Additional arguments passed to the underlying API calls.
10455+
10456+
Returns:
10457+
ChatStream instance for managing the stream
10458+
10459+
Example:
10460+
```python
10461+
streamer = client.chat_stream(
10462+
channel=&#34;C0123456789&#34;,
10463+
thread_ts=&#34;1700000001.123456&#34;,
10464+
recipient_team_id=&#34;T0123456789&#34;,
10465+
recipient_user_id=&#34;U0123456789&#34;,
10466+
)
10467+
streamer.append(markdown_text=&#34;**hello wo&#34;)
10468+
streamer.append(markdown_text=&#34;rld!**&#34;)
10469+
streamer.stop()
10470+
```
10471+
&#34;&#34;&#34;
10472+
return ChatStream(
10473+
self,
10474+
logger=self._logger,
10475+
channel=channel,
10476+
thread_ts=thread_ts,
10477+
recipient_team_id=recipient_team_id,
10478+
recipient_user_id=recipient_user_id,
10479+
buffer_size=buffer_size,
10480+
**kwargs,
10481+
)</code></pre>
10482+
</details>
10483+
<div class="desc"><p>Stream markdown text into a conversation.</p>
10484+
<p>This method starts a new chat stream in a coversation that can be appended to. After appending an entire message,
10485+
the stream can be stopped with concluding arguments such as "blocks" for gathering feedback.</p>
10486+
<p>The following methods are used:</p>
10487+
<ul>
10488+
<li>chat.startStream: Starts a new streaming conversation.
10489+
<a href="https://docs.slack.dev/reference/methods/chat.startStream">Reference</a>.</li>
10490+
<li>chat.appendStream: Appends text to an existing streaming conversation.
10491+
<a href="https://docs.slack.dev/reference/methods/chat.appendStream">Reference</a>.</li>
10492+
<li>chat.stopStream: Stops a streaming conversation.
10493+
<a href="https://docs.slack.dev/reference/methods/chat.stopStream">Reference</a>.</li>
10494+
</ul>
10495+
<h2 id="args">Args</h2>
10496+
<dl>
10497+
<dt><strong><code>buffer_size</code></strong></dt>
10498+
<dd>The length of markdown_text to buffer in-memory before calling a stream method. Increasing this
10499+
value decreases the number of method calls made for the same amount of text, which is useful to avoid rate
10500+
limits. Default: 256.</dd>
10501+
<dt><strong><code>channel</code></strong></dt>
10502+
<dd>An encoded ID that represents a channel, private group, or DM.</dd>
10503+
<dt><strong><code>thread_ts</code></strong></dt>
10504+
<dd>Provide another message's ts value to reply to. Streamed messages should always be replies to a user
10505+
request.</dd>
10506+
<dt><strong><code>recipient_team_id</code></strong></dt>
10507+
<dd>The encoded ID of the team the user receiving the streaming text belongs to. Required when
10508+
streaming to channels.</dd>
10509+
<dt><strong><code>recipient_user_id</code></strong></dt>
10510+
<dd>The encoded ID of the user to receive the streaming text. Required when streaming to channels.</dd>
10511+
<dt><strong><code>**kwargs</code></strong></dt>
10512+
<dd>Additional arguments passed to the underlying API calls.</dd>
10513+
</dl>
10514+
<h2 id="returns">Returns</h2>
10515+
<p>ChatStream instance for managing the stream</p>
10516+
<h2 id="example">Example</h2>
10517+
<pre><code class="language-python">streamer = client.chat_stream(
10518+
channel=&quot;C0123456789&quot;,
10519+
thread_ts=&quot;1700000001.123456&quot;,
10520+
recipient_team_id=&quot;T0123456789&quot;,
10521+
recipient_user_id=&quot;U0123456789&quot;,
10522+
)
10523+
streamer.append(markdown_text=&quot;**hello wo&quot;)
10524+
streamer.append(markdown_text=&quot;rld!**&quot;)
10525+
streamer.stop()
10526+
</code></pre></div>
10527+
</dd>
1034910528
<dt id="slack_sdk.WebClient.chat_unfurl"><code class="name flex">
1035010529
<span>def <span class="ident">chat_unfurl</span></span>(<span>self,<br>*,<br>channel: str | None = None,<br>ts: str | None = None,<br>source: str | None = None,<br>unfurl_id: str | None = None,<br>unfurls: Dict[str, Dict] | None = None,<br>user_auth_blocks: str | Sequence[Dict | <a title="slack_sdk.models.blocks.blocks.Block" href="models/blocks/blocks.html#slack_sdk.models.blocks.blocks.Block">Block</a>] | None = None,<br>user_auth_message: str | None = None,<br>user_auth_required: bool | None = None,<br>user_auth_url: str | None = None,<br>**kwargs) ‑> <a title="slack_sdk.web.slack_response.SlackResponse" href="web/slack_response.html#slack_sdk.web.slack_response.SlackResponse">SlackResponse</a></span>
1035110530
</code></dt>
@@ -15323,6 +15502,7 @@ <h4><code><a title="slack_sdk.WebClient" href="#slack_sdk.WebClient">WebClient</
1532315502
<li><code><a title="slack_sdk.WebClient.chat_scheduledMessages_list" href="#slack_sdk.WebClient.chat_scheduledMessages_list">chat_scheduledMessages_list</a></code></li>
1532415503
<li><code><a title="slack_sdk.WebClient.chat_startStream" href="#slack_sdk.WebClient.chat_startStream">chat_startStream</a></code></li>
1532515504
<li><code><a title="slack_sdk.WebClient.chat_stopStream" href="#slack_sdk.WebClient.chat_stopStream">chat_stopStream</a></code></li>
15505+
<li><code><a title="slack_sdk.WebClient.chat_stream" href="#slack_sdk.WebClient.chat_stream">chat_stream</a></code></li>
1532615506
<li><code><a title="slack_sdk.WebClient.chat_unfurl" href="#slack_sdk.WebClient.chat_unfurl">chat_unfurl</a></code></li>
1532715507
<li><code><a title="slack_sdk.WebClient.chat_update" href="#slack_sdk.WebClient.chat_update">chat_update</a></code></li>
1532815508
<li><code><a title="slack_sdk.WebClient.conversations_acceptSharedInvite" href="#slack_sdk.WebClient.conversations_acceptSharedInvite">conversations_acceptSharedInvite</a></code></li>

0 commit comments

Comments
 (0)