From 57dec19babe78e674edcbaca06e0609610eb2777 Mon Sep 17 00:00:00 2001 From: GochoMugo Date: Mon, 27 Nov 2017 07:54:01 +0300 Subject: [PATCH] src: Support future additional Telegram parameters References: * FR: https://github.com/yagop/node-telegram-bot-api/issues/454 --- CHANGELOG.md | 1 + doc/api.md | 137 ++++++++++++++++++++++++++++++------------------ src/telegram.js | 134 +++++++++++++++++++++++----------------------- 3 files changed, 155 insertions(+), 117 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73a2a72..19bd314 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ Added: * (#440) *TelegramBot#setChatStickerSet*, *TelegramBot#deleteChatStickerSet* (by @kamikazechaser) 1. Add `metadata` argument in `message` event (and friends e.g. `text`, `audio`, etc.) (#409) (by @jlsjonas, @GochoMugo) +1. Add forward-compatibility i.e. support future additional Telegram options (by @GochoMugo) 1. Add support for Node.js v9 (by @GochoMugo) 1. Document *TelegramBot.errors*, *TelegramBot.messageTypes* (by @GochoMugo) diff --git a/doc/api.md b/doc/api.md index 610d472..8f6ece7 100644 --- a/doc/api.md +++ b/doc/api.md @@ -21,10 +21,10 @@ TelegramBot * [.openWebHook()](#TelegramBot+openWebHook) ⇒ Promise * [.closeWebHook()](#TelegramBot+closeWebHook) ⇒ Promise * [.hasOpenWebHook()](#TelegramBot+hasOpenWebHook) ⇒ Boolean - * [.getMe()](#TelegramBot+getMe) ⇒ Promise + * [.getMe([options])](#TelegramBot+getMe) ⇒ Promise * [.setWebHook(url, [options])](#TelegramBot+setWebHook) ⇒ Promise - * [.deleteWebHook()](#TelegramBot+deleteWebHook) ⇒ Promise - * [.getWebHookInfo()](#TelegramBot+getWebHookInfo) ⇒ Promise + * [.deleteWebHook([options])](#TelegramBot+deleteWebHook) ⇒ Promise + * [.getWebHookInfo([options])](#TelegramBot+getWebHookInfo) ⇒ Promise * [.getUpdates([options])](#TelegramBot+getUpdates) ⇒ Promise * [.processUpdate(update)](#TelegramBot+processUpdate) * [.sendMessage(chatId, text, [options])](#TelegramBot+sendMessage) ⇒ Promise @@ -37,18 +37,18 @@ TelegramBot * [.sendVideo(chatId, video, [options])](#TelegramBot+sendVideo) ⇒ Promise * [.sendVideoNote(chatId, videoNote, [options])](#TelegramBot+sendVideoNote) ⇒ Promise * [.sendVoice(chatId, voice, [options])](#TelegramBot+sendVoice) ⇒ Promise - * [.sendChatAction(chatId, action)](#TelegramBot+sendChatAction) ⇒ Promise - * [.kickChatMember(chatId, userId)](#TelegramBot+kickChatMember) ⇒ Promise - * [.unbanChatMember(chatId, userId)](#TelegramBot+unbanChatMember) ⇒ Promise + * [.sendChatAction(chatId, action, [options])](#TelegramBot+sendChatAction) ⇒ Promise + * [.kickChatMember(chatId, userId, [options])](#TelegramBot+kickChatMember) ⇒ Promise + * [.unbanChatMember(chatId, userId, [options])](#TelegramBot+unbanChatMember) ⇒ Promise * [.restrictChatMember(chatId, userId, [options])](#TelegramBot+restrictChatMember) ⇒ Promise * [.promoteChatMember(chatId, userId, [options])](#TelegramBot+promoteChatMember) ⇒ Promise - * [.exportChatInviteLink(chatId)](#TelegramBot+exportChatInviteLink) ⇒ Promise - * [.setChatPhoto(chatId, photo)](#TelegramBot+setChatPhoto) ⇒ Promise - * [.deleteChatPhoto(chatId)](#TelegramBot+deleteChatPhoto) ⇒ Promise - * [.setChatTitle(chatId, title)](#TelegramBot+setChatTitle) ⇒ Promise - * [.setChatDescription(chatId, description)](#TelegramBot+setChatDescription) ⇒ Promise - * [.pinChatMessage(chatId, messageId)](#TelegramBot+pinChatMessage) ⇒ Promise - * [.unpinChatMessage(chatId)](#TelegramBot+unpinChatMessage) ⇒ Promise + * [.exportChatInviteLink(chatId, [options])](#TelegramBot+exportChatInviteLink) ⇒ Promise + * [.setChatPhoto(chatId, photo, [options])](#TelegramBot+setChatPhoto) ⇒ Promise + * [.deleteChatPhoto(chatId, [options])](#TelegramBot+deleteChatPhoto) ⇒ Promise + * [.setChatTitle(chatId, title, [options])](#TelegramBot+setChatTitle) ⇒ Promise + * [.setChatDescription(chatId, description, [options])](#TelegramBot+setChatDescription) ⇒ Promise + * [.pinChatMessage(chatId, messageId, [options])](#TelegramBot+pinChatMessage) ⇒ Promise + * [.unpinChatMessage(chatId, [options])](#TelegramBot+unpinChatMessage) ⇒ Promise * [.answerCallbackQuery(callbackQueryId, [options])](#TelegramBot+answerCallbackQuery) ⇒ Promise * [.editMessageText(text, [options])](#TelegramBot+editMessageText) ⇒ Promise * [.editMessageCaption(caption, [options])](#TelegramBot+editMessageCaption) ⇒ Promise @@ -59,20 +59,20 @@ TelegramBot * [.stopMessageLiveLocation([options])](#TelegramBot+stopMessageLiveLocation) ⇒ Promise * [.sendVenue(chatId, latitude, longitude, title, address, [options])](#TelegramBot+sendVenue) ⇒ Promise * [.sendContact(chatId, phoneNumber, firstName, [options])](#TelegramBot+sendContact) ⇒ Promise - * [.getFile(fileId)](#TelegramBot+getFile) ⇒ Promise - * [.getFileLink(fileId)](#TelegramBot+getFileLink) ⇒ Promise - * [.downloadFile(fileId, downloadDir)](#TelegramBot+downloadFile) ⇒ Promise + * [.getFile(fileId, [options])](#TelegramBot+getFile) ⇒ Promise + * [.getFileLink(fileId, [options])](#TelegramBot+getFileLink) ⇒ Promise + * [.downloadFile(fileId, downloadDir, [options])](#TelegramBot+downloadFile) ⇒ Promise * [.onText(regexp, callback)](#TelegramBot+onText) * [.removeTextListener(regexp)](#TelegramBot+removeTextListener) ⇒ Object * [.onReplyToMessage(chatId, messageId, callback)](#TelegramBot+onReplyToMessage) ⇒ Number * [.removeReplyListener(replyListenerId)](#TelegramBot+removeReplyListener) ⇒ Object - * [.getChat(chatId)](#TelegramBot+getChat) ⇒ Promise - * [.getChatAdministrators(chatId)](#TelegramBot+getChatAdministrators) ⇒ Promise - * [.getChatMembersCount(chatId)](#TelegramBot+getChatMembersCount) ⇒ Promise - * [.getChatMember(chatId, userId)](#TelegramBot+getChatMember) ⇒ Promise - * [.leaveChat(chatId)](#TelegramBot+leaveChat) ⇒ Promise - * [.setChatStickerSet(chatId, stickerSetName)](#TelegramBot+setChatStickerSet) ⇒ Promise - * [.deleteChatStickerSet(chatId)](#TelegramBot+deleteChatStickerSet) ⇒ Promise + * [.getChat(chatId, [options])](#TelegramBot+getChat) ⇒ Promise + * [.getChatAdministrators(chatId, [options])](#TelegramBot+getChatAdministrators) ⇒ Promise + * [.getChatMembersCount(chatId, [options])](#TelegramBot+getChatMembersCount) ⇒ Promise + * [.getChatMember(chatId, userId, [options])](#TelegramBot+getChatMember) ⇒ Promise + * [.leaveChat(chatId, [options])](#TelegramBot+leaveChat) ⇒ Promise + * [.setChatStickerSet(chatId, stickerSetName, [options])](#TelegramBot+setChatStickerSet) ⇒ Promise + * [.deleteChatStickerSet(chatId, [options])](#TelegramBot+deleteChatStickerSet) ⇒ Promise * [.sendGame(chatId, gameShortName, [options])](#TelegramBot+sendGame) ⇒ Promise * [.setGameScore(userId, score, [options])](#TelegramBot+setGameScore) ⇒ Promise * [.getGameHighScores(userId, [options])](#TelegramBot+getGameHighScores) ⇒ Promise @@ -84,8 +84,8 @@ TelegramBot * [.uploadStickerFile(userId, pngSticker, [options])](#TelegramBot+uploadStickerFile) ⇒ Promise * [.createNewStickerSet(userId, name, title, pngSticker, emojis, [options])](#TelegramBot+createNewStickerSet) ⇒ Promise * [.addStickerToSet(userId, name, pngSticker, emojis, [options])](#TelegramBot+addStickerToSet) ⇒ Promise - * [.setStickerPositionInSet(sticker, position)](#TelegramBot+setStickerPositionInSet) ⇒ Promise - * [.deleteStickerFromSet(sticker)](#TelegramBot+deleteStickerFromSet) ⇒ Promise + * [.setStickerPositionInSet(sticker, position, [options])](#TelegramBot+setStickerPositionInSet) ⇒ Promise + * [.deleteStickerFromSet(sticker, [options])](#TelegramBot+deleteStickerFromSet) ⇒ Promise * _static_ * [.errors](#TelegramBot.errors) : Object * [.messageTypes](#TelegramBot.messageTypes) : Array.<String> @@ -206,11 +206,16 @@ Otherwise, false. **Kind**: instance method of [TelegramBot](#TelegramBot) -### telegramBot.getMe() ⇒ Promise +### telegramBot.getMe([options]) ⇒ Promise Returns basic information about the bot in form of a `User` object. **Kind**: instance method of [TelegramBot](#TelegramBot) **See**: https://core.telegram.org/bots/api#getme + +| Param | Type | Description | +| --- | --- | --- | +| [options] | Object | Additional Telegram query options | + ### telegramBot.setWebHook(url, [options]) ⇒ Promise @@ -229,15 +234,20 @@ that is being deprecated. -### telegramBot.deleteWebHook() ⇒ Promise +### telegramBot.deleteWebHook([options]) ⇒ Promise Use this method to remove webhook integration if you decide to switch back to getUpdates. Returns True on success. **Kind**: instance method of [TelegramBot](#TelegramBot) **See**: https://core.telegram.org/bots/api#deletewebhook + +| Param | Type | Description | +| --- | --- | --- | +| [options] | Object | Additional Telegram query options | + -### telegramBot.getWebHookInfo() ⇒ Promise +### telegramBot.getWebHookInfo([options]) ⇒ Promise Use this method to get current webhook status. On success, returns a [WebhookInfo](https://core.telegram.org/bots/api#webhookinfo) object. If the bot is using getUpdates, will return an object with the @@ -245,6 +255,11 @@ url field empty. **Kind**: instance method of [TelegramBot](#TelegramBot) **See**: https://core.telegram.org/bots/api#getwebhookinfo + +| Param | Type | Description | +| --- | --- | --- | +| [options] | Object | Additional Telegram query options | + ### telegramBot.getUpdates([options]) ⇒ Promise @@ -417,7 +432,7 @@ Send voice -### telegramBot.sendChatAction(chatId, action) ⇒ Promise +### telegramBot.sendChatAction(chatId, action, [options]) ⇒ Promise Send chat action. `typing` for text messages, `upload_photo` for photos, `record_video` or `upload_video` for videos, @@ -431,10 +446,11 @@ Send chat action. | --- | --- | --- | | chatId | Number | String | Unique identifier for the message recipient | | action | String | Type of action to broadcast. | +| [options] | Object | Additional Telegram query options | -### telegramBot.kickChatMember(chatId, userId) ⇒ Promise +### telegramBot.kickChatMember(chatId, userId, [options]) ⇒ Promise Use this method to kick a user from a group or a supergroup. In the case of supergroups, the user will not be able to return to the group on their own using invite links, etc., unless unbanned @@ -448,10 +464,11 @@ Returns True on success. | --- | --- | --- | | chatId | Number | String | Unique identifier for the target group or username of the target supergroup | | userId | Number | Unique identifier of the target user | +| [options] | Object | Additional Telegram query options | -### telegramBot.unbanChatMember(chatId, userId) ⇒ Promise +### telegramBot.unbanChatMember(chatId, userId, [options]) ⇒ Promise Use this method to unban a previously kicked user in a supergroup. The user will not return to the group automatically, but will be able to join via link, etc. The bot must be an administrator in @@ -464,6 +481,7 @@ the group for this to work. Returns True on success. | --- | --- | --- | | chatId | Number | String | Unique identifier for the target group or username of the target supergroup | | userId | Number | Unique identifier of the target user | +| [options] | Object | Additional Telegram query options | @@ -501,7 +519,7 @@ Returns True on success. -### telegramBot.exportChatInviteLink(chatId) ⇒ Promise +### telegramBot.exportChatInviteLink(chatId, [options]) ⇒ Promise Use this method to export an invite link to a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns exported invite link as String on success. @@ -512,10 +530,11 @@ Returns exported invite link as String on success. | Param | Type | Description | | --- | --- | --- | | chatId | Number | String | Unique identifier for the target chat or username of the target supergroup | +| [options] | Object | Additional Telegram query options | -### telegramBot.setChatPhoto(chatId, photo) ⇒ Promise +### telegramBot.setChatPhoto(chatId, photo, [options]) ⇒ Promise Use this method to set a new profile photo for the chat. Photos can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success. @@ -527,10 +546,11 @@ Returns True on success. | --- | --- | --- | | chatId | Number | String | Unique identifier for the message recipient | | photo | stream.Stream | Buffer | A file path or a Stream. | +| [options] | Object | Additional Telegram query options | -### telegramBot.deleteChatPhoto(chatId) ⇒ Promise +### telegramBot.deleteChatPhoto(chatId, [options]) ⇒ Promise Use this method to delete a chat photo. Photos can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success. @@ -541,10 +561,11 @@ Returns True on success. | Param | Type | Description | | --- | --- | --- | | chatId | Number | String | Unique identifier for the message recipient | +| [options] | Object | Additional Telegram query options | -### telegramBot.setChatTitle(chatId, title) ⇒ Promise +### telegramBot.setChatTitle(chatId, title, [options]) ⇒ Promise Use this method to change the title of a chat. Titles can't be changed for private chats. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success. @@ -556,10 +577,11 @@ Returns True on success. | --- | --- | --- | | chatId | Number | String | Unique identifier for the message recipient | | title | String | New chat title, 1-255 characters | +| [options] | Object | Additional Telegram query options | -### telegramBot.setChatDescription(chatId, description) ⇒ Promise +### telegramBot.setChatDescription(chatId, description, [options]) ⇒ Promise Use this method to change the description of a supergroup or a channel. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success. @@ -571,10 +593,11 @@ Returns True on success. | --- | --- | --- | | chatId | Number | String | Unique identifier for the message recipient | | description | String | New chat title, 1-255 characters | +| [options] | Object | Additional Telegram query options | -### telegramBot.pinChatMessage(chatId, messageId) ⇒ Promise +### telegramBot.pinChatMessage(chatId, messageId, [options]) ⇒ Promise Use this method to pin a message in a supergroup. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success. @@ -586,10 +609,11 @@ Returns True on success. | --- | --- | --- | | chatId | Number | String | Unique identifier for the message recipient | | messageId | String | Identifier of a message to pin | +| [options] | Object | Additional Telegram query options | -### telegramBot.unpinChatMessage(chatId) ⇒ Promise +### telegramBot.unpinChatMessage(chatId, [options]) ⇒ Promise Use this method to unpin a message in a supergroup chat. The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. Returns True on success. @@ -600,6 +624,7 @@ Returns True on success. | Param | Type | Description | | --- | --- | --- | | chatId | Number | String | Unique identifier for the message recipient | +| [options] | Object | Additional Telegram query options | @@ -776,7 +801,7 @@ Use this method to send phone contacts. -### telegramBot.getFile(fileId) ⇒ Promise +### telegramBot.getFile(fileId, [options]) ⇒ Promise Get file. Use this method to get basic info about a file and prepare it for downloading. Attention: link will be valid for 1 hour. @@ -787,10 +812,11 @@ Attention: link will be valid for 1 hour. | Param | Type | Description | | --- | --- | --- | | fileId | String | File identifier to get info about | +| [options] | Object | Additional Telegram query options | -### telegramBot.getFileLink(fileId) ⇒ Promise +### telegramBot.getFileLink(fileId, [options]) ⇒ Promise Get link for file. Use this method to get link for file for subsequent use. Attention: link will be valid for 1 hour. @@ -805,10 +831,11 @@ which returns just path to file on remote server (you will have to manually buil | Param | Type | Description | | --- | --- | --- | | fileId | String | File identifier to get info about | +| [options] | Object | Additional Telegram query options | -### telegramBot.downloadFile(fileId, downloadDir) ⇒ Promise +### telegramBot.downloadFile(fileId, downloadDir, [options]) ⇒ Promise Downloads file in the specified folder. This is just a sugar for (getFile)[#getfilefiled] method @@ -819,6 +846,7 @@ This is just a sugar for (getFile)[#getfilefiled] method | --- | --- | --- | | fileId | String | File identifier to get info about | | downloadDir | String | Absolute path to the folder in which file will be saved | +| [options] | Object | Additional Telegram query options | @@ -876,7 +904,7 @@ Removes a reply that has been prev. registered for a message response. -### telegramBot.getChat(chatId) ⇒ Promise +### telegramBot.getChat(chatId, [options]) ⇒ Promise Use this method to get up to date information about the chat (current name of the user for one-on-one conversations, current username of a user, group or channel, etc.). @@ -887,10 +915,11 @@ username of a user, group or channel, etc.). | Param | Type | Description | | --- | --- | --- | | chatId | Number | String | Unique identifier for the target chat or username of the target supergroup or channel | +| [options] | Object | Additional Telegram query options | -### telegramBot.getChatAdministrators(chatId) ⇒ Promise +### telegramBot.getChatAdministrators(chatId, [options]) ⇒ Promise Returns the administrators in a chat in form of an Array of `ChatMember` objects. **Kind**: instance method of [TelegramBot](#TelegramBot) @@ -899,10 +928,11 @@ Returns the administrators in a chat in form of an Array of `ChatMember` objects | Param | Type | Description | | --- | --- | --- | | chatId | Number | String | Unique identifier for the target group or username of the target supergroup | +| [options] | Object | Additional Telegram query options | -### telegramBot.getChatMembersCount(chatId) ⇒ Promise +### telegramBot.getChatMembersCount(chatId, [options]) ⇒ Promise Use this method to get the number of members in a chat. **Kind**: instance method of [TelegramBot](#TelegramBot) @@ -911,10 +941,11 @@ Use this method to get the number of members in a chat. | Param | Type | Description | | --- | --- | --- | | chatId | Number | String | Unique identifier for the target group or username of the target supergroup | +| [options] | Object | Additional Telegram query options | -### telegramBot.getChatMember(chatId, userId) ⇒ Promise +### telegramBot.getChatMember(chatId, userId, [options]) ⇒ Promise Use this method to get information about a member of a chat. **Kind**: instance method of [TelegramBot](#TelegramBot) @@ -924,10 +955,11 @@ Use this method to get information about a member of a chat. | --- | --- | --- | | chatId | Number | String | Unique identifier for the target group or username of the target supergroup | | userId | Number | Unique identifier of the target user | +| [options] | Object | Additional Telegram query options | -### telegramBot.leaveChat(chatId) ⇒ Promise +### telegramBot.leaveChat(chatId, [options]) ⇒ Promise Leave a group, supergroup or channel. **Kind**: instance method of [TelegramBot](#TelegramBot) @@ -936,10 +968,11 @@ Leave a group, supergroup or channel. | Param | Type | Description | | --- | --- | --- | | chatId | Number | String | Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername) | +| [options] | Object | Additional Telegram query options | -### telegramBot.setChatStickerSet(chatId, stickerSetName) ⇒ Promise +### telegramBot.setChatStickerSet(chatId, stickerSetName, [options]) ⇒ Promise Use this method to set a new group sticker set for a supergroup. **Kind**: instance method of [TelegramBot](#TelegramBot) @@ -949,10 +982,11 @@ Use this method to set a new group sticker set for a supergroup. | --- | --- | --- | | chatId | Number | String | Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername) | | stickerSetName | String | Name of the sticker set to be set as the group sticker set | +| [options] | Object | Additional Telegram query options | -### telegramBot.deleteChatStickerSet(chatId) ⇒ Promise +### telegramBot.deleteChatStickerSet(chatId, [options]) ⇒ Promise Use this method to delete a group sticker set from a supergroup. **Kind**: instance method of [TelegramBot](#TelegramBot) @@ -961,6 +995,7 @@ Use this method to delete a group sticker set from a supergroup. | Param | Type | Description | | --- | --- | --- | | chatId | Number | String | Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername) | +| [options] | Object | Additional Telegram query options | @@ -1142,7 +1177,7 @@ Returns True on success. -### telegramBot.setStickerPositionInSet(sticker, position) ⇒ Promise +### telegramBot.setStickerPositionInSet(sticker, position, [options]) ⇒ Promise Use this method to move a sticker in a set created by the bot to a specific position. Returns True on success. @@ -1157,10 +1192,11 @@ Returns True on success. | --- | --- | --- | | sticker | String | File identifier of the sticker | | position | Number | New sticker position in the set, zero-based | +| [options] | Object | Additional Telegram query options | -### telegramBot.deleteStickerFromSet(sticker) ⇒ Promise +### telegramBot.deleteStickerFromSet(sticker, [options]) ⇒ Promise Use this method to delete a sticker from a set created by the bot. Returns True on success. @@ -1174,6 +1210,7 @@ Returns True on success. | Param | Type | Description | | --- | --- | --- | | sticker | String | File identifier of the sticker | +| [options] | Object | Additional Telegram query options | diff --git a/src/telegram.js b/src/telegram.js index 7d0d441..72f4283 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -416,12 +416,12 @@ class TelegramBot extends EventEmitter { /** * Returns basic information about the bot in form of a `User` object. + * @param {Object} [options] Additional Telegram query options * @return {Promise} * @see https://core.telegram.org/bots/api#getme */ - getMe() { - const _path = 'getMe'; - return this._request(_path); + getMe(form = {}) { + return this._request('getMe', { form }); } /** @@ -471,11 +471,12 @@ class TelegramBot extends EventEmitter { /** * Use this method to remove webhook integration if you decide to * switch back to getUpdates. Returns True on success. + * @param {Object} [options] Additional Telegram query options * @return {Promise} * @see https://core.telegram.org/bots/api#deletewebhook */ - deleteWebHook() { - return this._request('deleteWebhook'); + deleteWebHook(form = {}) { + return this._request('deleteWebhook', { form }); } /** @@ -483,11 +484,12 @@ class TelegramBot extends EventEmitter { * On success, returns a [WebhookInfo](https://core.telegram.org/bots/api#webhookinfo) object. * If the bot is using getUpdates, will return an object with the * url field empty. + * @param {Object} [options] Additional Telegram query options * @return {Promise} * @see https://core.telegram.org/bots/api#getwebhookinfo */ - getWebHookInfo() { - return this._request('getWebhookInfo'); + getWebHookInfo(form = {}) { + return this._request('getWebhookInfo', { form }); } /** @@ -842,14 +844,13 @@ class TelegramBot extends EventEmitter { * * @param {Number|String} chatId Unique identifier for the message recipient * @param {String} action Type of action to broadcast. + * @param {Object} [options] Additional Telegram query options * @return {Promise} * @see https://core.telegram.org/bots/api#sendchataction */ - sendChatAction(chatId, action) { - const form = { - action, - chat_id: chatId - }; + sendChatAction(chatId, action, form = {}) { + form.chat_id = chatId; + form.action = action; return this._request('sendChatAction', { form }); } @@ -862,14 +863,13 @@ class TelegramBot extends EventEmitter { * * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup * @param {Number} userId Unique identifier of the target user + * @param {Object} [options] Additional Telegram query options * @return {Promise} * @see https://core.telegram.org/bots/api#kickchatmember */ - kickChatMember(chatId, userId) { - const form = { - chat_id: chatId, - user_id: userId - }; + kickChatMember(chatId, userId, form = {}) { + form.chat_id = chatId; + form.user_id = userId; return this._request('kickChatMember', { form }); } @@ -881,14 +881,13 @@ class TelegramBot extends EventEmitter { * * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup * @param {Number} userId Unique identifier of the target user + * @param {Object} [options] Additional Telegram query options * @return {Promise} * @see https://core.telegram.org/bots/api#unbanchatmember */ - unbanChatMember(chatId, userId) { - const form = { - chat_id: chatId, - user_id: userId - }; + unbanChatMember(chatId, userId, form = {}) { + form.chat_id = chatId; + form.user_id = userId; return this._request('unbanChatMember', { form }); } @@ -934,6 +933,7 @@ class TelegramBot extends EventEmitter { * Returns exported invite link as String on success. * * @param {Number|String} chatId Unique identifier for the target chat or username of the target supergroup + * @param {Object} [options] Additional Telegram query options * @return {Promise} * @see https://core.telegram.org/bots/api#exportchatinvitelink */ @@ -949,6 +949,7 @@ class TelegramBot extends EventEmitter { * * @param {Number|String} chatId Unique identifier for the message recipient * @param {stream.Stream|Buffer} photo A file path or a Stream. + * @param {Object} [options] Additional Telegram query options * @return {Promise} * @see https://core.telegram.org/bots/api#setchatphoto */ @@ -973,6 +974,7 @@ class TelegramBot extends EventEmitter { * Returns True on success. * * @param {Number|String} chatId Unique identifier for the message recipient + * @param {Object} [options] Additional Telegram query options * @return {Promise} * @see https://core.telegram.org/bots/api#deletechatphoto */ @@ -988,6 +990,7 @@ class TelegramBot extends EventEmitter { * * @param {Number|String} chatId Unique identifier for the message recipient * @param {String} title New chat title, 1-255 characters + * @param {Object} [options] Additional Telegram query options * @return {Promise} * @see https://core.telegram.org/bots/api#setchattitle */ @@ -1004,6 +1007,7 @@ class TelegramBot extends EventEmitter { * * @param {Number|String} chatId Unique identifier for the message recipient * @param {String} description New chat title, 1-255 characters + * @param {Object} [options] Additional Telegram query options * @return {Promise} * @see https://core.telegram.org/bots/api#setchatdescription */ @@ -1020,6 +1024,7 @@ class TelegramBot extends EventEmitter { * * @param {Number|String} chatId Unique identifier for the message recipient * @param {String} messageId Identifier of a message to pin + * @param {Object} [options] Additional Telegram query options * @return {Promise} * @see https://core.telegram.org/bots/api#pinchatmessage */ @@ -1035,6 +1040,7 @@ class TelegramBot extends EventEmitter { * Returns True on success. * * @param {Number|String} chatId Unique identifier for the message recipient + * @param {Object} [options] Additional Telegram query options * @return {Promise} * @see https://core.telegram.org/bots/api#unpinchatmessage */ @@ -1266,11 +1272,12 @@ class TelegramBot extends EventEmitter { * Attention: link will be valid for 1 hour. * * @param {String} fileId File identifier to get info about + * @param {Object} [options] Additional Telegram query options * @return {Promise} * @see https://core.telegram.org/bots/api#getfile */ - getFile(fileId) { - const form = { file_id: fileId }; + getFile(fileId, form = {}) { + form.file_id = fileId; return this._request('getFile', { form }); } @@ -1283,11 +1290,12 @@ class TelegramBot extends EventEmitter { * which returns just path to file on remote server (you will have to manually build full uri after that). * * @param {String} fileId File identifier to get info about + * @param {Object} [options] Additional Telegram query options * @return {Promise} promise Promise which will have *fileURI* in resolve callback * @see https://core.telegram.org/bots/api#getfile */ - getFileLink(fileId) { - return this.getFile(fileId) + getFileLink(fileId, form = {}) { + return this.getFile(fileId, form) .then(resp => `${this.options.baseApiUrl}/file/bot${this.token}/${resp.file_path}`); } @@ -1297,11 +1305,12 @@ class TelegramBot extends EventEmitter { * * @param {String} fileId File identifier to get info about * @param {String} downloadDir Absolute path to the folder in which file will be saved + * @param {Object} [options] Additional Telegram query options * @return {Promise} promise Promise, which will have *filePath* of downloaded file in resolve callback */ - downloadFile(fileId, downloadDir) { + downloadFile(fileId, downloadDir, form = {}) { return this - .getFileLink(fileId) + .getFileLink(fileId, form) .then(fileURI => { const fileName = fileURI.slice(fileURI.lastIndexOf('/') + 1); // TODO: Ensure fileName doesn't contains slashes @@ -1384,39 +1393,36 @@ class TelegramBot extends EventEmitter { * (current name of the user for one-on-one conversations, current * username of a user, group or channel, etc.). * @param {Number|String} chatId Unique identifier for the target chat or username of the target supergroup or channel + * @param {Object} [options] Additional Telegram query options * @return {Promise} * @see https://core.telegram.org/bots/api#getchat */ - getChat(chatId) { - const form = { - chat_id: chatId - }; + getChat(chatId, form = {}) { + form.chat_id = chatId; return this._request('getChat', { form }); } /** * Returns the administrators in a chat in form of an Array of `ChatMember` objects. * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup + * @param {Object} [options] Additional Telegram query options * @return {Promise} * @see https://core.telegram.org/bots/api#getchatadministrators */ - getChatAdministrators(chatId) { - const form = { - chat_id: chatId - }; + getChatAdministrators(chatId, form = {}) { + form.chat_id = chatId; return this._request('getChatAdministrators', { form }); } /** * Use this method to get the number of members in a chat. * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup + * @param {Object} [options] Additional Telegram query options * @return {Promise} * @see https://core.telegram.org/bots/api#getchatmemberscount */ - getChatMembersCount(chatId) { - const form = { - chat_id: chatId - }; + getChatMembersCount(chatId, form = {}) { + form.chat_id = chatId; return this._request('getChatMembersCount', { form }); } @@ -1424,27 +1430,25 @@ class TelegramBot extends EventEmitter { * Use this method to get information about a member of a chat. * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup * @param {Number} userId Unique identifier of the target user + * @param {Object} [options] Additional Telegram query options * @return {Promise} * @see https://core.telegram.org/bots/api#getchatmember */ - getChatMember(chatId, userId) { - const form = { - chat_id: chatId, - user_id: userId - }; + getChatMember(chatId, userId, form = {}) { + form.chat_id = chatId; + form.user_id = userId; return this._request('getChatMember', { form }); } /** * Leave a group, supergroup or channel. * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername) + * @param {Object} [options] Additional Telegram query options * @return {Promise} * @see https://core.telegram.org/bots/api#leavechat */ - leaveChat(chatId) { - const form = { - chat_id: chatId - }; + leaveChat(chatId, form = {}) { + form.chat_id = chatId; return this._request('leaveChat', { form }); } @@ -1452,27 +1456,25 @@ class TelegramBot extends EventEmitter { * Use this method to set a new group sticker set for a supergroup. * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername) * @param {String} stickerSetName Name of the sticker set to be set as the group sticker set + * @param {Object} [options] Additional Telegram query options * @return {Promise} * @see https://core.telegram.org/bots/api#setchatstickerset */ - setChatStickerSet(chatId, stickerSetName) { - const form = { - chat_id: chatId, - sticker_set_name: stickerSetName - }; + setChatStickerSet(chatId, stickerSetName, form = {}) { + form.chat_id = chatId; + form.sticker_set_name = stickerSetName; return this._request('setChatStickerSet', { form }); } /** * Use this method to delete a group sticker set from a supergroup. * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup (in the format @supergroupusername) + * @param {Object} [options] Additional Telegram query options * @return {Promise} * @see https://core.telegram.org/bots/api#deletechatstickerset */ - deleteChatStickerSet(chatId) { - const form = { - chat_id: chatId - }; + deleteChatStickerSet(chatId, form = {}) { + form.chat_id = chatId; return this._request('deleteChatStickerSet', { form }); } @@ -1703,15 +1705,14 @@ class TelegramBot extends EventEmitter { * * @param {String} sticker File identifier of the sticker * @param {Number} position New sticker position in the set, zero-based + * @param {Object} [options] Additional Telegram query options * @return {Promise} * @see https://core.telegram.org/bots/api#setstickerpositioninset * @todo Add tests for this method! */ - setStickerPositionInSet(sticker, position) { - const form = { - sticker, - position, - }; + setStickerPositionInSet(sticker, position, form = {}) { + form.sticker = sticker; + form.position = position; return this._request('setStickerPositionInSet', { form }); } @@ -1720,14 +1721,13 @@ class TelegramBot extends EventEmitter { * Returns True on success. * * @param {String} sticker File identifier of the sticker + * @param {Object} [options] Additional Telegram query options * @return {Promise} * @see https://core.telegram.org/bots/api#deletestickerfromset * @todo Add tests for this method! */ - deleteStickerFromSet(sticker) { - const form = { - sticker, - }; + deleteStickerFromSet(sticker, form = {}) { + form.sticker = sticker; return this._request('deleteStickerFromSet', { form }); } }