From 67c738b0d3551e0ef643a48dd2d3a30f585d6bd3 Mon Sep 17 00:00:00 2001 From: Mohammed Sohail Date: Wed, 1 Aug 2018 22:15:05 +0530 Subject: [PATCH 1/5] Add editMessageMedia method Reference: Telegram API Documentation: https://core.telegram.org/bots/api#editmessagemedia --- src/telegram.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/telegram.js b/src/telegram.js index d95a4de0..34c13835 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -1184,6 +1184,26 @@ class TelegramBot extends EventEmitter { return this._request('editMessageCaption', { form }); } + /** + * Use this method to edit 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. + * Otherwise, message type can be changed arbitrarily. When inline message is edited, new file can't be uploaded. + * Use previously uploaded file via its file_id or specify a URL. + * On success, the edited Message is returned. + * + * Note that you must provide one of chat_id, message_id, or + * inline_message_id in your request. + * + * @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) + * @return {Promise} + * @see https://core.telegram.org/bots/api#editmessagemedia + */ + editMessageMedia(media, form = {}) { + form.media = media; + return this._request('editMessageMedia', { form }); + } + /** * Use this method to edit only the reply markup of messages * sent by the bot or via the bot (for inline bots). From 2d3421905c9bc07083707e08896d061b7194dd34 Mon Sep 17 00:00:00 2001 From: Mohammed Sohail Date: Wed, 1 Aug 2018 22:20:47 +0530 Subject: [PATCH 2/5] Add animation message type References: Telegram API Documentation: https://core.telegram.org/bots/api#message --- src/telegram.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/telegram.js b/src/telegram.js index 34c13835..878997c8 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -21,6 +21,7 @@ let Promise = require('bluebird'); const _messageTypes = [ 'text', + 'animation', 'audio', 'channel_chat_created', 'contact', From 8b99ccb75cd039b2200f1db46fadba4ac553b995 Mon Sep 17 00:00:00 2001 From: Mohammed Sohail Date: Wed, 1 Aug 2018 22:29:09 +0530 Subject: [PATCH 3/5] Add sendAnimation method Reference: Telegram API Documentation: https://core.telegram.org/bots/api#sendanimation --- src/telegram.js | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/telegram.js b/src/telegram.js index 878997c8..868d2686 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -838,6 +838,32 @@ class TelegramBot extends EventEmitter { return this._request('sendVideo', opts); } + /** + * Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound). + * @param {Number|String} chatId Unique identifier for the message recipient + * @param {String|stream.Stream|Buffer} doc A file path, Stream or Buffer. + * Can also be a `file_id` previously uploaded. + * @param {Object} [options] Additional Telegram query options + * @param {Object} [fileOptions] Optional file related meta-data + * @return {Promise} + * @see https://core.telegram.org/bots/api#sendanimation + * @see https://github.com/yagop/node-telegram-bot-api/blob/master/doc/usage.md#sending-files + */ + sendAnimation(chatId, animation, options = {}, fileOptions = {}) { + const opts = { + qs: options + }; + opts.qs.chat_id = chatId; + try { + const sendData = this._formatSendData('animation', animation, fileOptions); + opts.formData = sendData[0]; + opts.qs.document = sendData[1]; + } catch (ex) { + return Promise.reject(ex); + } + return this._request('sendAnimation', opts); + } + /** * Use this method to send rounded square videos of upto 1 minute long. * @param {Number|String} chatId Unique identifier for the message recipient From fadf738da4058da4d53dd3ccaf1aef07391cc3c5 Mon Sep 17 00:00:00 2001 From: Mohammed Sohail Date: Wed, 1 Aug 2018 22:31:43 +0530 Subject: [PATCH 4/5] Add passport_data message type Reference: Telegram API Documentation: https://core.telegram.org/bots/api#message --- src/telegram.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/telegram.js b/src/telegram.js index 868d2686..38329c55 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -37,6 +37,7 @@ const _messageTypes = [ 'new_chat_members', 'new_chat_photo', 'new_chat_title', + 'passport_data', 'photo', 'pinned_message', 'sticker', From cca75ec92a65423c0731d8a9cbeb16cc07b9f772 Mon Sep 17 00:00:00 2001 From: Mohammed Sohail Date: Wed, 1 Aug 2018 22:50:53 +0530 Subject: [PATCH 5/5] Add documentation --- doc/api.md | 41 +++++++++++++++++++++++++++++++++++++++++ src/telegram.js | 2 +- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/doc/api.md b/doc/api.md index c8b93950..d93cc251 100644 --- a/doc/api.md +++ b/doc/api.md @@ -35,6 +35,7 @@ TelegramBot * [.sendDocument(chatId, doc, [options], [fileOptions])](#TelegramBot+sendDocument) ⇒ Promise * [.sendSticker(chatId, sticker, [options], [fileOptions])](#TelegramBot+sendSticker) ⇒ Promise * [.sendVideo(chatId, video, [options], [fileOptions])](#TelegramBot+sendVideo) ⇒ Promise + * [.sendAnimation(chatId, animation, [options], [fileOptions])](#TelegramBot+sendAnimation) ⇒ Promise * [.sendVideoNote(chatId, videoNote, [options], [fileOptions])](#TelegramBot+sendVideoNote) ⇒ Promise * [.sendVoice(chatId, voice, [options], [fileOptions])](#TelegramBot+sendVoice) ⇒ Promise * [.sendChatAction(chatId, action, [options])](#TelegramBot+sendChatAction) ⇒ Promise @@ -52,6 +53,7 @@ TelegramBot * [.answerCallbackQuery(callbackQueryId, [options])](#TelegramBot+answerCallbackQuery) ⇒ Promise * [.editMessageText(text, [options])](#TelegramBot+editMessageText) ⇒ Promise * [.editMessageCaption(caption, [options])](#TelegramBot+editMessageCaption) ⇒ Promise + * [.editMessageMedia(media, [options])](#TelegramBot+editMessageMedia) ⇒ Promise * [.editMessageReplyMarkup(replyMarkup, [options])](#TelegramBot+editMessageReplyMarkup) ⇒ Promise * [.getUserProfilePhotos(userId, [options])](#TelegramBot+getUserProfilePhotos) ⇒ Promise * [.sendLocation(chatId, latitude, longitude, [options])](#TelegramBot+sendLocation) ⇒ Promise @@ -436,6 +438,25 @@ Use this method to send video files, Telegram clients support mp4 videos (other | [options] | Object | Additional Telegram query options | | [fileOptions] | Object | Optional file related meta-data | + + +### telegramBot.sendAnimation(chatId, animation, [options], [fileOptions]) ⇒ Promise +Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound). + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**See** + +- https://core.telegram.org/bots/api#sendanimation +- https://github.com/yagop/node-telegram-bot-api/blob/master/doc/usage.md#sending-files + + +| Param | Type | Description | +| --- | --- | --- | +| chatId | Number \| String | Unique identifier for the message recipient | +| animation | String \| stream.Stream \| Buffer | A file path, Stream or Buffer. Can also be a `file_id` previously uploaded. | +| [options] | Object | Additional Telegram query options | +| [fileOptions] | Object | Optional file related meta-data | + ### telegramBot.sendVideoNote(chatId, videoNote, [options], [fileOptions]) ⇒ Promise @@ -727,6 +748,26 @@ inline_message_id in your request. | caption | String | New caption of the message | | [options] | Object | Additional Telegram query options (provide either one of chat_id, message_id, or inline_message_id here) | + + +### telegramBot.editMessageMedia(media, [options]) ⇒ Promise +Use this method to edit 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. +Otherwise, message type can be changed arbitrarily. When inline message is edited, new file can't be uploaded. +Use previously uploaded file via its file_id or specify a URL. +On success, the edited Message is returned. + +Note that you must provide one of chat_id, message_id, or +inline_message_id in your request. + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**See**: https://core.telegram.org/bots/api#editmessagemedia + +| Param | Type | Description | +| --- | --- | --- | +| 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) | + ### telegramBot.editMessageReplyMarkup(replyMarkup, [options]) ⇒ Promise diff --git a/src/telegram.js b/src/telegram.js index 38329c55..88bb9f2a 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -842,7 +842,7 @@ class TelegramBot extends EventEmitter { /** * Use this method to send animation files (GIF or H.264/MPEG-4 AVC video without sound). * @param {Number|String} chatId Unique identifier for the message recipient - * @param {String|stream.Stream|Buffer} doc A file path, Stream or Buffer. + * @param {String|stream.Stream|Buffer} animation A file path, Stream or Buffer. * Can also be a `file_id` previously uploaded. * @param {Object} [options] Additional Telegram query options * @param {Object} [fileOptions] Optional file related meta-data