MCPcopy Index your code
hub / github.com/slackapi/python-slack-sdk / append

Method append

slack_sdk/web/async_chat_stream.py:98–152  ·  view source on GitHub ↗

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,
    )

Source from the content-addressed store, hash-verified

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

Callers 2

stopMethod · 0.45
_flush_bufferMethod · 0.45

Calls 3

_flush_bufferMethod · 0.95
getMethod · 0.45
debugMethod · 0.45

Tested by

no test coverage detected