UNPKG

@humanwhocodes/crosspost

Version:

A utility to post across multiple social networks.

167 lines (166 loc) 3.76 kB
/** * A strategy for posting messages to Slack. */ export class SlackStrategy { /** * Creates a new instance. * @param {SlackOptions} options Options for the instance. * @throws {Error} When options are missing. */ constructor(options: SlackOptions); /** * Maximum length of a Slack message in characters. * @type {number} * @const */ MAX_MESSAGE_LENGTH: number; /** * The ID of the strategy. * @type {string} * @readonly */ readonly id: string; /** * The display name of the strategy. * @type {string} * @readonly */ readonly name: string; /** * Calculates the length of a message according to Slack's algorithm. * All characters are counted as is. * @param {string} message The message to calculate the length of. * @returns {number} The calculated length of the message. */ calculateMessageLength(message: string): number; /** * Posts a message to Slack. * @param {string} message The message to post. * @param {PostOptions} [postOptions] Additional options for the post. * @returns {Promise<SlackMessageResponse>} A promise that resolves with the message data. * @throws {Error} When the message fails to post. */ post(message: string, postOptions?: PostOptions): Promise<SlackMessageResponse>; /** * Gets the URL for a response. * @param {SlackMessageResponse} response The response from posting. * @returns {string} The URL for the message. */ getUrlFromResponse(response: SlackMessageResponse): string; #private; } export type PostOptions = import("../types.js").PostOptions; export type SlackOptions = { /** * The Slack bot token. */ botToken: string; /** * The Slack channel ID or name to post to. */ channel: string; }; export type SlackMessageResponse = { /** * Whether the request was successful. */ ok: boolean; /** * The channel ID where the message was posted. */ channel: string; /** * The timestamp of the message. */ ts: string; /** * The message data. */ message: SlackMessage; }; export type SlackMessage = { /** * The text of the message. */ text: string; /** * The user ID who posted the message. */ user: string; /** * The timestamp of the message. */ ts: string; }; export type SlackErrorResponse = { /** * Whether the request was successful (false for errors). */ ok: boolean; /** * The error code. */ error: string; }; export type SlackUploadURLResponse = { /** * Whether the request was successful. */ ok: boolean; /** * The URL to upload the file to. */ upload_url: string; /** * The file ID for completing the upload. */ file_id: string; }; export type SlackUploadCompleteResponse = { /** * Whether the request was successful. */ ok: boolean; /** * The uploaded file information. */ files: SlackFileInfo[]; }; export type SlackFileInfo = { /** * The file ID. */ id: string; /** * The file title. */ title: string; /** * The permanent link to the file. */ permalink: string; }; export type SlackUploadResponse = { /** * Whether the request was successful. */ ok: boolean; /** * The uploaded file data. */ file: SlackFile; }; export type SlackFile = { /** * The file ID. */ id: string; /** * The file name. */ name: string; /** * The permanent link to the file. */ permalink: string; };