@gramio/format
Advanced tools
| class FormattableString { | ||
| /** Text of FormattableString (auto covert to it if entities is unsupported)*/ | ||
| text; | ||
| /** Entities of FormattableString */ | ||
| entities; | ||
| /** Create new FormattableString */ | ||
| constructor(text, entities) { | ||
| this.text = text; | ||
| this.entities = entities; | ||
| } | ||
| /** Create new FormattableString */ | ||
| static from(text, entities) { | ||
| return new FormattableString(text, entities); | ||
| } | ||
| toString() { | ||
| return this.text; | ||
| } | ||
| toJSON() { | ||
| return this.text; | ||
| } | ||
| // ![INFO] - https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-3.html#instanceof-narrowing-through-symbolhasinstance | ||
| static [Symbol.hasInstance](value) { | ||
| return !!value && typeof value === "object" && "text" in value && "entities" in value; | ||
| } | ||
| } | ||
| function getFormattable(str) { | ||
| if (str instanceof FormattableString) return str; | ||
| if (str == null || str === void 0) { | ||
| return new FormattableString("", []); | ||
| } | ||
| return new FormattableString(str.toString(), []); | ||
| } | ||
| const isFormattableString = (value) => FormattableString[Symbol.hasInstance](value); | ||
| const FormattableMap = { | ||
| sendMessage: (params) => { | ||
| if (isFormattableString(params.text)) { | ||
| params.entities = params.text.entities; | ||
| params.text = params.text.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| copyMessage: (params) => { | ||
| if (isFormattableString(params.caption)) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendPhoto: (params) => { | ||
| if (isFormattableString(params.caption)) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendAudio: (params) => { | ||
| if (isFormattableString(params.caption)) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendDocument: (params) => { | ||
| if (isFormattableString(params.caption)) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendVideo: (params) => { | ||
| if (isFormattableString(params.caption)) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendAnimation: (params) => { | ||
| if (isFormattableString(params.caption)) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendVoice: (params) => { | ||
| if (isFormattableString(params.caption)) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendVideoNote: (params) => { | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendPaidMedia: (params) => { | ||
| if (isFormattableString(params.caption)) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendMediaGroup: (params) => { | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| if (params.media.length) | ||
| params.media = params.media.map( | ||
| (x) => "caption" in x && isFormattableString(x.caption) ? { | ||
| ...x, | ||
| caption: x.caption.text, | ||
| caption_entities: x.caption.entities | ||
| } : x | ||
| ); | ||
| return params; | ||
| }, | ||
| sendLocation: (params) => { | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendVenue: (params) => { | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendContact: (params) => { | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendPoll: (params) => { | ||
| if (isFormattableString(params.question)) { | ||
| params.question_entities = params.question.entities; | ||
| params.question = params.question.text; | ||
| } | ||
| if (isFormattableString(params.explanation)) { | ||
| params.explanation_entities = params.explanation.entities; | ||
| params.explanation = params.explanation.text; | ||
| } | ||
| if (isFormattableString(params.description)) { | ||
| params.description_entities = params.description.entities; | ||
| params.description = params.description.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| if (params.options.length) | ||
| params.options = params.options.map( | ||
| (x) => "text" in x && isFormattableString(x.text) ? { | ||
| ...x, | ||
| text: x.text.text, | ||
| text_entities: x.text.entities | ||
| } : x | ||
| ); | ||
| return params; | ||
| }, | ||
| sendChecklist: (params) => { | ||
| if (isFormattableString(params.checklist.title)) { | ||
| params.checklist.title_entities = params.checklist.title.entities; | ||
| params.checklist.title = params.checklist.title.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| if (params.checklist.tasks.length) | ||
| params.checklist.tasks = params.checklist.tasks.map( | ||
| (x) => "text" in x && isFormattableString(x.text) ? { | ||
| ...x, | ||
| text: x.text.text, | ||
| text_entities: x.text.entities | ||
| } : x | ||
| ); | ||
| return params; | ||
| }, | ||
| sendDice: (params) => { | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendMessageDraft: (params) => { | ||
| if (isFormattableString(params.text)) { | ||
| params.entities = params.text.entities; | ||
| params.text = params.text.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendGift: (params) => { | ||
| if (isFormattableString(params.text)) { | ||
| params.text_entities = params.text.entities; | ||
| params.text = params.text.text; | ||
| } | ||
| return params; | ||
| }, | ||
| giftPremiumSubscription: (params) => { | ||
| if (isFormattableString(params.text)) { | ||
| params.text_entities = params.text.entities; | ||
| params.text = params.text.text; | ||
| } | ||
| return params; | ||
| }, | ||
| postStory: (params) => { | ||
| if (isFormattableString(params.caption)) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| return params; | ||
| }, | ||
| editStory: (params) => { | ||
| if (isFormattableString(params.caption)) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| return params; | ||
| }, | ||
| answerWebAppQuery: (params) => { | ||
| if ("caption" in params.result && isFormattableString(params.result.caption)) { | ||
| params.result.caption_entities = params.result.caption.entities; | ||
| params.result.caption = params.result.caption.text; | ||
| } | ||
| if ("input_message_content" in params.result && params.result.input_message_content !== void 0 && "message_text" in params.result.input_message_content && isFormattableString( | ||
| params.result.input_message_content.message_text | ||
| )) { | ||
| params.result.input_message_content.entities = params.result.input_message_content.message_text.entities; | ||
| params.result.input_message_content.message_text = params.result.input_message_content.message_text.text; | ||
| } | ||
| return params; | ||
| }, | ||
| savePreparedInlineMessage: (params) => { | ||
| if ("caption" in params.result && isFormattableString(params.result.caption)) { | ||
| params.result.caption_entities = params.result.caption.entities; | ||
| params.result.caption = params.result.caption.text; | ||
| } | ||
| if ("input_message_content" in params.result && params.result.input_message_content !== void 0 && "message_text" in params.result.input_message_content && isFormattableString( | ||
| params.result.input_message_content.message_text | ||
| )) { | ||
| params.result.input_message_content.entities = params.result.input_message_content.message_text.entities; | ||
| params.result.input_message_content.message_text = params.result.input_message_content.message_text.text; | ||
| } | ||
| return params; | ||
| }, | ||
| editMessageText: (params) => { | ||
| if (isFormattableString(params.text)) { | ||
| params.entities = params.text.entities; | ||
| params.text = params.text.text; | ||
| } | ||
| return params; | ||
| }, | ||
| editMessageCaption: (params) => { | ||
| if (isFormattableString(params.caption)) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| return params; | ||
| }, | ||
| editMessageMedia: (params) => { | ||
| if ("caption" in params.media && isFormattableString(params.media.caption)) { | ||
| params.media.caption_entities = params.media.caption.entities; | ||
| params.media.caption = params.media.caption.text; | ||
| } | ||
| return params; | ||
| }, | ||
| editMessageChecklist: (params) => { | ||
| if (isFormattableString(params.checklist.title)) { | ||
| params.checklist.title_entities = params.checklist.title.entities; | ||
| params.checklist.title = params.checklist.title.text; | ||
| } | ||
| if (params.checklist.tasks.length) | ||
| params.checklist.tasks = params.checklist.tasks.map( | ||
| (x) => "text" in x && isFormattableString(x.text) ? { | ||
| ...x, | ||
| text: x.text.text, | ||
| text_entities: x.text.entities | ||
| } : x | ||
| ); | ||
| return params; | ||
| }, | ||
| sendSticker: (params) => { | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| answerInlineQuery: (params) => { | ||
| if (params.results.length) | ||
| params.results = params.results.map( | ||
| (x) => "caption" in x && isFormattableString(x.caption) ? { | ||
| ...x, | ||
| caption: x.caption.text, | ||
| caption_entities: x.caption.entities | ||
| } : x | ||
| ); | ||
| if (params.results.length) | ||
| params.results = params.results.map( | ||
| (x) => "input_message_content" in x && x.input_message_content !== void 0 && "message_text" in x.input_message_content && isFormattableString(x.input_message_content.message_text) ? { | ||
| ...x, | ||
| input_message_content: { | ||
| ...x.input_message_content, | ||
| message_text: x.input_message_content.message_text.text, | ||
| entities: x.input_message_content.message_text.entities | ||
| } | ||
| } : x | ||
| ); | ||
| return params; | ||
| }, | ||
| sendInvoice: (params) => { | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendGame: (params) => { | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| } | ||
| }; | ||
| export { FormattableString as F, FormattableMap as a, getFormattable as g }; |
| 'use strict'; | ||
| class FormattableString { | ||
| /** Text of FormattableString (auto covert to it if entities is unsupported)*/ | ||
| text; | ||
| /** Entities of FormattableString */ | ||
| entities; | ||
| /** Create new FormattableString */ | ||
| constructor(text, entities) { | ||
| this.text = text; | ||
| this.entities = entities; | ||
| } | ||
| /** Create new FormattableString */ | ||
| static from(text, entities) { | ||
| return new FormattableString(text, entities); | ||
| } | ||
| toString() { | ||
| return this.text; | ||
| } | ||
| toJSON() { | ||
| return this.text; | ||
| } | ||
| // ![INFO] - https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-3.html#instanceof-narrowing-through-symbolhasinstance | ||
| static [Symbol.hasInstance](value) { | ||
| return !!value && typeof value === "object" && "text" in value && "entities" in value; | ||
| } | ||
| } | ||
| function getFormattable(str) { | ||
| if (str instanceof FormattableString) return str; | ||
| if (str == null || str === void 0) { | ||
| return new FormattableString("", []); | ||
| } | ||
| return new FormattableString(str.toString(), []); | ||
| } | ||
| const isFormattableString = (value) => FormattableString[Symbol.hasInstance](value); | ||
| const FormattableMap = { | ||
| sendMessage: (params) => { | ||
| if (isFormattableString(params.text)) { | ||
| params.entities = params.text.entities; | ||
| params.text = params.text.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| copyMessage: (params) => { | ||
| if (isFormattableString(params.caption)) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendPhoto: (params) => { | ||
| if (isFormattableString(params.caption)) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendAudio: (params) => { | ||
| if (isFormattableString(params.caption)) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendDocument: (params) => { | ||
| if (isFormattableString(params.caption)) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendVideo: (params) => { | ||
| if (isFormattableString(params.caption)) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendAnimation: (params) => { | ||
| if (isFormattableString(params.caption)) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendVoice: (params) => { | ||
| if (isFormattableString(params.caption)) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendVideoNote: (params) => { | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendPaidMedia: (params) => { | ||
| if (isFormattableString(params.caption)) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendMediaGroup: (params) => { | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| if (params.media.length) | ||
| params.media = params.media.map( | ||
| (x) => "caption" in x && isFormattableString(x.caption) ? { | ||
| ...x, | ||
| caption: x.caption.text, | ||
| caption_entities: x.caption.entities | ||
| } : x | ||
| ); | ||
| return params; | ||
| }, | ||
| sendLocation: (params) => { | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendVenue: (params) => { | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendContact: (params) => { | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendPoll: (params) => { | ||
| if (isFormattableString(params.question)) { | ||
| params.question_entities = params.question.entities; | ||
| params.question = params.question.text; | ||
| } | ||
| if (isFormattableString(params.explanation)) { | ||
| params.explanation_entities = params.explanation.entities; | ||
| params.explanation = params.explanation.text; | ||
| } | ||
| if (isFormattableString(params.description)) { | ||
| params.description_entities = params.description.entities; | ||
| params.description = params.description.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| if (params.options.length) | ||
| params.options = params.options.map( | ||
| (x) => "text" in x && isFormattableString(x.text) ? { | ||
| ...x, | ||
| text: x.text.text, | ||
| text_entities: x.text.entities | ||
| } : x | ||
| ); | ||
| return params; | ||
| }, | ||
| sendChecklist: (params) => { | ||
| if (isFormattableString(params.checklist.title)) { | ||
| params.checklist.title_entities = params.checklist.title.entities; | ||
| params.checklist.title = params.checklist.title.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| if (params.checklist.tasks.length) | ||
| params.checklist.tasks = params.checklist.tasks.map( | ||
| (x) => "text" in x && isFormattableString(x.text) ? { | ||
| ...x, | ||
| text: x.text.text, | ||
| text_entities: x.text.entities | ||
| } : x | ||
| ); | ||
| return params; | ||
| }, | ||
| sendDice: (params) => { | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendMessageDraft: (params) => { | ||
| if (isFormattableString(params.text)) { | ||
| params.entities = params.text.entities; | ||
| params.text = params.text.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendGift: (params) => { | ||
| if (isFormattableString(params.text)) { | ||
| params.text_entities = params.text.entities; | ||
| params.text = params.text.text; | ||
| } | ||
| return params; | ||
| }, | ||
| giftPremiumSubscription: (params) => { | ||
| if (isFormattableString(params.text)) { | ||
| params.text_entities = params.text.entities; | ||
| params.text = params.text.text; | ||
| } | ||
| return params; | ||
| }, | ||
| postStory: (params) => { | ||
| if (isFormattableString(params.caption)) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| return params; | ||
| }, | ||
| editStory: (params) => { | ||
| if (isFormattableString(params.caption)) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| return params; | ||
| }, | ||
| answerWebAppQuery: (params) => { | ||
| if ("caption" in params.result && isFormattableString(params.result.caption)) { | ||
| params.result.caption_entities = params.result.caption.entities; | ||
| params.result.caption = params.result.caption.text; | ||
| } | ||
| if ("input_message_content" in params.result && params.result.input_message_content !== void 0 && "message_text" in params.result.input_message_content && isFormattableString( | ||
| params.result.input_message_content.message_text | ||
| )) { | ||
| params.result.input_message_content.entities = params.result.input_message_content.message_text.entities; | ||
| params.result.input_message_content.message_text = params.result.input_message_content.message_text.text; | ||
| } | ||
| return params; | ||
| }, | ||
| savePreparedInlineMessage: (params) => { | ||
| if ("caption" in params.result && isFormattableString(params.result.caption)) { | ||
| params.result.caption_entities = params.result.caption.entities; | ||
| params.result.caption = params.result.caption.text; | ||
| } | ||
| if ("input_message_content" in params.result && params.result.input_message_content !== void 0 && "message_text" in params.result.input_message_content && isFormattableString( | ||
| params.result.input_message_content.message_text | ||
| )) { | ||
| params.result.input_message_content.entities = params.result.input_message_content.message_text.entities; | ||
| params.result.input_message_content.message_text = params.result.input_message_content.message_text.text; | ||
| } | ||
| return params; | ||
| }, | ||
| editMessageText: (params) => { | ||
| if (isFormattableString(params.text)) { | ||
| params.entities = params.text.entities; | ||
| params.text = params.text.text; | ||
| } | ||
| return params; | ||
| }, | ||
| editMessageCaption: (params) => { | ||
| if (isFormattableString(params.caption)) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| return params; | ||
| }, | ||
| editMessageMedia: (params) => { | ||
| if ("caption" in params.media && isFormattableString(params.media.caption)) { | ||
| params.media.caption_entities = params.media.caption.entities; | ||
| params.media.caption = params.media.caption.text; | ||
| } | ||
| return params; | ||
| }, | ||
| editMessageChecklist: (params) => { | ||
| if (isFormattableString(params.checklist.title)) { | ||
| params.checklist.title_entities = params.checklist.title.entities; | ||
| params.checklist.title = params.checklist.title.text; | ||
| } | ||
| if (params.checklist.tasks.length) | ||
| params.checklist.tasks = params.checklist.tasks.map( | ||
| (x) => "text" in x && isFormattableString(x.text) ? { | ||
| ...x, | ||
| text: x.text.text, | ||
| text_entities: x.text.entities | ||
| } : x | ||
| ); | ||
| return params; | ||
| }, | ||
| sendSticker: (params) => { | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| answerInlineQuery: (params) => { | ||
| if (params.results.length) | ||
| params.results = params.results.map( | ||
| (x) => "caption" in x && isFormattableString(x.caption) ? { | ||
| ...x, | ||
| caption: x.caption.text, | ||
| caption_entities: x.caption.entities | ||
| } : x | ||
| ); | ||
| if (params.results.length) | ||
| params.results = params.results.map( | ||
| (x) => "input_message_content" in x && x.input_message_content !== void 0 && "message_text" in x.input_message_content && isFormattableString(x.input_message_content.message_text) ? { | ||
| ...x, | ||
| input_message_content: { | ||
| ...x.input_message_content, | ||
| message_text: x.input_message_content.message_text.text, | ||
| entities: x.input_message_content.message_text.entities | ||
| } | ||
| } : x | ||
| ); | ||
| return params; | ||
| }, | ||
| sendInvoice: (params) => { | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendGame: (params) => { | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && isFormattableString(params.reply_parameters.quote)) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| } | ||
| }; | ||
| exports.FormattableMap = FormattableMap; | ||
| exports.FormattableString = FormattableString; | ||
| exports.getFormattable = getFormattable; |
@@ -5,3 +5,3 @@ 'use strict'; | ||
| var index = require('../index.cjs'); | ||
| require('../mutator-DC4naHea.cjs'); | ||
| require('../mutator-DnoFwAyW.cjs'); | ||
@@ -8,0 +8,0 @@ const ELEMENT_NODE = 1; |
| import { parse } from 'node-html-parser'; | ||
| import { join, formatSaveIndents, bold, link, blockquote, pre, code, strikethrough, underline, italic, format } from '../index.js'; | ||
| import '../mutator-DllIOGPF.js'; | ||
| import '../mutator-CK5h8wA4.js'; | ||
@@ -5,0 +5,0 @@ const ELEMENT_NODE = 1; |
+1
-1
| 'use strict'; | ||
| var mutator = require('./mutator-DC4naHea.cjs'); | ||
| var mutator = require('./mutator-DnoFwAyW.cjs'); | ||
@@ -5,0 +5,0 @@ function buildFormatter(type) { |
+1
-1
@@ -12,3 +12,3 @@ import { APIMethods, APIMethodParams, TelegramUser } from '@gramio/types'; | ||
| * | ||
| * @codegenerated | ||
| * @codegenerated from Telegram Bot API 9.6 | ||
| */ | ||
@@ -15,0 +15,0 @@ declare const FormattableMap: FormattableMethods; |
+1
-1
@@ -12,3 +12,3 @@ import { APIMethods, APIMethodParams, TelegramUser } from '@gramio/types'; | ||
| * | ||
| * @codegenerated | ||
| * @codegenerated from Telegram Bot API 9.6 | ||
| */ | ||
@@ -15,0 +15,0 @@ declare const FormattableMap: FormattableMethods; |
+2
-2
@@ -1,3 +0,3 @@ | ||
| import { F as FormattableString, g as getFormattable } from './mutator-DllIOGPF.js'; | ||
| export { a as FormattableMap } from './mutator-DllIOGPF.js'; | ||
| import { F as FormattableString, g as getFormattable } from './mutator-CK5h8wA4.js'; | ||
| export { a as FormattableMap } from './mutator-CK5h8wA4.js'; | ||
@@ -4,0 +4,0 @@ function buildFormatter(type) { |
@@ -5,3 +5,3 @@ 'use strict'; | ||
| var index = require('../index.cjs'); | ||
| require('../mutator-DC4naHea.cjs'); | ||
| require('../mutator-DnoFwAyW.cjs'); | ||
@@ -8,0 +8,0 @@ function processToken(token) { |
| import { lexer } from 'marked'; | ||
| import { join, blockquote, bold, italic, link, strikethrough, code, pre, formatSaveIndents, format } from '../index.js'; | ||
| import '../mutator-DllIOGPF.js'; | ||
| import '../mutator-CK5h8wA4.js'; | ||
@@ -5,0 +5,0 @@ function processToken(token) { |
| 'use strict'; | ||
| var mutator = require('./mutator-DC4naHea.cjs'); | ||
| var mutator = require('./mutator-DnoFwAyW.cjs'); | ||
@@ -5,0 +5,0 @@ const formatMiddleware = (context, next) => { |
@@ -1,2 +0,2 @@ | ||
| import { a as FormattableMap } from './mutator-DllIOGPF.js'; | ||
| import { a as FormattableMap } from './mutator-CK5h8wA4.js'; | ||
@@ -3,0 +3,0 @@ const formatMiddleware = (context, next) => { |
+3
-2
| { | ||
| "name": "@gramio/format", | ||
| "version": "0.6.1", | ||
| "version": "0.7.0", | ||
| "repository": { | ||
@@ -10,6 +10,7 @@ "type": "git", | ||
| "dependencies": { | ||
| "@gramio/types": "^9.5.0" | ||
| "@gramio/types": "^9.6.0" | ||
| }, | ||
| "devDependencies": { | ||
| "@biomejs/biome": "^2.4.4", | ||
| "@gramio/schema-parser": "^1.1.0", | ||
| "@types/bun": "^1.3.9", | ||
@@ -16,0 +17,0 @@ "expect-type": "^1.3.0", |
| 'use strict'; | ||
| class FormattableString { | ||
| /** Text of FormattableString (auto covert to it if entities is unsupported)*/ | ||
| text; | ||
| /** Entities of FormattableString */ | ||
| entities; | ||
| /** Create new FormattableString */ | ||
| constructor(text, entities) { | ||
| this.text = text; | ||
| this.entities = entities; | ||
| } | ||
| /** Create new FormattableString */ | ||
| static from(text, entities) { | ||
| return new FormattableString(text, entities); | ||
| } | ||
| toString() { | ||
| return this.text; | ||
| } | ||
| toJSON() { | ||
| return this.text; | ||
| } | ||
| // ![INFO] - https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-3.html#instanceof-narrowing-through-symbolhasinstance | ||
| static [Symbol.hasInstance](value) { | ||
| return !!value && typeof value === "object" && "text" in value && "entities" in value; | ||
| } | ||
| } | ||
| function getFormattable(str) { | ||
| if (str instanceof FormattableString) return str; | ||
| if (str == null || str === void 0) { | ||
| return new FormattableString("", []); | ||
| } | ||
| return new FormattableString(str.toString(), []); | ||
| } | ||
| const isFormattableString = (value) => FormattableString[Symbol.hasInstance](value); | ||
| const FormattableMap = { | ||
| sendMessage: (params) => { | ||
| if (params.text instanceof FormattableString) { | ||
| params.entities = params.text.entities; | ||
| params.text = params.text.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && params.reply_parameters.quote instanceof FormattableString) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| copyMessage: (params) => { | ||
| if (params.caption instanceof FormattableString) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && params.reply_parameters.quote instanceof FormattableString) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendPhoto: (params) => { | ||
| if (params.caption instanceof FormattableString) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && params.reply_parameters.quote instanceof FormattableString) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendAudio: (params) => { | ||
| if (params.caption instanceof FormattableString) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && params.reply_parameters.quote instanceof FormattableString) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendDocument: (params) => { | ||
| if (params.caption instanceof FormattableString) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && params.reply_parameters.quote instanceof FormattableString) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendVideo: (params) => { | ||
| if (params.caption instanceof FormattableString) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && params.reply_parameters.quote instanceof FormattableString) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendAnimation: (params) => { | ||
| if (params.caption instanceof FormattableString) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && params.reply_parameters.quote instanceof FormattableString) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendVoice: (params) => { | ||
| if (params.caption instanceof FormattableString) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && params.reply_parameters.quote instanceof FormattableString) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendVideoNote: (params) => { | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && params.reply_parameters.quote instanceof FormattableString) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendMediaGroup: (params) => { | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && params.reply_parameters.quote instanceof FormattableString) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| if (params.media.length) | ||
| params.media = params.media.map( | ||
| (x) => "caption" in x && x.caption instanceof FormattableString ? { | ||
| ...x, | ||
| caption: x.caption.text, | ||
| caption_entities: x.caption.entities | ||
| } : x | ||
| ); | ||
| return params; | ||
| }, | ||
| sendLocation: (params) => { | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && params.reply_parameters.quote instanceof FormattableString) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendVenue: (params) => { | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && params.reply_parameters.quote instanceof FormattableString) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendContact: (params) => { | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && params.reply_parameters.quote instanceof FormattableString) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendPoll: (params) => { | ||
| if (params.question instanceof FormattableString) { | ||
| params.question_entities = params.question.entities; | ||
| params.question = params.question.text; | ||
| } | ||
| if (params.explanation instanceof FormattableString) { | ||
| params.explanation_entities = params.explanation.entities; | ||
| params.explanation = params.explanation.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && params.reply_parameters.quote instanceof FormattableString) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| if (params.options.length) | ||
| params.options = params.options.map( | ||
| (x) => "text" in x && x.text instanceof FormattableString ? { ...x, text: x.text.text, text_entities: x.text.entities } : x | ||
| ); | ||
| return params; | ||
| }, | ||
| sendDice: (params) => { | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && params.reply_parameters.quote instanceof FormattableString) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| editMessageText: (params) => { | ||
| if (params.text instanceof FormattableString) { | ||
| params.entities = params.text.entities; | ||
| params.text = params.text.text; | ||
| } | ||
| return params; | ||
| }, | ||
| editMessageCaption: (params) => { | ||
| if (params.caption instanceof FormattableString) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| return params; | ||
| }, | ||
| editMessageMedia: (params) => { | ||
| if (params.media !== void 0 && "caption" in params.media && params.media.caption instanceof FormattableString) { | ||
| params.media.caption_entities = params.media.caption.entities; | ||
| params.media.caption = params.media.caption.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendSticker: (params) => { | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && params.reply_parameters.quote instanceof FormattableString) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| // TODO: fix | ||
| answerInlineQuery: (params) => { | ||
| if (params.results?.length) | ||
| params.results = params.results.map( | ||
| (x) => "caption" in x && x.caption instanceof FormattableString ? { | ||
| ...x, | ||
| caption: x.caption.text, | ||
| caption_entities: x.caption.entities | ||
| } : x | ||
| ); | ||
| if (params.results?.length) | ||
| params.results = params.results.map( | ||
| (x) => "input_message_content" in x && x.input_message_content && "message_text" in x.input_message_content && isFormattableString(x.input_message_content.message_text) ? { | ||
| ...x, | ||
| input_message_content: { | ||
| ...x.input_message_content, | ||
| message_text: x.input_message_content.message_text.text, | ||
| entities: x.input_message_content.message_text.entities | ||
| } | ||
| } : x | ||
| ); | ||
| return params; | ||
| }, | ||
| savePreparedInlineMessage: (params) => { | ||
| if ("caption" in params.result && params.result.caption instanceof FormattableString) { | ||
| params.result.caption_entities = params.result.caption.entities; | ||
| params.result.caption = params.result.caption.text; | ||
| } | ||
| if ("input_message_content" in params.result && params.result.input_message_content && "message_text" in params.result.input_message_content && isFormattableString(params.result.input_message_content.message_text)) { | ||
| params.result = { | ||
| ...params.result, | ||
| input_message_content: { | ||
| ...params.result.input_message_content, | ||
| message_text: params.result.input_message_content.message_text.text, | ||
| entities: params.result.input_message_content.message_text.entities | ||
| } | ||
| }; | ||
| } | ||
| return params; | ||
| }, | ||
| sendGift: (params) => { | ||
| if (params.text instanceof FormattableString) { | ||
| params.text_entities = params.text.entities; | ||
| params.text = params.text.text; | ||
| } | ||
| return params; | ||
| }, | ||
| answerWebAppQuery: (params) => { | ||
| if (params.result !== void 0 && "caption" in params.result && params.result.caption instanceof FormattableString) { | ||
| params.result.caption_entities = params.result.caption.entities; | ||
| params.result.caption = params.result.caption.text; | ||
| } | ||
| if ("input_message_content" in params.result && params.result.input_message_content !== void 0 && "message_text" in params.result.input_message_content && isFormattableString(params.result.input_message_content.message_text)) { | ||
| params.result.input_message_content.entities = params.result.input_message_content.message_text.entities; | ||
| params.result.input_message_content.message_text = params.result.input_message_content.message_text.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendInvoice: (params) => { | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && params.reply_parameters.quote instanceof FormattableString) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendGame: (params) => { | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && params.reply_parameters.quote instanceof FormattableString) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| giftPremiumSubscription: (params) => { | ||
| if (params.text && params.text instanceof FormattableString) { | ||
| params.text_entities = params.text.entities; | ||
| params.text = params.text.text; | ||
| } | ||
| return params; | ||
| }, | ||
| postStory: (params) => { | ||
| if (params.caption && params.caption instanceof FormattableString) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| return params; | ||
| }, | ||
| editStory: (params) => { | ||
| if (params.caption && params.caption instanceof FormattableString) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| return params; | ||
| }, | ||
| editMessageChecklist: (params) => { | ||
| if (params.checklist.title instanceof FormattableString) { | ||
| params.checklist.title_entities = params.checklist.title.entities; | ||
| params.checklist.title = params.checklist.title.text; | ||
| } | ||
| if (params.checklist.tasks.length) { | ||
| params.checklist.tasks = params.checklist.tasks.map((x) => { | ||
| if (x.text instanceof FormattableString) { | ||
| x.text_entities = x.text.entities; | ||
| x.text = x.text.text; | ||
| } | ||
| return x; | ||
| }); | ||
| } | ||
| return params; | ||
| }, | ||
| sendChecklist: (params) => { | ||
| if (params.checklist.title instanceof FormattableString) { | ||
| params.checklist.title_entities = params.checklist.title.entities; | ||
| params.checklist.title = params.checklist.title.text; | ||
| } | ||
| if (params.checklist.tasks.length) { | ||
| params.checklist.tasks = params.checklist.tasks.map((x) => { | ||
| if (x.text instanceof FormattableString) { | ||
| x.text_entities = x.text.entities; | ||
| x.text = x.text.text; | ||
| } | ||
| return x; | ||
| }); | ||
| } | ||
| return params; | ||
| } | ||
| }; | ||
| exports.FormattableMap = FormattableMap; | ||
| exports.FormattableString = FormattableString; | ||
| exports.getFormattable = getFormattable; |
| class FormattableString { | ||
| /** Text of FormattableString (auto covert to it if entities is unsupported)*/ | ||
| text; | ||
| /** Entities of FormattableString */ | ||
| entities; | ||
| /** Create new FormattableString */ | ||
| constructor(text, entities) { | ||
| this.text = text; | ||
| this.entities = entities; | ||
| } | ||
| /** Create new FormattableString */ | ||
| static from(text, entities) { | ||
| return new FormattableString(text, entities); | ||
| } | ||
| toString() { | ||
| return this.text; | ||
| } | ||
| toJSON() { | ||
| return this.text; | ||
| } | ||
| // ![INFO] - https://www.typescriptlang.org/docs/handbook/release-notes/typescript-5-3.html#instanceof-narrowing-through-symbolhasinstance | ||
| static [Symbol.hasInstance](value) { | ||
| return !!value && typeof value === "object" && "text" in value && "entities" in value; | ||
| } | ||
| } | ||
| function getFormattable(str) { | ||
| if (str instanceof FormattableString) return str; | ||
| if (str == null || str === void 0) { | ||
| return new FormattableString("", []); | ||
| } | ||
| return new FormattableString(str.toString(), []); | ||
| } | ||
| const isFormattableString = (value) => FormattableString[Symbol.hasInstance](value); | ||
| const FormattableMap = { | ||
| sendMessage: (params) => { | ||
| if (params.text instanceof FormattableString) { | ||
| params.entities = params.text.entities; | ||
| params.text = params.text.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && params.reply_parameters.quote instanceof FormattableString) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| copyMessage: (params) => { | ||
| if (params.caption instanceof FormattableString) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && params.reply_parameters.quote instanceof FormattableString) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendPhoto: (params) => { | ||
| if (params.caption instanceof FormattableString) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && params.reply_parameters.quote instanceof FormattableString) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendAudio: (params) => { | ||
| if (params.caption instanceof FormattableString) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && params.reply_parameters.quote instanceof FormattableString) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendDocument: (params) => { | ||
| if (params.caption instanceof FormattableString) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && params.reply_parameters.quote instanceof FormattableString) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendVideo: (params) => { | ||
| if (params.caption instanceof FormattableString) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && params.reply_parameters.quote instanceof FormattableString) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendAnimation: (params) => { | ||
| if (params.caption instanceof FormattableString) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && params.reply_parameters.quote instanceof FormattableString) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendVoice: (params) => { | ||
| if (params.caption instanceof FormattableString) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && params.reply_parameters.quote instanceof FormattableString) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendVideoNote: (params) => { | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && params.reply_parameters.quote instanceof FormattableString) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendMediaGroup: (params) => { | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && params.reply_parameters.quote instanceof FormattableString) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| if (params.media.length) | ||
| params.media = params.media.map( | ||
| (x) => "caption" in x && x.caption instanceof FormattableString ? { | ||
| ...x, | ||
| caption: x.caption.text, | ||
| caption_entities: x.caption.entities | ||
| } : x | ||
| ); | ||
| return params; | ||
| }, | ||
| sendLocation: (params) => { | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && params.reply_parameters.quote instanceof FormattableString) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendVenue: (params) => { | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && params.reply_parameters.quote instanceof FormattableString) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendContact: (params) => { | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && params.reply_parameters.quote instanceof FormattableString) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendPoll: (params) => { | ||
| if (params.question instanceof FormattableString) { | ||
| params.question_entities = params.question.entities; | ||
| params.question = params.question.text; | ||
| } | ||
| if (params.explanation instanceof FormattableString) { | ||
| params.explanation_entities = params.explanation.entities; | ||
| params.explanation = params.explanation.text; | ||
| } | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && params.reply_parameters.quote instanceof FormattableString) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| if (params.options.length) | ||
| params.options = params.options.map( | ||
| (x) => "text" in x && x.text instanceof FormattableString ? { ...x, text: x.text.text, text_entities: x.text.entities } : x | ||
| ); | ||
| return params; | ||
| }, | ||
| sendDice: (params) => { | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && params.reply_parameters.quote instanceof FormattableString) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| editMessageText: (params) => { | ||
| if (params.text instanceof FormattableString) { | ||
| params.entities = params.text.entities; | ||
| params.text = params.text.text; | ||
| } | ||
| return params; | ||
| }, | ||
| editMessageCaption: (params) => { | ||
| if (params.caption instanceof FormattableString) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| return params; | ||
| }, | ||
| editMessageMedia: (params) => { | ||
| if (params.media !== void 0 && "caption" in params.media && params.media.caption instanceof FormattableString) { | ||
| params.media.caption_entities = params.media.caption.entities; | ||
| params.media.caption = params.media.caption.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendSticker: (params) => { | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && params.reply_parameters.quote instanceof FormattableString) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| // TODO: fix | ||
| answerInlineQuery: (params) => { | ||
| if (params.results?.length) | ||
| params.results = params.results.map( | ||
| (x) => "caption" in x && x.caption instanceof FormattableString ? { | ||
| ...x, | ||
| caption: x.caption.text, | ||
| caption_entities: x.caption.entities | ||
| } : x | ||
| ); | ||
| if (params.results?.length) | ||
| params.results = params.results.map( | ||
| (x) => "input_message_content" in x && x.input_message_content && "message_text" in x.input_message_content && isFormattableString(x.input_message_content.message_text) ? { | ||
| ...x, | ||
| input_message_content: { | ||
| ...x.input_message_content, | ||
| message_text: x.input_message_content.message_text.text, | ||
| entities: x.input_message_content.message_text.entities | ||
| } | ||
| } : x | ||
| ); | ||
| return params; | ||
| }, | ||
| savePreparedInlineMessage: (params) => { | ||
| if ("caption" in params.result && params.result.caption instanceof FormattableString) { | ||
| params.result.caption_entities = params.result.caption.entities; | ||
| params.result.caption = params.result.caption.text; | ||
| } | ||
| if ("input_message_content" in params.result && params.result.input_message_content && "message_text" in params.result.input_message_content && isFormattableString(params.result.input_message_content.message_text)) { | ||
| params.result = { | ||
| ...params.result, | ||
| input_message_content: { | ||
| ...params.result.input_message_content, | ||
| message_text: params.result.input_message_content.message_text.text, | ||
| entities: params.result.input_message_content.message_text.entities | ||
| } | ||
| }; | ||
| } | ||
| return params; | ||
| }, | ||
| sendGift: (params) => { | ||
| if (params.text instanceof FormattableString) { | ||
| params.text_entities = params.text.entities; | ||
| params.text = params.text.text; | ||
| } | ||
| return params; | ||
| }, | ||
| answerWebAppQuery: (params) => { | ||
| if (params.result !== void 0 && "caption" in params.result && params.result.caption instanceof FormattableString) { | ||
| params.result.caption_entities = params.result.caption.entities; | ||
| params.result.caption = params.result.caption.text; | ||
| } | ||
| if ("input_message_content" in params.result && params.result.input_message_content !== void 0 && "message_text" in params.result.input_message_content && isFormattableString(params.result.input_message_content.message_text)) { | ||
| params.result.input_message_content.entities = params.result.input_message_content.message_text.entities; | ||
| params.result.input_message_content.message_text = params.result.input_message_content.message_text.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendInvoice: (params) => { | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && params.reply_parameters.quote instanceof FormattableString) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| sendGame: (params) => { | ||
| if (params.reply_parameters !== void 0 && "quote" in params.reply_parameters && params.reply_parameters.quote instanceof FormattableString) { | ||
| params.reply_parameters.quote_entities = params.reply_parameters.quote.entities; | ||
| params.reply_parameters.quote = params.reply_parameters.quote.text; | ||
| } | ||
| return params; | ||
| }, | ||
| giftPremiumSubscription: (params) => { | ||
| if (params.text && params.text instanceof FormattableString) { | ||
| params.text_entities = params.text.entities; | ||
| params.text = params.text.text; | ||
| } | ||
| return params; | ||
| }, | ||
| postStory: (params) => { | ||
| if (params.caption && params.caption instanceof FormattableString) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| return params; | ||
| }, | ||
| editStory: (params) => { | ||
| if (params.caption && params.caption instanceof FormattableString) { | ||
| params.caption_entities = params.caption.entities; | ||
| params.caption = params.caption.text; | ||
| } | ||
| return params; | ||
| }, | ||
| editMessageChecklist: (params) => { | ||
| if (params.checklist.title instanceof FormattableString) { | ||
| params.checklist.title_entities = params.checklist.title.entities; | ||
| params.checklist.title = params.checklist.title.text; | ||
| } | ||
| if (params.checklist.tasks.length) { | ||
| params.checklist.tasks = params.checklist.tasks.map((x) => { | ||
| if (x.text instanceof FormattableString) { | ||
| x.text_entities = x.text.entities; | ||
| x.text = x.text.text; | ||
| } | ||
| return x; | ||
| }); | ||
| } | ||
| return params; | ||
| }, | ||
| sendChecklist: (params) => { | ||
| if (params.checklist.title instanceof FormattableString) { | ||
| params.checklist.title_entities = params.checklist.title.entities; | ||
| params.checklist.title = params.checklist.title.text; | ||
| } | ||
| if (params.checklist.tasks.length) { | ||
| params.checklist.tasks = params.checklist.tasks.map((x) => { | ||
| if (x.text instanceof FormattableString) { | ||
| x.text_entities = x.text.entities; | ||
| x.text = x.text.text; | ||
| } | ||
| return x; | ||
| }); | ||
| } | ||
| return params; | ||
| } | ||
| }; | ||
| export { FormattableString as F, FormattableMap as a, getFormattable as g }; |
Sorry, the diff of this file is not supported yet
149949
1.01%1817
2.83%9
12.5%Updated