Stop the stream and finalize the message. Args: blocks: A list of blocks that will be rendered at the bottom of the finalized message. chunks: An array of streaming chunks. Chunks can be markdown text, plan, or task update chunks. markdown_text: Accepts m
(
self,
*,
markdown_text: Optional[str] = None,
chunks: Optional[Sequence[Union[Dict, Chunk]]] = None,
blocks: Optional[Union[str, Sequence[Union[Dict, Block]]]] = None,
metadata: Optional[Union[Dict, Metadata]] = None,
**kwargs,
)
| 152 | return None |
| 153 | |
| 154 | async def stop( |
| 155 | self, |
| 156 | *, |
| 157 | markdown_text: Optional[str] = None, |
| 158 | chunks: Optional[Sequence[Union[Dict, Chunk]]] = None, |
| 159 | blocks: Optional[Union[str, Sequence[Union[Dict, Block]]]] = None, |
| 160 | metadata: Optional[Union[Dict, Metadata]] = None, |
| 161 | **kwargs, |
| 162 | ) -> AsyncSlackResponse: |
| 163 | """Stop the stream and finalize the message. |
| 164 | |
| 165 | Args: |
| 166 | blocks: A list of blocks that will be rendered at the bottom of the finalized message. |
| 167 | chunks: An array of streaming chunks. Chunks can be markdown text, plan, or task update chunks. |
| 168 | markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is |
| 169 | what will be appended to the message received so far. |
| 170 | metadata: JSON object with event_type and event_payload fields, presented as a URL-encoded string. Metadata you |
| 171 | post to Slack is accessible to any app or user who is a member of that workspace. |
| 172 | **kwargs: Additional arguments passed to the underlying API calls. |
| 173 | |
| 174 | Returns: |
| 175 | AsyncSlackResponse from the chat.stopStream API call. |
| 176 | |
| 177 | Raises: |
| 178 | SlackRequestError: If the stream is already completed. |
| 179 | |
| 180 | Example: |
| 181 | ```python |
| 182 | streamer = client.chat_stream( |
| 183 | channel="C0123456789", |
| 184 | thread_ts="1700000001.123456", |
| 185 | recipient_team_id="T0123456789", |
| 186 | recipient_user_id="U0123456789", |
| 187 | ) |
| 188 | streamer.append(markdown_text="**hello wo") |
| 189 | streamer.append(markdown_text="rld!**") |
| 190 | streamer.stop() |
| 191 | ``` |
| 192 | """ |
| 193 | if self._state == "completed": |
| 194 | raise e.SlackRequestError(f"Cannot stop stream: stream state is {self._state}") |
| 195 | if kwargs.get("token"): |
| 196 | self._token = kwargs.pop("token") |
| 197 | if markdown_text: |
| 198 | self._buffer += markdown_text |
| 199 | if not self._stream_ts: |
| 200 | response = await self._client.chat_startStream( |
| 201 | **self._stream_args, |
| 202 | token=self._token, |
| 203 | ) |
| 204 | if not response.get("ts"): |
| 205 | raise e.SlackRequestError("Failed to stop stream: stream not started") |
| 206 | self._stream_ts = str(response["ts"]) |
| 207 | self._state = "in_progress" |
| 208 | flushings: List[Union[Dict, Chunk]] = [] |
| 209 | if len(self._buffer) != 0: |
| 210 | flushings.append(MarkdownTextChunk(text=self._buffer)) |
| 211 | if chunks is not None: |
nothing calls this directly
no test coverage detected