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