UNPKG

@atomist/slack-messages

Version:

Atomist utilities for creating formatted Slack messages

295 lines 8.88 kB
/** * Type defining the MIME types that the Slack message API accepts. */ export declare type MessageMimeType = "application/x-atomist-slack+json" | "application/x-atomist-slack-file+json" | "text/plain" | "application/json"; /** * Helper constants for the MIME types the Slack message API accepts. */ export declare const MessageMimeTypes: { [key: string]: MessageMimeType; }; /** * Construct and render slack messages according to Slack message * formatting: https://api.slack.com/docs/message-formatting. Customize * messages with rug actions. */ /** * Encode special Slack characters and HTML entities. */ export declare function escape(text: string): string; /** * Constructs slack link. * Label is automatically escaped. */ export declare function url(fullUrl: string, label?: string): string; /** * Mentions user (e.g. @anna). * When userName is provided will add readable user name. * * @param userId Slack user ID * @param userName alternative user name, which Slack seems to ignore * @return properly formatted Slack user mention */ export declare function user(userId: string, userName?: string): string; /** * Mentions channel (e.g. #general). * Will mention specific channel by channelId. * When channelName is provided will add readable channel name. */ export declare function channel(channelId: string, channelName?: string): string; /** Mentions @channel */ export declare function atChannel(): string; /** Mentions here (@here) */ export declare function atHere(): string; /** Mentions everyone (@everyone) */ export declare function atEveryone(): string; /** Renders JSON representation of slack message. */ export declare function render(message: SlackMessage, pretty?: boolean): string; /** Render emoji by name */ export declare function emoji(name: string): string; /** Render bold text */ export declare function bold(text: string): string; /** Render italic text */ export declare function italic(text: string): string; /** Render strike-through text */ export declare function strikethrough(text: string): string; /** Render single line code block */ export declare function codeLine(text: string): string; /** Render multiline code block */ export declare function codeBlock(text: string): string; /** Render bullet list item */ export declare function listItem(item: string): string; /** Represents slack message object. */ export interface SlackMessage { text?: string; attachments?: Attachment[]; blocks?: Block[]; unfurl_links?: boolean; unfurl_media?: boolean; } /** * Represent slack attachment. * https://api.slack.com/docs/interactive-message-field-guide#attachment_fields */ export interface Attachment { text?: string; fallback: string; mrkdwn_in?: string[]; color?: string; pretext?: string; author_name?: string; author_link?: string; author_icon?: string; title?: string; title_link?: string; fields?: Field[]; image_url?: string; thumb_url?: string; footer?: string; footer_icon?: string; ts?: number; actions?: Action[]; callback_id?: string; attachment_type?: string; } /** Represents slack attachment field. */ export interface Field { title?: string; value?: string; short?: boolean; } export interface SelectOption { text: string; value: string; } export interface OptionGroup { text: string; options: SelectOption[]; } export declare type DataSource = "static" | "users" | "channels" | "conversations" | "external"; /** * Represents Slack action. * Only button is currently supported. */ export interface Action { text: string; name: string; type: ActionType; value?: string; style?: string; confirm?: ActionConfirmation; options?: SelectOption[]; option_groups?: OptionGroup[]; data_source?: DataSource; } /** Represents Slack action confirmation. */ export interface ActionConfirmation { title?: string; text: string; ok_text?: string; dismiss_text?: string; } export declare type ActionType = "button" | "select"; export interface Block { type: "actions" | "context" | "divider" | "file" | "header" | "image" | "section" | "input"; block_id?: string; } export interface ActionsBlock extends Block { type: "actions"; elements: Array<ButtonElement | CheckboxesElement | PlainTextElement | RadioButtonsElement | StaticOptionElement | UserOptionElement | ConversationOptionElement | ChannelOptionElement | DatePickerElement | OverflowElement>; } export interface ContextBlock extends Block { type: "context"; elements: Array<TextObject | ImageElement>; } export interface DividerBlock { type: "divider"; } export interface FileBlock { type: "file"; external_id: string; source: string; } export interface HeaderBlock { type: "header"; text: PlainTextObject; } export interface ImageBlock { type: "image"; image_url: string; alt_text: string; title?: PlainTextObject; } export interface SectionBlock { type: "section"; text: TextObject; fields?: TextObject[]; accessory?: Element; } export interface Element { type: "button" | "checkboxes" | "datepicker" | "image" | "multi_static_select" | "multi_users_select" | "multi_conversations_select" | "multi_channels_select" | "overflow" | "plain_text_input" | "radio_buttons" | "static_select" | "users_select" | "conversations_select" | "channels_select"; action_id?: string; } export interface TextObject { type: "plain_text" | "mrkdwn"; text: string; emoji?: boolean; verbatim?: boolean; } export interface ConfirmObject { title: string; text: string; confirm: string; deny: string; style?: "primary" | "danger"; } export interface PlainTextObject extends TextObject { type: "plain_text"; } export interface ButtonElement extends Element { type: "button"; text: PlainTextObject; url?: string; value?: string; style?: "primary" | "danger"; confirm?: ConfirmObject; } export interface CheckboxesElement extends Element { type: "checkboxes"; options: OptionObject[]; initial_option?: OptionObject; confirm?: ConfirmObject; } export interface DatePickerElement extends Element { type: "datepicker"; placeholder: PlainTextObject; initial_date?: string; confirm?: ConfirmObject; } export interface ImageElement extends Element { type: "image"; image_url: string; alt_text: string; } export interface OverflowElement extends Element { type: "overflow"; options: OptionObject[]; confirm?: ConfirmObject; } export interface PlainTextElement extends Element { type: "plain_text_input"; placeholder?: PlainTextObject; initial_value?: string; multiline?: boolean; min_length?: number; max_length?: number; } export interface RadioButtonsElement extends Element { type: "radio_buttons"; options: OptionObject[]; initial_option?: OptionObject; confirm?: ConfirmObject; } export interface OptionObject { text: PlainTextObject; value: string; description?: string; url?: string; } export interface StaticOptionElement extends Element { type: "static_select"; placeholder: PlainTextObject; options?: OptionObject[]; option_groups?: Array<{ label: PlainTextObject; options: OptionObject[]; }>; initial_option?: OptionObject; confirm?: ConfirmObject; } export interface UserOptionElement extends Element { type: "users_select"; placeholder: PlainTextObject; initial_user?: string; confirm?: ConfirmObject; } export interface ConversationOptionElement extends Element { type: "conversations_select"; placeholder: PlainTextObject; initial_conversation?: string; default_to_current_conversation?: boolean; confirm?: ConfirmObject; response_url_enabled?: boolean; filter?: { include?: string[]; exclude_external_shared_channels?: boolean; exclude_bot_users?: boolean; }; } export interface ChannelOptionElement extends Element { type: "channels_select"; placeholder: PlainTextObject; initial_channel?: string; confirm?: ConfirmObject; response_url_enabled?: boolean; } export interface SlackModal { type: "modal"; title: PlainTextObject; blocks: Block[]; close?: PlainTextObject; submit?: PlainTextObject; private_metadata?: string; callback_id?: string; clear_on_close?: boolean; notify_on_close?: boolean; external_id?: boolean; } export interface InputBlock extends Block { type: "input"; label: PlainTextObject; element: PlainTextElement | DatePickerElement | StaticOptionElement | UserOptionElement | ConversationOptionElement | ChannelOptionElement; hint?: PlainTextObject; optional?: boolean; } //# sourceMappingURL=SlackMessages.d.ts.map