/** * Utility functions for Slack bubble * Handles markdown to Slack blocks conversion and mrkdwn formatting */ /** * Slack block types for rich message formatting */ export interface SlackTextObject { type: 'plain_text' | 'mrkdwn'; text: string; emoji?: boolean; verbatim?: boolean; } export interface SlackSectionBlock { type: 'section'; text: SlackTextObject; } export interface SlackDividerBlock { type: 'divider'; } export interface SlackHeaderBlock { type: 'header'; text: SlackTextObject; } export interface SlackContextBlock { type: 'context'; elements: SlackTextObject[]; } export interface SlackTableCellRawText { type: 'raw_text'; text: string; } export interface SlackTableCellRichText { type: 'rich_text'; elements: unknown[]; } export type SlackTableCell = SlackTableCellRawText | SlackTableCellRichText; export interface SlackTableColumnSetting { align?: 'left' | 'center' | 'right'; is_wrapped?: boolean; } export interface SlackTableBlock { type: 'table'; rows: SlackTableCell[][]; column_settings?: SlackTableColumnSetting[]; block_id?: string; } export interface SlackImageBlock { type: 'image'; image_url: string; alt_text: string; title?: SlackTextObject; block_id?: string; } export type SlackBlock = SlackSectionBlock | SlackDividerBlock | SlackHeaderBlock | SlackContextBlock | SlackTableBlock | SlackImageBlock; /** * Options for markdown to blocks conversion */ export interface MarkdownToBlocksOptions { /** * Whether to convert headers to header blocks (true) or bold section blocks (false) * Header blocks have larger text but limited formatting * @default false */ useHeaderBlocks?: boolean; /** * Whether to add dividers after headers * @default false */ addDividersAfterHeaders?: boolean; /** * Whether to preserve line breaks within paragraphs * @default true */ preserveLineBreaks?: boolean; } /** * Converts standard markdown text formatting to Slack mrkdwn format. * * Conversions: * - **bold** or __bold__ → *bold* * - *italic* (when not **) or _italic_ (when not __) → _italic_ * - ~~strikethrough~~ → ~strikethrough~ * - `code` → `code` (unchanged) * - [text](url) → * - > blockquote → > blockquote (unchanged, Slack supports this) * * @param markdown - Standard markdown text * @returns Slack mrkdwn formatted text */ export declare function markdownToMrkdwn(markdown: string): string; /** * Converts markdown text to an array of Slack blocks for rich message formatting. * * This function parses markdown and creates appropriate Slack block types: * - Headers → header blocks or bold section blocks * - Paragraphs → section blocks with mrkdwn * - Code blocks → section blocks with code formatting * - Horizontal rules → divider blocks * - Block quotes → section blocks with quote formatting * - Lists → section blocks with bullet formatting * * @param markdown - Standard markdown text * @param options - Conversion options * @returns Array of Slack blocks * * @example * ```typescript * const blocks = markdownToBlocks(` * # Welcome * * This is **bold** and _italic_ text. * * - Item 1 * - Item 2 * * \`\`\`javascript * const x = 1; * \`\`\` * `); * * // Returns: * // [ * // { type: 'section', text: { type: 'mrkdwn', text: '*Welcome*' } }, * // { type: 'section', text: { type: 'mrkdwn', text: 'This is *bold* and _italic_ text.' } }, * // { type: 'section', text: { type: 'mrkdwn', text: '• Item 1\n• Item 2' } }, * // { type: 'section', text: { type: 'mrkdwn', text: '```const x = 1;```' } } * // ] * ``` */ export declare function markdownToBlocks(markdown: string, options?: MarkdownToBlocksOptions): SlackBlock[]; /** * Creates a simple text message with optional markdown formatting. * Use this for simple messages that don't need complex block structure. * * @param text - Text to send (supports markdown) * @param useMrkdwn - Whether to convert markdown to Slack mrkdwn format * @returns A single section block with the formatted text */ export declare function createTextBlock(text: string, useMrkdwn?: boolean): SlackSectionBlock; /** * Creates a divider block for visual separation */ export declare function createDividerBlock(): SlackDividerBlock; /** * Creates a header block with plain text * Note: Header blocks have a 150 character limit * * @param text - Header text (will be truncated to 150 chars) */ export declare function createHeaderBlock(text: string): SlackHeaderBlock; /** * Creates a context block for secondary information * Context blocks display smaller text, useful for timestamps, metadata, etc. * * @param texts - Array of text strings to display */ export declare function createContextBlock(texts: string[]): SlackContextBlock; /** * Slack table block constraints */ export declare const SLACK_TABLE_MAX_ROWS = 1000; export declare const SLACK_TABLE_MAX_COLUMNS = 20; export interface TableChunkInfo { block: SlackTableBlock; /** 1-based start row (data rows, not counting header) */ rowStart: number; /** 1-based end row (inclusive) */ rowEnd: number; } export interface CreateTableBlockResult { tableBlock: SlackTableBlock; /** Additional table chunks when a single table exceeds Slack's character limit */ overflowChunks?: TableChunkInfo[]; /** Total data row count across all chunks */ totalDataRows: number; overflowCsv?: string; wasTruncated: boolean; originalRowCount: number; } /** * Creates a Slack table block from headers and rows. * Truncates to fit Slack's limits (100 rows including header, 20 columns). * If rows exceed the limit, generates a CSV containing all data. * * @param headers - Column header strings * @param rows - 2D array of cell values * @param columnSettings - Optional column alignment/wrapping settings * @returns Table block, optional CSV overflow, and truncation info */ export declare function createTableBlock(headers: string[], rows: string[][], columnSettings?: SlackTableColumnSetting[]): CreateTableBlockResult; /** * Splits long text into chunks that fit within Slack's block text limit. * Attempts to split at paragraph boundaries first, then at sentence boundaries, * and finally at word boundaries if necessary. * * @param text - Text to split * @param maxLength - Maximum length per chunk (default: 3000) * @returns Array of text chunks, each within the limit */ export declare function splitLongText(text: string, maxLength?: number): string[]; /** * Processes an array of Slack blocks, splitting any that exceed the text limit. * * @param blocks - Array of Slack blocks * @returns Array of blocks with long texts split into multiple blocks */ export declare function splitLongBlocks(blocks: SlackBlock[]): SlackBlock[]; /** * Splits an array of Slack blocks into chunks so that each chunk contains * at most one table block. Slack only allows a single table block per message, * so this lets the caller send each chunk as a separate message. * * Non-table blocks are grouped with the nearest following table. If there are * no subsequent tables, trailing blocks stay in the last chunk. * * @returns The original array wrapped in a single-element array if there are * 0 or 1 table blocks; otherwise an array of chunk arrays. */ export declare function splitBlocksByTable(blocks: SlackBlock[]): SlackBlock[][]; /** * Detects if a string contains markdown formatting. * Checks for common markdown patterns like headers, bold, italic, code blocks, lists, etc. * * @param text - Text to check for markdown * @returns True if markdown patterns are detected */ export declare function containsMarkdown(text: string): boolean; //# sourceMappingURL=slack.utils.d.ts.map