From f35b3b6f8a8d2718d0a41e2df3c44b8756baf807 Mon Sep 17 00:00:00 2001 From: Sp3rick Date: Wed, 12 Jun 2024 16:25:35 +0200 Subject: [PATCH 1/2] Install latest api version and a community project --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9e29966b..1b9f6b34 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Node.js module to interact with the official [Telegram Bot API](https://core.tel ## 📦 Install ```sh -npm i node-telegram-bot-api +npm i yagop/node-telegram-bot-api ```
@@ -100,6 +100,7 @@ Some things built using this library that might interest you: * [beetube-bot](https://github.com/kodjunkie/beetube-bot): A telegram bot for music, videos, movies, EDM tracks, torrent downloads, files and more. * [telegram-inline-calendar](https://github.com/VDS13/telegram-inline-calendar): Date and time picker and inline calendar for Node.js telegram bots. * [telegram-captcha](https://github.com/VDS13/telegram-captcha): Telegram bot to protect Telegram groups from automatic bots. +* [LibreGroupHelp](https://github.com/Sp3rick/GroupHelp): A privacy oriented Telegram bot to protect and better manage your groups. ## 👥 Contributors From 45e7d27595a7d073e249a22a83be4014197dc9bf Mon Sep 17 00:00:00 2001 From: Sp3rick Date: Thu, 13 Jun 2024 23:32:47 +0200 Subject: [PATCH 2/2] Support streams and buffers on editMessageMedia --- doc/api.md | 5 +++-- src/telegram.js | 26 +++++++++++++++++--------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/doc/api.md b/doc/api.md index 52a066f5..e903b3a7 100644 --- a/doc/api.md +++ b/doc/api.md @@ -121,7 +121,7 @@ TelegramBot * [.getMyDefaultAdministratorRights([options])](#TelegramBot+getMyDefaultAdministratorRights) ⇒ Promise * [.editMessageText(text, [options])](#TelegramBot+editMessageText) ⇒ Promise * [.editMessageCaption(caption, [options])](#TelegramBot+editMessageCaption) ⇒ Promise - * [.editMessageMedia(media, [options])](#TelegramBot+editMessageMedia) ⇒ Promise + * [.editMessageMedia(media, [options], [fileOptions])](#TelegramBot+editMessageMedia) ⇒ Promise * [.editMessageReplyMarkup(replyMarkup, [options])](#TelegramBot+editMessageReplyMarkup) ⇒ Promise * [.stopPoll(chatId, pollId, [options])](#TelegramBot+stopPoll) ⇒ Promise * [.sendSticker(chatId, sticker, [options], [fileOptions])](#TelegramBot+sendSticker) ⇒ Promise @@ -1922,7 +1922,7 @@ Note: You **must provide one of chat_id, message_id, or inline_message_id** in y -### telegramBot.editMessageMedia(media, [options]) ⇒ Promise +### telegramBot.editMessageMedia(media, [options], [fileOptions]) ⇒ Promise Use this method to edit animation, audio, document, photo, or video messages. If a message is a part of a message album, then it can be edited only to a photo or a video. @@ -1940,6 +1940,7 @@ Note: You **must provide one of chat_id, message_id, or inline_message_id** in y | --- | --- | --- | | media | Object | A JSON-serialized object for a new media content of the message | | [options] | Object | Additional Telegram query options (provide either one of chat_id, message_id, or inline_message_id here) | +| [fileOptions] | Object | Optional file related meta-data | diff --git a/src/telegram.js b/src/telegram.js index b527a9f8..c68d1045 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -2477,16 +2477,18 @@ class TelegramBot extends EventEmitter { * * @param {Object} media A JSON-serialized object for a new media content of the message * @param {Object} [options] Additional Telegram query options (provide either one of chat_id, message_id, or inline_message_id here) + * @param {Object} [fileOptions] Optional file related meta-data * @return {Promise} On success, if the edited message is not an inline message, the edited [Message](https://core.telegram.org/bots/api#message) is returned, otherwise True is returned * @see https://core.telegram.org/bots/api#editmessagemedia */ - editMessageMedia(media, form = {}) { - const regexAttach = /attach:\/\/.+/; - + editMessageMedia(media, form = {}, fileOptions = {}) { + const opts = { + qs: form, + }; + + // This is to keep a backward compatibility, that was undocumented so no-one may be acutally using it if (typeof media.media === 'string' && regexAttach.test(media.media)) { - const opts = { - qs: form, - }; + const regexAttach = /attach:\/\/.+/; opts.formData = {}; @@ -2516,9 +2518,15 @@ class TelegramBot extends EventEmitter { return this._request('editMessageMedia', opts); } - form.media = stringify(media); - - return this._request('editMessageMedia', { form }); + try { + const sendData = this._formatSendData(media.type, media.media, fileOptions); + opts.formData = sendData[0]; + media.media = sendData[1] || "attach://"+media.type; + opts.qs.media = stringify(media); + } catch (ex) { + return Promise.reject(ex); + } + return this._request('editMessageMedia', opts); } /**