Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/add-blocks-chunk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@slack/types': patch
---

Add `BlocksChunk` type for passing Block Kit blocks within streaming messages
14 changes: 13 additions & 1 deletion packages/types/src/chunk.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import type { URLSourceElement } from './block-kit/block-elements';
import type { AnyBlock } from './block-kit/blocks';

/**
* Base interface for streaming message chunks.
* https://docs.slack.dev/messaging/sending-and-scheduling-messages#text-streaming
Expand All @@ -7,6 +9,16 @@ export interface Chunk {
type: string;
}

/**
* Used for passing an array of blocks within a streaming message.
* https://docs.slack.dev/changelog/2026/04/16/block-kit-new-blocks/
*/
export interface BlocksChunk extends Chunk {
type: 'blocks';
/** @description An array of {@link AnyBlock} objects. Maximum of 50 blocks. */
blocks: AnyBlock[];
}

/**
* Used for streaming text content with markdown formatting support.
* https://docs.slack.dev/messaging/sending-and-scheduling-messages#text-streaming
Expand Down Expand Up @@ -42,4 +54,4 @@ export interface TaskUpdateChunk extends Chunk {
/**
* Union type of all possible chunk types
*/
export type AnyChunk = MarkdownTextChunk | PlanUpdateChunk | TaskUpdateChunk;
export type AnyChunk = BlocksChunk | MarkdownTextChunk | PlanUpdateChunk | TaskUpdateChunk;
32 changes: 32 additions & 0 deletions packages/types/test/chunk.test-d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { expectAssignable, expectError } from 'tsd';
import type { AnyChunk, BlocksChunk } from '../src/index';

// BlocksChunk
// -- sad path
expectError<BlocksChunk>({});
expectError<BlocksChunk>({ type: 'blocks' });
expectError<BlocksChunk>({ blocks: [] });

// -- happy path
expectAssignable<BlocksChunk>({ type: 'blocks', blocks: [] });
expectAssignable<BlocksChunk>({
type: 'blocks',
blocks: [
{
type: 'section',
text: { type: 'plain_text', text: "Sandra's plan outline" },
},
],
});
expectAssignable<BlocksChunk>({
type: 'blocks',
blocks: [{ type: 'divider' }, { type: 'header', text: { type: 'plain_text', text: 'Hello' } }],
});
// Unknown block types accepted via generic Block interface
expectAssignable<BlocksChunk>({
type: 'blocks',
blocks: [{ type: 'future_block_type' }],
});

// BlocksChunk is assignable to AnyChunk
expectAssignable<AnyChunk>({ type: 'blocks', blocks: [] });
12 changes: 12 additions & 0 deletions packages/web-api/test/types/methods/chat.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ expectAssignable<Parameters<typeof web.chat.appendStream>>([
channel: 'C1234',
ts: '1234.56',
chunks: [
{
type: 'blocks',
blocks: [{ type: 'section', text: { type: 'mrkdwn', text: 'Hello' } }],
},
{
type: 'markdown_text',
text: 'Hello world',
Expand Down Expand Up @@ -789,6 +793,10 @@ expectAssignable<Parameters<typeof web.chat.startStream>>([
channel: 'C1234',
thread_ts: '1234.56',
chunks: [
{
type: 'blocks',
blocks: [{ type: 'section', text: { type: 'mrkdwn', text: 'Hello' } }],
},
{
type: 'markdown_text',
text: 'Hello world',
Expand Down Expand Up @@ -913,6 +921,10 @@ expectAssignable<Parameters<typeof web.chat.stopStream>>([
channel: 'C1234',
ts: '1234.56',
chunks: [
{
type: 'blocks',
blocks: [{ type: 'section', text: { type: 'mrkdwn', text: 'Hello' } }],
},
{
type: 'markdown_text',
text: 'Hello world',
Expand Down
Loading