@slack/web-api / ChatStreamer
Class: ChatStreamer
Defined in: packages/web-api/src/chat-stream.ts:15
Constructors
Constructor
new ChatStreamer(
client,
logger,
args,
options): ChatStreamer;
Defined in: packages/web-api/src/chat-stream.ts:47
Instantiate a new chat streamer.
Parameters
client
logger
args
options
Returns
ChatStreamer
Description
The "constructor" method creates a unique ChatStreamer instance that keeps track of one chat stream.
Example
const client = new WebClient(process.env.SLACK_BOT_TOKEN);
const logger = new ConsoleLogger();
const args = {
channel: "C0123456789",
thread_ts: "1700000001.123456",
recipient_team_id: "T0123456789",
recipient_user_id: "U0123456789",
};
const streamer = new ChatStreamer(client, logger, args, { buffer_size: 512 });
await streamer.append({
markdown_text: "**hello world!**",
});
await streamer.stop();
See
- https://docs.slack.dev/reference/methods/chat.startStream
- https://docs.slack.dev/reference/methods/chat.appendStream
- https://docs.slack.dev/reference/methods/chat.stopStream
Methods
append()
append(args): Promise<
| ChatAppendStreamResponse
| ChatStartStreamResponse
| null>;
Defined in: packages/web-api/src/chat-stream.ts:77
Append to the stream.
Parameters
args
Omit<ChatAppendStreamArguments, "channel" | "ts">
Returns
Promise<
| ChatAppendStreamResponse
| ChatStartStreamResponse
| null>
Description
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.
Example
const streamer = client.chatStream({
channel: "C0123456789",
thread_ts: "1700000001.123456",
recipient_team_id: "T0123456789",
recipient_user_id: "U0123456789",
});
await streamer.append({
markdown_text: "**hello wo",
});
await streamer.append({
markdown_text: "rld!**",
});
await streamer.stop();
See
https://docs.slack.dev/reference/methods/chat.appendStream
stop()
stop(args?): Promise<ChatStopStreamResponse>;
Defined in: packages/web-api/src/chat-stream.ts:123
Stop the stream and finalize the message.
Parameters
args?
Omit<ChatStopStreamArguments, "channel" | "ts">
Returns
Promise<ChatStopStreamResponse>
Description
The "stop" method stops the chat stream being used. This method can be called once to end the stream. Additional "blocks" and "metadata" can be provided.
Example
const streamer = client.chatStream({
channel: "C0123456789",
thread_ts: "1700000001.123456",
recipient_team_id: "T0123456789",
recipient_user_id: "U0123456789",
});
await streamer.append({
markdown_text: "**hello world!**",
});
await streamer.stop();