From 574827816d861f5ddaaea900c34ec66b137e24fe Mon Sep 17 00:00:00 2001 From: Cojad Date: Sun, 20 Mar 2022 13:09:32 +0800 Subject: [PATCH] add method copyMessage for telegram Bot API 5.0, add parameter protect_content for telegram Bot API 5.6. --- .../src/TelegramClient.ts | 34 ++++ .../src/TelegramTypes.ts | 186 ++++++++++++++++++ 2 files changed, 220 insertions(+) diff --git a/packages/messaging-api-telegram/src/TelegramClient.ts b/packages/messaging-api-telegram/src/TelegramClient.ts index 11537c62..5b87f9eb 100644 --- a/packages/messaging-api-telegram/src/TelegramClient.ts +++ b/packages/messaging-api-telegram/src/TelegramClient.ts @@ -322,6 +322,40 @@ export default class TelegramClient { }); } + /** + * Use this method to forward messages of any kind. + * + * @param chatId - Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) + * @param fromChatId - Unique identifier for the chat where the original message was sent (or channel username in the format `@channelusername`) + * @param messageId - Message identifier in the chat specified in fromChatId + * @param options - Options for other optional parameters. + * @returns On success, the sent Message is returned. + * + * @see https://core.telegram.org/bots/api#copymessage + * + * @example + * + * ```js + * await client.copyMessage(CHAT_ID, USER_ID, MESSAGE_ID, { + * disableNotification: true, + * protect_content: true, + * }); + * ``` + */ + copyMessage( + chatId: string | number, + fromChatId: string | number, + messageId: number, + options?: TelegramTypes.CopyMessageOption + ): Promise { + return this.request('/copyMessage', { + chatId, + fromChatId, + messageId, + ...options, + }); + } + /** * Use this method to send photos. * diff --git a/packages/messaging-api-telegram/src/TelegramTypes.ts b/packages/messaging-api-telegram/src/TelegramTypes.ts index 2ca554cf..19f72302 100644 --- a/packages/messaging-api-telegram/src/TelegramTypes.ts +++ b/packages/messaging-api-telegram/src/TelegramTypes.ts @@ -1468,6 +1468,7 @@ export type SendMessageOption = { /** * Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message. * + * - https://core.telegram.org/bots/api#markdownv2-style * - https://core.telegram.org/bots/api#markdown-style * - https://core.telegram.org/bots/api#html-style * - https://core.telegram.org/bots/api#formatting-options @@ -1486,6 +1487,13 @@ export type SendMessageOption = { */ disableNotification?: boolean; + /** + * Protects the contents of the sent message from forwarding and saving + * + * - https://telegram.org/blog/protected-content-delete-by-date-and-more#protected-content-in-groups-and-channels + */ + protect_content?: boolean; + /** * If the message is a reply, ID of the original message */ @@ -1509,6 +1517,7 @@ export type SendMessageOption = { }; export enum ParseMode { + MarkdownV2 = 'MarkdownV2', Markdown = 'Markdown', HTML = 'HTML', } @@ -1518,6 +1527,70 @@ export type ForwardMessageOption = { * Sends the message silently. Users will receive a notification with no sound. */ disableNotification?: boolean; + + /** + * Protects the contents of the sent message from forwarding and saving + * + * - https://telegram.org/blog/protected-content-delete-by-date-and-more#protected-content-in-groups-and-channels + */ + protect_content?: boolean; +}; + +export type CopyMessageOption = { + /** + * New caption for media, 0-1024 characters after entities parsing. If not specified, the original caption is kept + */ + caption?: string; + + /** + * Mode for parsing entities in the new caption. See formatting options for more details. + * + * - https://core.telegram.org/bots/api#markdownv2-style + * - https://core.telegram.org/bots/api#markdown-style + * - https://core.telegram.org/bots/api#html-style + * - https://core.telegram.org/bots/api#formatting-options + */ + parseMode?: ParseMode; + + /** + * Sends the message silently. Users will receive a notification with no sound. + * + * - https://telegram.org/blog/channels-2-0#silent-messages + */ + disableNotification?: boolean; + + /** + * Protects the contents of the sent message from forwarding and saving + * + * - https://telegram.org/blog/protected-content-delete-by-date-and-more#protected-content-in-groups-and-channels + */ + protect_content?: boolean; + + /** + * If the message is a reply, ID of the original message + */ + replyToMessageId?: number; + + /** + * Pass True, if the message should be sent even if the specified replied-to message is not found + */ + allow_sending_without_reply?: boolean; + + /** + * Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. + * + * - https://core.telegram.org/bots#inline-keyboards-and-on-the-fly-updating + * - https://core.telegram.org/bots#keyboards + * - https://core.telegram.org/bots/api#inlinekeyboardmarkup + * - https://core.telegram.org/bots/api#replykeyboardmarkup + * - https://core.telegram.org/bots/api#replykeyboardremove + * - https://core.telegram.org/bots/api#forcereply + */ + replyMarkup?: + | InlineKeyboardMarkup + | ReplyKeyboardMarkup + | ReplyKeyboardRemove + | ForceReply; }; export type SendPhotoOption = { @@ -1529,6 +1602,7 @@ export type SendPhotoOption = { /** * Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. * + * - https://core.telegram.org/bots/api#markdownv2-style * - https://core.telegram.org/bots/api#markdown-style * - https://core.telegram.org/bots/api#html-style * - https://core.telegram.org/bots/api#formatting-options @@ -1542,6 +1616,13 @@ export type SendPhotoOption = { */ disableNotification?: boolean; + /** + * Protects the contents of the sent message from forwarding and saving + * + * - https://telegram.org/blog/protected-content-delete-by-date-and-more#protected-content-in-groups-and-channels + */ + protect_content?: boolean; + /** * If the message is a reply, ID of the original message */ @@ -1573,6 +1654,7 @@ export type SendAudioOption = { /** * Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. * + * - https://core.telegram.org/bots/api#markdownv2-style * - https://core.telegram.org/bots/api#markdown-style * - https://core.telegram.org/bots/api#html-style * - https://core.telegram.org/bots/api#formatting-options @@ -1606,6 +1688,13 @@ export type SendAudioOption = { */ disableNotification?: boolean; + /** + * Protects the contents of the sent message from forwarding and saving + * + * - https://telegram.org/blog/protected-content-delete-by-date-and-more#protected-content-in-groups-and-channels + */ + protect_content?: boolean; + /** * If the message is a reply, ID of the original message */ @@ -1642,6 +1731,7 @@ export type SendDocumentOption = { /** * Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. * + * - https://core.telegram.org/bots/api#markdownv2-style * - https://core.telegram.org/bots/api#markdown-style * - https://core.telegram.org/bots/api#html-style * - https://core.telegram.org/bots/api#formatting-options @@ -1655,6 +1745,13 @@ export type SendDocumentOption = { */ disableNotification?: boolean; + /** + * Protects the contents of the sent message from forwarding and saving + * + * - https://telegram.org/blog/protected-content-delete-by-date-and-more#protected-content-in-groups-and-channels + */ + protect_content?: boolean; + /** * If the message is a reply, ID of the original message */ @@ -1706,6 +1803,7 @@ export type SendVideoOption = { /** * Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. * + * - https://core.telegram.org/bots/api#markdownv2-style * - https://core.telegram.org/bots/api#markdown-style * - https://core.telegram.org/bots/api#html-style * - https://core.telegram.org/bots/api#formatting-options @@ -1724,6 +1822,13 @@ export type SendVideoOption = { */ disableNotification?: boolean; + /** + * Protects the contents of the sent message from forwarding and saving + * + * - https://telegram.org/blog/protected-content-delete-by-date-and-more#protected-content-in-groups-and-channels + */ + protect_content?: boolean; + /** * If the message is a reply, ID of the original message */ @@ -1775,6 +1880,7 @@ export type SendAnimationOption = { /** * Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. * + * - https://core.telegram.org/bots/api#markdownv2-style * - https://core.telegram.org/bots/api#markdown-style * - https://core.telegram.org/bots/api#html-style * - https://core.telegram.org/bots/api#formatting-options @@ -1788,6 +1894,13 @@ export type SendAnimationOption = { */ disableNotification?: boolean; + /** + * Protects the contents of the sent message from forwarding and saving + * + * - https://telegram.org/blog/protected-content-delete-by-date-and-more#protected-content-in-groups-and-channels + */ + protect_content?: boolean; + /** * If the message is a reply, ID of the original message */ @@ -1824,6 +1937,7 @@ export type SendVoiceOption = { /** * Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in the media caption. * + * - https://core.telegram.org/bots/api#markdownv2-style * - https://core.telegram.org/bots/api#markdown-style * - https://core.telegram.org/bots/api#html-style * - https://core.telegram.org/bots/api#formatting-options @@ -1837,6 +1951,13 @@ export type SendVoiceOption = { */ disableNotification?: boolean; + /** + * Protects the contents of the sent message from forwarding and saving + * + * - https://telegram.org/blog/protected-content-delete-by-date-and-more#protected-content-in-groups-and-channels + */ + protect_content?: boolean; + /** * If the message is a reply, ID of the original message */ @@ -1882,6 +2003,13 @@ export type SendVideoNoteOption = { */ disableNotification?: boolean; + /** + * Protects the contents of the sent message from forwarding and saving + * + * - https://telegram.org/blog/protected-content-delete-by-date-and-more#protected-content-in-groups-and-channels + */ + protect_content?: boolean; + /** * If the message is a reply, ID of the original message */ @@ -1912,6 +2040,13 @@ export type SendMediaGroupOption = { */ disableNotification?: boolean; + /** + * Protects the contents of the sent message from forwarding and saving + * + * - https://telegram.org/blog/protected-content-delete-by-date-and-more#protected-content-in-groups-and-channels + */ + protect_content?: boolean; + /** * If the message is a reply, ID of the original message */ @@ -1933,6 +2068,13 @@ export type SendLocationOption = { */ disableNotification?: boolean; + /** + * Protects the contents of the sent message from forwarding and saving + * + * - https://telegram.org/blog/protected-content-delete-by-date-and-more#protected-content-in-groups-and-channels + */ + protect_content?: boolean; + /** * If the message is a reply, ID of the original message */ @@ -2012,6 +2154,13 @@ export type SendVenueOption = { */ disableNotification?: boolean; + /** + * Protects the contents of the sent message from forwarding and saving + * + * - https://telegram.org/blog/protected-content-delete-by-date-and-more#protected-content-in-groups-and-channels + */ + protect_content?: boolean; + /** * If the message is a reply, ID of the original message */ @@ -2066,6 +2215,13 @@ export type SendContactOption = { */ disableNotification?: boolean; + /** + * Protects the contents of the sent message from forwarding and saving + * + * - https://telegram.org/blog/protected-content-delete-by-date-and-more#protected-content-in-groups-and-channels + */ + protect_content?: boolean; + /** * If the message is a reply, ID of the original message */ @@ -2141,6 +2297,13 @@ export type SendPollOption = { */ disableNotification?: boolean; + /** + * Protects the contents of the sent message from forwarding and saving + * + * - https://telegram.org/blog/protected-content-delete-by-date-and-more#protected-content-in-groups-and-channels + */ + protect_content?: boolean; + /** * If the message is a reply, ID of the original message */ @@ -2242,6 +2405,7 @@ export type EditMessageTextOption = EditOption & { /** * Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message. * + * - https://core.telegram.org/bots/api#markdownv2-style * - https://core.telegram.org/bots/api#markdown-style * - https://core.telegram.org/bots/api#html-style * - https://core.telegram.org/bots/api#formatting-options @@ -2266,6 +2430,7 @@ export type EditMessageCaptionOption = EditOption & { /** * Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message. * + * - https://core.telegram.org/bots/api#markdownv2-style * - https://core.telegram.org/bots/api#markdown-style * - https://core.telegram.org/bots/api#html-style * - https://core.telegram.org/bots/api#formatting-options @@ -2311,6 +2476,13 @@ export type SendStickerOption = { */ disableNotification?: boolean; + /** + * Protects the contents of the sent message from forwarding and saving + * + * - https://telegram.org/blog/protected-content-delete-by-date-and-more#protected-content-in-groups-and-channels + */ + protect_content?: boolean; + /** * If the message is a reply, ID of the original message */ @@ -2432,6 +2604,13 @@ export type SendInvoiceOption = { */ disableNotification?: boolean; + /** + * Protects the contents of the sent message from forwarding and saving + * + * - https://telegram.org/blog/protected-content-delete-by-date-and-more#protected-content-in-groups-and-channels + */ + protect_content?: boolean; + /** * If the message is a reply, ID of the original message */ @@ -2499,6 +2678,13 @@ export type SendGameOption = { */ disableNotification?: boolean; + /** + * Protects the contents of the sent message from forwarding and saving + * + * - https://telegram.org/blog/protected-content-delete-by-date-and-more#protected-content-in-groups-and-channels + */ + protect_content?: boolean; + /** * If the message is a reply, ID of the original message */