Skip to content

Commit 73e46fd

Browse files
committed
feat(web-api): add a chat stream method to the web client
1 parent bd1857f commit 73e46fd

File tree

14 files changed

+2280
-0
lines changed

14 files changed

+2280
-0
lines changed

docs/reference/index.html

Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3030,6 +3030,64 @@ <h2 class="section-title" id="header-classes">Classes</h2>
30303030
kwargs = _remove_none_values(kwargs)
30313031
return self.api_call(&#34;chat.startStream&#34;, json=kwargs)
30323032

3033+
def chat_stream(
3034+
self,
3035+
*,
3036+
buffer_size: Optional[int] = 256,
3037+
channel: str,
3038+
thread_ts: str,
3039+
recipient_team_id: Optional[str] = None,
3040+
recipient_user_id: Optional[str] = None,
3041+
unfurl_links: Optional[bool] = None,
3042+
unfurl_media: Optional[bool] = None,
3043+
**kwargs,
3044+
) -&gt; ChatStream:
3045+
&#34;&#34;&#34;Stream markdown text into a conversation.
3046+
3047+
This method provides an easy way to stream markdown text using the following endpoints:
3048+
- chat.startStream: Starts a new streaming conversation
3049+
- chat.appendStream: Appends text to an existing streaming conversation
3050+
- chat.stopStream: Stops a streaming conversation
3051+
3052+
Args:
3053+
buffer_size: Size of the internal buffer before automatically flushing (default: 256)
3054+
channel: Channel to stream to
3055+
thread_ts: Thread timestamp to stream to (required)
3056+
recipient_team_id: Team ID of the recipient (for Slack Connect)
3057+
recipient_user_id: User ID of the recipient (for Slack Connect)
3058+
unfurl_links: Whether to unfurl links
3059+
unfurl_media: Whether to unfurl media
3060+
**kwargs: Additional arguments passed to the underlying API calls
3061+
3062+
Returns:
3063+
ChatStreamer instance for managing the stream
3064+
3065+
Example:
3066+
```python
3067+
streamer = client.chat_stream(
3068+
channel=&#34;C0123456789&#34;,
3069+
thread_ts=&#34;1700000001.123456&#34;,
3070+
recipient_team_id=&#34;T0123456789&#34;,
3071+
recipient_user_id=&#34;U0123456789&#34;,
3072+
)
3073+
streamer.append(markdown_text=&#34;**hello wo&#34;)
3074+
streamer.append(markdown_text=&#34;rld!**&#34;)
3075+
streamer.stop()
3076+
```
3077+
&#34;&#34;&#34;
3078+
return ChatStream(
3079+
self,
3080+
logger=self._logger,
3081+
channel=channel,
3082+
thread_ts=thread_ts,
3083+
recipient_team_id=recipient_team_id,
3084+
recipient_user_id=recipient_user_id,
3085+
unfurl_links=unfurl_links,
3086+
unfurl_media=unfurl_media,
3087+
buffer_size=buffer_size,
3088+
**kwargs,
3089+
)
3090+
30333091
def chat_stopStream(
30343092
self,
30353093
*,
@@ -10346,6 +10404,110 @@ <h3>Methods</h3>
1034610404
<div class="desc"><p>Stops a streaming conversation.
1034710405
<a href="https://api.slack.com/methods/chat.stopStream">https://api.slack.com/methods/chat.stopStream</a></p></div>
1034810406
</dd>
10407+
<dt id="slack_sdk.WebClient.chat_stream"><code class="name flex">
10408+
<span>def <span class="ident">chat_stream</span></span>(<span>self,<br>*,<br>buffer_size: int | None = 256,<br>channel: str,<br>thread_ts: str,<br>recipient_team_id: str | None = None,<br>recipient_user_id: str | None = None,<br>unfurl_links: bool | None = None,<br>unfurl_media: bool | 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>
10409+
</code></dt>
10410+
<dd>
10411+
<details class="source">
10412+
<summary>
10413+
<span>Expand source code</span>
10414+
</summary>
10415+
<pre><code class="python">def chat_stream(
10416+
self,
10417+
*,
10418+
buffer_size: Optional[int] = 256,
10419+
channel: str,
10420+
thread_ts: str,
10421+
recipient_team_id: Optional[str] = None,
10422+
recipient_user_id: Optional[str] = None,
10423+
unfurl_links: Optional[bool] = None,
10424+
unfurl_media: Optional[bool] = None,
10425+
**kwargs,
10426+
) -&gt; ChatStream:
10427+
&#34;&#34;&#34;Stream markdown text into a conversation.
10428+
10429+
This method provides an easy way to stream markdown text using the following endpoints:
10430+
- chat.startStream: Starts a new streaming conversation
10431+
- chat.appendStream: Appends text to an existing streaming conversation
10432+
- chat.stopStream: Stops a streaming conversation
10433+
10434+
Args:
10435+
buffer_size: Size of the internal buffer before automatically flushing (default: 256)
10436+
channel: Channel to stream to
10437+
thread_ts: Thread timestamp to stream to (required)
10438+
recipient_team_id: Team ID of the recipient (for Slack Connect)
10439+
recipient_user_id: User ID of the recipient (for Slack Connect)
10440+
unfurl_links: Whether to unfurl links
10441+
unfurl_media: Whether to unfurl media
10442+
**kwargs: Additional arguments passed to the underlying API calls
10443+
10444+
Returns:
10445+
ChatStreamer instance for managing the stream
10446+
10447+
Example:
10448+
```python
10449+
streamer = client.chat_stream(
10450+
channel=&#34;C0123456789&#34;,
10451+
thread_ts=&#34;1700000001.123456&#34;,
10452+
recipient_team_id=&#34;T0123456789&#34;,
10453+
recipient_user_id=&#34;U0123456789&#34;,
10454+
)
10455+
streamer.append(markdown_text=&#34;**hello wo&#34;)
10456+
streamer.append(markdown_text=&#34;rld!**&#34;)
10457+
streamer.stop()
10458+
```
10459+
&#34;&#34;&#34;
10460+
return ChatStream(
10461+
self,
10462+
logger=self._logger,
10463+
channel=channel,
10464+
thread_ts=thread_ts,
10465+
recipient_team_id=recipient_team_id,
10466+
recipient_user_id=recipient_user_id,
10467+
unfurl_links=unfurl_links,
10468+
unfurl_media=unfurl_media,
10469+
buffer_size=buffer_size,
10470+
**kwargs,
10471+
)</code></pre>
10472+
</details>
10473+
<div class="desc"><p>Stream markdown text into a conversation.</p>
10474+
<p>This method provides an easy way to stream markdown text using the following endpoints:
10475+
- chat.startStream: Starts a new streaming conversation
10476+
- chat.appendStream: Appends text to an existing streaming conversation
10477+
- chat.stopStream: Stops a streaming conversation</p>
10478+
<h2 id="args">Args</h2>
10479+
<dl>
10480+
<dt><strong><code>buffer_size</code></strong></dt>
10481+
<dd>Size of the internal buffer before automatically flushing (default: 256)</dd>
10482+
<dt><strong><code>channel</code></strong></dt>
10483+
<dd>Channel to stream to</dd>
10484+
<dt><strong><code>thread_ts</code></strong></dt>
10485+
<dd>Thread timestamp to stream to (required)</dd>
10486+
<dt><strong><code>recipient_team_id</code></strong></dt>
10487+
<dd>Team ID of the recipient (for Slack Connect)</dd>
10488+
<dt><strong><code>recipient_user_id</code></strong></dt>
10489+
<dd>User ID of the recipient (for Slack Connect)</dd>
10490+
<dt><strong><code>unfurl_links</code></strong></dt>
10491+
<dd>Whether to unfurl links</dd>
10492+
<dt><strong><code>unfurl_media</code></strong></dt>
10493+
<dd>Whether to unfurl media</dd>
10494+
<dt><strong><code>**kwargs</code></strong></dt>
10495+
<dd>Additional arguments passed to the underlying API calls</dd>
10496+
</dl>
10497+
<h2 id="returns">Returns</h2>
10498+
<p>ChatStreamer instance for managing the stream</p>
10499+
<h2 id="example">Example</h2>
10500+
<pre><code class="language-python">streamer = client.chat_stream(
10501+
channel=&quot;C0123456789&quot;,
10502+
thread_ts=&quot;1700000001.123456&quot;,
10503+
recipient_team_id=&quot;T0123456789&quot;,
10504+
recipient_user_id=&quot;U0123456789&quot;,
10505+
)
10506+
streamer.append(markdown_text=&quot;**hello wo&quot;)
10507+
streamer.append(markdown_text=&quot;rld!**&quot;)
10508+
streamer.stop()
10509+
</code></pre></div>
10510+
</dd>
1034910511
<dt id="slack_sdk.WebClient.chat_unfurl"><code class="name flex">
1035010512
<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>
1035110513
</code></dt>
@@ -15323,6 +15485,7 @@ <h4><code><a title="slack_sdk.WebClient" href="#slack_sdk.WebClient">WebClient</
1532315485
<li><code><a title="slack_sdk.WebClient.chat_scheduledMessages_list" href="#slack_sdk.WebClient.chat_scheduledMessages_list">chat_scheduledMessages_list</a></code></li>
1532415486
<li><code><a title="slack_sdk.WebClient.chat_startStream" href="#slack_sdk.WebClient.chat_startStream">chat_startStream</a></code></li>
1532515487
<li><code><a title="slack_sdk.WebClient.chat_stopStream" href="#slack_sdk.WebClient.chat_stopStream">chat_stopStream</a></code></li>
15488+
<li><code><a title="slack_sdk.WebClient.chat_stream" href="#slack_sdk.WebClient.chat_stream">chat_stream</a></code></li>
1532615489
<li><code><a title="slack_sdk.WebClient.chat_unfurl" href="#slack_sdk.WebClient.chat_unfurl">chat_unfurl</a></code></li>
1532715490
<li><code><a title="slack_sdk.WebClient.chat_update" href="#slack_sdk.WebClient.chat_update">chat_update</a></code></li>
1532815491
<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)