Skip to main content

@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​

WebClient

logger​

Logger

args​

ChatStartStreamArguments

options​

ChatStreamerOptions

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​

Accessors​

ts​

Get Signature​

get ts(): string | undefined;

Defined in: packages/web-api/src/chat-stream.ts:62

Description​

The message timestamp of the stream. Returns undefined until the first flush (when chat.startStream is called).

See​

https://docs.slack.dev/reference/methods/chat.update

Returns​

string | undefined

Methods​

append()​

append(args): Promise<
| ChatAppendStreamResponse
| ChatStartStreamResponse
| null>;

Defined in: packages/web-api/src/chat-stream.ts:86

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:132

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();

See​

https://docs.slack.dev/reference/methods/chat.stopStream