Append to the stream. The "append" method appends to the chat stream being used. This method can be called multiple times. After the stream is stopped this method cannot be called. Args: chunks: An array of streaming chunks. Chunks can be markdown text, plan, or
(
self,
*,
markdown_text: Optional[str] = None,
chunks: Optional[Sequence[Union[Dict, Chunk]]] = None,
**kwargs,
)
| 86 | return self._stream_ts |
| 87 | |
| 88 | def append( |
| 89 | self, |
| 90 | *, |
| 91 | markdown_text: Optional[str] = None, |
| 92 | chunks: Optional[Sequence[Union[Dict, Chunk]]] = None, |
| 93 | **kwargs, |
| 94 | ) -> Optional[SlackResponse]: |
| 95 | """Append to the stream. |
| 96 | |
| 97 | The "append" method appends to the chat stream being used. This method can be called multiple times. After the stream |
| 98 | is stopped this method cannot be called. |
| 99 | |
| 100 | Args: |
| 101 | chunks: An array of streaming chunks. Chunks can be markdown text, plan, or task update chunks. |
| 102 | markdown_text: Accepts message text formatted in markdown. Limit this field to 12,000 characters. This text is |
| 103 | what will be appended to the message received so far. |
| 104 | **kwargs: Additional arguments passed to the underlying API calls. |
| 105 | |
| 106 | Returns: |
| 107 | SlackResponse if the buffer was flushed, None if buffering. |
| 108 | |
| 109 | Raises: |
| 110 | SlackRequestError: If the stream is already completed. |
| 111 | |
| 112 | Example: |
| 113 | ```python |
| 114 | streamer = client.chat_stream( |
| 115 | channel="C0123456789", |
| 116 | thread_ts="1700000001.123456", |
| 117 | recipient_team_id="T0123456789", |
| 118 | recipient_user_id="U0123456789", |
| 119 | ) |
| 120 | streamer.append(markdown_text="**hello wo") |
| 121 | streamer.append(markdown_text="rld!**") |
| 122 | streamer.stop() |
| 123 | ``` |
| 124 | """ |
| 125 | if self._state == "completed": |
| 126 | raise e.SlackRequestError(f"Cannot append to stream: stream state is {self._state}") |
| 127 | if kwargs.get("token"): |
| 128 | self._token = kwargs.pop("token") |
| 129 | if markdown_text is not None: |
| 130 | self._buffer += markdown_text |
| 131 | if len(self._buffer) >= self._buffer_size or chunks is not None: |
| 132 | return self._flush_buffer(chunks=chunks, **kwargs) |
| 133 | details = { |
| 134 | "buffer_length": len(self._buffer), |
| 135 | "buffer_size": self._buffer_size, |
| 136 | "channel": self._stream_args.get("channel"), |
| 137 | "recipient_team_id": self._stream_args.get("recipient_team_id"), |
| 138 | "recipient_user_id": self._stream_args.get("recipient_user_id"), |
| 139 | "thread_ts": self._stream_args.get("thread_ts"), |
| 140 | } |
| 141 | self._logger.debug(f"ChatStream appended to buffer: {json.dumps(details)}") |
| 142 | return None |
| 143 | |
| 144 | def stop( |
| 145 | self, |