From 8b99ccb75cd039b2200f1db46fadba4ac553b995 Mon Sep 17 00:00:00 2001 From: Mohammed Sohail Date: Wed, 1 Aug 2018 22:29:09 +0530 Subject: [PATCH] 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 878997c..868d268 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