Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

README.md: Install latest api version and adds a community project and support stream or buffers on editMessageMedia #1203

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

<br/>
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions doc/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ TelegramBot
* [.getMyDefaultAdministratorRights([options])](#TelegramBot+getMyDefaultAdministratorRights) ⇒ <code>Promise</code>
* [.editMessageText(text, [options])](#TelegramBot+editMessageText) ⇒ <code>Promise</code>
* [.editMessageCaption(caption, [options])](#TelegramBot+editMessageCaption) ⇒ <code>Promise</code>
* [.editMessageMedia(media, [options])](#TelegramBot+editMessageMedia) ⇒ <code>Promise</code>
* [.editMessageMedia(media, [options], [fileOptions])](#TelegramBot+editMessageMedia) ⇒ <code>Promise</code>
* [.editMessageReplyMarkup(replyMarkup, [options])](#TelegramBot+editMessageReplyMarkup) ⇒ <code>Promise</code>
* [.stopPoll(chatId, pollId, [options])](#TelegramBot+stopPoll) ⇒ <code>Promise</code>
* [.sendSticker(chatId, sticker, [options], [fileOptions])](#TelegramBot+sendSticker) ⇒ <code>Promise</code>
Expand Down Expand Up @@ -1922,7 +1922,7 @@ Note: You **must provide one of chat_id, message_id, or inline_message_id** in y

<a name="TelegramBot+editMessageMedia"></a>

### telegramBot.editMessageMedia(media, [options]) ⇒ <code>Promise</code>
### telegramBot.editMessageMedia(media, [options], [fileOptions]) ⇒ <code>Promise</code>
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.
Expand All @@ -1940,6 +1940,7 @@ Note: You **must provide one of chat_id, message_id, or inline_message_id** in y
| --- | --- | --- |
| media | <code>Object</code> | A JSON-serialized object for a new media content of the message |
| [options] | <code>Object</code> | Additional Telegram query options (provide either one of chat_id, message_id, or inline_message_id here) |
| [fileOptions] | <code>Object</code> | Optional file related meta-data |

<a name="TelegramBot+editMessageReplyMarkup"></a>

Expand Down
26 changes: 17 additions & 9 deletions src/telegram.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {};

Expand Down Expand Up @@ -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);
}

/**
Expand Down