Comprehensive TypeScript type definitions for building Slack applications and integrations with the Node Slack SDK
npx @tessl/cli install tessl/npm-slack--types@2.16.0@slack/types provides comprehensive TypeScript type definitions for building Slack applications and integrations with the Node Slack SDK. This package serves as the foundational type system for the entire Slack development ecosystem, offering strongly-typed interfaces for Block Kit components, event handling, message formatting, and all Slack API interactions.
npm install @slack/typesimport {
Button,
SectionBlock,
PlainTextElement,
SlackEvent,
ModalView,
MessageAttachment,
MessageMetadata,
Dialog,
BotProfile
} from "@slack/types";For CommonJS:
const {
Button,
SectionBlock,
PlainTextElement,
SlackEvent,
ModalView,
MessageAttachment,
MessageMetadata,
Dialog,
BotProfile
} = require("@slack/types");import { SectionBlock, PlainTextElement, Button } from "@slack/types";
// Define a section block with text and button
const section: SectionBlock = {
type: "section",
text: {
type: "plain_text",
text: "Hello from Slack!"
},
accessory: {
type: "button",
text: {
type: "plain_text",
text: "Click me"
},
value: "button_1",
action_id: "button_action"
}
};
// Use in a message or modal
const message = {
blocks: [section]
};@slack/types is organized around several key architectural patterns:
type field as the discriminator for type safetyActionable, Confirmable are mixed into concrete interfacesCore building blocks for creating rich, interactive Slack interfaces including blocks, elements, and composition objects. Essential for building modern Slack apps with sophisticated UI components.
// Block types
type KnownBlock = ActionsBlock | ContextBlock | DividerBlock | FileBlock | HeaderBlock | ImageBlock | InputBlock | MarkdownBlock | RichTextBlock | SectionBlock | VideoBlock;
// Key block interfaces
interface SectionBlock extends Block {
type: 'section';
text?: TextObject;
fields?: TextObject[];
accessory?: SectionBlockAccessory;
expand?: boolean;
}
interface ActionsBlock extends Block {
type: 'actions';
elements: ActionsBlockElement[];
}Complete set of interactive UI components for user input including buttons, select menus, date pickers, and text inputs. These elements enable rich user interactions within Slack interfaces.
interface Button extends Actionable, Confirmable {
type: 'button';
text: PlainTextElement;
value?: string;
url?: string;
style?: ColorScheme;
accessibility_label?: string;
}
interface PlainTextInput extends Actionable, Dispatchable, Focusable, Placeholdable {
type: 'plain_text_input';
initial_value?: string;
multiline?: boolean;
min_length?: number;
max_length?: number;
}Comprehensive event type definitions for all Slack Events API events including message events, user events, channel events, and app events. Essential for building reactive Slack applications.
type SlackEvent = AppDeletedEvent | AppHomeOpenedEvent | AppMentionEvent | ChannelCreatedEvent | MessageEvent | UserChangeEvent | /* ...70+ more event types */;
interface MessageEvent {
type: 'message';
channel: string;
user: string;
text: string;
ts: string;
thread_ts?: string;
blocks?: AnyBlock[];
}Type definitions for Slack surfaces including modals, App Home tabs, and workflow step configuration views. Critical for building interactive Slack applications with sophisticated user interfaces.
type View = HomeView | ModalView | WorkflowStepView;
interface ModalView extends BaseView {
type: 'modal';
title: PlainTextElement;
close?: PlainTextElement;
submit?: PlainTextElement;
clear_on_close?: boolean;
notify_on_close?: boolean;
}Legacy message attachment system for adding rich content to messages. While Block Kit is preferred for new development, attachments remain supported for backward compatibility.
interface MessageAttachment {
blocks?: AnyBlock[];
fallback?: string;
color?: 'good' | 'warning' | 'danger' | string;
title?: string;
text?: string;
fields?: MessageAttachmentField[];
image_url?: string;
footer?: string;
}Type definitions for Slack Calls API enabling 3rd party call integrations within the Slack client. Used for displaying external call information and participants.
type CallUser = CallUserSlack | CallUserExternal;
interface CallUserSlack {
slack_id: string;
}
interface CallUserExternal {
external_id: string;
display_name: string;
avatar_url?: string;
}Application-specific data that can be attached to Slack messages to enable rich interactive experiences and custom workflows. Essential for building contextual applications.
interface MessageMetadata {
/** Human readable alphanumeric string representing your application's metadata event */
event_type: string;
/** Free-form object containing whatever data your application wishes to attach */
event_payload: {
[key: string]: string | number | boolean | MessageMetadataEventPayloadObject | MessageMetadataEventPayloadObject[];
};
}
interface MessageMetadataEventPayloadObject {
[key: string]: string | number | boolean;
}Legacy dialog interface for simple form collection. This interface is deprecated in favor of Block Kit modals but remains available for backward compatibility.
/**
* @deprecated Dialogs are deprecated. Use Block Kit modals instead.
*/
interface Dialog {
title: string;
callback_id: string;
elements: DialogElement[];
submit_label?: string;
notify_on_cancel?: boolean;
state?: string;
}type TextObject = PlainTextElement | MrkdwnElement;
interface PlainTextElement {
type: 'plain_text';
text: string;
emoji?: boolean;
}
interface MrkdwnElement {
type: 'mrkdwn';
text: string;
verbatim?: boolean;
}type ColorScheme = 'primary' | 'danger';
type ConversationType = 'im' | 'mpim' | 'private' | 'public';interface Actionable {
type: string;
action_id?: string;
}
interface Confirmable {
confirm?: ConfirmationDialog;
}
interface Placeholdable {
placeholder?: PlainTextElement;
}interface BotProfile {
id: string;
name: string;
app_id: string;
team_id: string;
icons: {
[size: string]: string;
};
updated: number;
deleted: boolean;
}
interface StatusEmojiDisplayInfo {
emoji_name?: string;
display_alias?: string;
display_url?: string;
}