UNPKG

@humanwhocodes/crosspost

Version:

A utility to post across multiple social networks.

96 lines (95 loc) 3.29 kB
/** * @typedef {Object} TwitterOptions * @property {string} accessTokenKey The access token for the Twitter app. * @property {string} accessTokenSecret The access token secret for the Twitter app. * @property {string} apiConsumerKey The app (consumer) key for the Twitter app. * @property {string} apiConsumerSecret The app (consumer) secret for the Twitter app. * * @typedef {Object} TwitterPostResponse * @property {Object} data The data of the posted tweet. * @property {string} data.id The ID of the tweet. * @property {string} data.text The text content of the tweet. * @property {string[]} data.edit_history_tweet_ids The edit history tweet IDs. */ /** @typedef {[string]|[string,string]|[string,string,string]|[string,string,string,string]} TwitterMediaIdArray */ /** @typedef {import("../types.js").PostOptions} PostOptions */ /** * A strategy for posting to Twitter. */ export class TwitterStrategy { /** * Creates a new instance. * @param {TwitterOptions} options Options for the instance. * @throws {Error} When options are missing. */ constructor(options: TwitterOptions); /** * The ID of the strategy. * @type {string} * @readonly */ readonly id: string; /** * The display name of the strategy. * @type {string} * @readonly */ readonly name: string; /** * Posts a message to Twitter. * @param {string} message The message to tweet. * @param {PostOptions} [postOptions] Additional options for the post. * @returns {Promise<object>} A promise that resolves with the tweet data. */ post(message: string, postOptions?: PostOptions): Promise<object>; /** * Extracts a URL from a Twitter API response. * @param {TwitterPostResponse} response The response from the Twitter API post request. * @returns {string} The URL for the tweet. */ getUrlFromResponse(response: TwitterPostResponse): string; /** * Maximum length of a tweet in characters. * @type {number} * @const */ MAX_MESSAGE_LENGTH: number; /** * Calculates the length of a message according to Twitter's algorithm. * URLs are counted as 23 characters for http:// or https:// URLs regardless of their actual length. * @param {string} message The message to calculate the length of. * @returns {number} The calculated length of the message. */ calculateMessageLength(message: string): number; #private; } export type TwitterOptions = { /** * The access token for the Twitter app. */ accessTokenKey: string; /** * The access token secret for the Twitter app. */ accessTokenSecret: string; /** * The app (consumer) key for the Twitter app. */ apiConsumerKey: string; /** * The app (consumer) secret for the Twitter app. */ apiConsumerSecret: string; }; export type TwitterPostResponse = { /** * The data of the posted tweet. */ data: { id: string; text: string; edit_history_tweet_ids: string[]; }; }; export type TwitterMediaIdArray = [string] | [string, string] | [string, string, string] | [string, string, string, string]; export type PostOptions = import("../types.js").PostOptions;