Skip to content

Commit 5bc7685

Browse files
authored
feat(types): add BlockChunk type to chat.{start,append,stop}Stream methods (#2580)
1 parent 21b0839 commit 5bc7685

4 files changed

Lines changed: 62 additions & 1 deletion

File tree

.changeset/add-blocks-chunk.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@slack/types': patch
3+
---
4+
5+
Add `BlocksChunk` type for passing Block Kit blocks within streaming messages

packages/types/src/chunk.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import type { URLSourceElement } from './block-kit/block-elements';
2+
import type { AnyBlock } from './block-kit/blocks';
3+
24
/**
35
* Base interface for streaming message chunks.
46
* https://docs.slack.dev/messaging/sending-and-scheduling-messages#text-streaming
@@ -7,6 +9,16 @@ export interface Chunk {
79
type: string;
810
}
911

12+
/**
13+
* Used for passing an array of blocks within a streaming message.
14+
* https://docs.slack.dev/changelog/2026/04/16/block-kit-new-blocks/
15+
*/
16+
export interface BlocksChunk extends Chunk {
17+
type: 'blocks';
18+
/** @description An array of {@link AnyBlock} objects. Maximum of 50 blocks. */
19+
blocks: AnyBlock[];
20+
}
21+
1022
/**
1123
* Used for streaming text content with markdown formatting support.
1224
* https://docs.slack.dev/messaging/sending-and-scheduling-messages#text-streaming
@@ -42,4 +54,4 @@ export interface TaskUpdateChunk extends Chunk {
4254
/**
4355
* Union type of all possible chunk types
4456
*/
45-
export type AnyChunk = MarkdownTextChunk | PlanUpdateChunk | TaskUpdateChunk;
57+
export type AnyChunk = BlocksChunk | MarkdownTextChunk | PlanUpdateChunk | TaskUpdateChunk;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { expectAssignable, expectError } from 'tsd';
2+
import type { AnyChunk, BlocksChunk } from '../src/index';
3+
4+
// BlocksChunk
5+
// -- sad path
6+
expectError<BlocksChunk>({});
7+
expectError<BlocksChunk>({ type: 'blocks' });
8+
expectError<BlocksChunk>({ blocks: [] });
9+
10+
// -- happy path
11+
expectAssignable<BlocksChunk>({ type: 'blocks', blocks: [] });
12+
expectAssignable<BlocksChunk>({
13+
type: 'blocks',
14+
blocks: [
15+
{
16+
type: 'section',
17+
text: { type: 'plain_text', text: "Sandra's plan outline" },
18+
},
19+
],
20+
});
21+
expectAssignable<BlocksChunk>({
22+
type: 'blocks',
23+
blocks: [{ type: 'divider' }, { type: 'header', text: { type: 'plain_text', text: 'Hello' } }],
24+
});
25+
// Unknown block types accepted via generic Block interface
26+
expectAssignable<BlocksChunk>({
27+
type: 'blocks',
28+
blocks: [{ type: 'future_block_type' }],
29+
});
30+
31+
// BlocksChunk is assignable to AnyChunk
32+
expectAssignable<AnyChunk>({ type: 'blocks', blocks: [] });

packages/web-api/test/types/methods/chat.test-d.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ expectAssignable<Parameters<typeof web.chat.appendStream>>([
3232
channel: 'C1234',
3333
ts: '1234.56',
3434
chunks: [
35+
{
36+
type: 'blocks',
37+
blocks: [{ type: 'section', text: { type: 'mrkdwn', text: 'Hello' } }],
38+
},
3539
{
3640
type: 'markdown_text',
3741
text: 'Hello world',
@@ -789,6 +793,10 @@ expectAssignable<Parameters<typeof web.chat.startStream>>([
789793
channel: 'C1234',
790794
thread_ts: '1234.56',
791795
chunks: [
796+
{
797+
type: 'blocks',
798+
blocks: [{ type: 'section', text: { type: 'mrkdwn', text: 'Hello' } }],
799+
},
792800
{
793801
type: 'markdown_text',
794802
text: 'Hello world',
@@ -913,6 +921,10 @@ expectAssignable<Parameters<typeof web.chat.stopStream>>([
913921
channel: 'C1234',
914922
ts: '1234.56',
915923
chunks: [
924+
{
925+
type: 'blocks',
926+
blocks: [{ type: 'section', text: { type: 'mrkdwn', text: 'Hello' } }],
927+
},
916928
{
917929
type: 'markdown_text',
918930
text: 'Hello world',

0 commit comments

Comments
 (0)