From 83d3235cc536ceca5b97802c8f1760759ea34166 Mon Sep 17 00:00:00 2001 From: Savely Krasovsky Date: Fri, 30 Jun 2017 16:57:32 +0300 Subject: [PATCH 1/3] src/telegram: Support Bot API v3.1 References: * Bot API v3.1: https://core.telegram.org/bots/api-changelog#june-30-2017 --- README.md | 2 +- doc/api.md | 145 ++++++++++++++++++++++++++++++++++++++++++++++ src/telegram.js | 151 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 297 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1fb310d..3003c5c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Node.js Telegram Bot API -[![Bot API](http://img.shields.io/badge/Bot%20API-v3.0.0-00aced.svg)](https://core.telegram.org/bots/api) +[![Bot API](https://img.shields.io/badge/Bot%20API-v.3.1.0-00aced.svg)](https://core.telegram.org/bots/api) [![Build Status](https://travis-ci.org/yagop/node-telegram-bot-api.svg?branch=master)](https://travis-ci.org/yagop/node-telegram-bot-api) [![Build status](https://ci.appveyor.com/api/projects/status/ujko6bsum3g5msjh/branch/master?svg=true)](https://ci.appveyor.com/project/yagop/node-telegram-bot-api/branch/master) [![Coverage Status](https://coveralls.io/repos/yagop/node-telegram-bot-api/badge.svg?branch=master)](https://coveralls.io/r/yagop/node-telegram-bot-api?branch=master) diff --git a/doc/api.md b/doc/api.md index 47c3d6e..0cd1369 100644 --- a/doc/api.md +++ b/doc/api.md @@ -38,6 +38,15 @@ TelegramBot * [.sendChatAction(chatId, action)](#TelegramBot+sendChatAction) ⇒ Promise * [.kickChatMember(chatId, userId)](#TelegramBot+kickChatMember) ⇒ Promise * [.unbanChatMember(chatId, userId)](#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 * [.answerCallbackQuery(callbackQueryId, text, showAlert, [options])](#TelegramBot+answerCallbackQuery) ⇒ Promise * [.editMessageText(text, [options])](#TelegramBot+editMessageText) ⇒ Promise * [.editMessageCaption(caption, [options])](#TelegramBot+editMessageCaption) ⇒ Promise @@ -422,6 +431,142 @@ 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 | String | Unique identifier of the target user | + + +### telegramBot.restrictChatMember(chatId, userId, [options]) ⇒ Promise +Use this method to restrict a user in a supergroup. +The bot must be an administrator in the supergroup for this to work +and must have the appropriate admin rights. Pass True for all boolean parameters +to lift restrictions from a user. Returns True on success. + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**See**: https://core.telegram.org/bots/api#restrictchatmember + +| Param | Type | Description | +| --- | --- | --- | +| chatId | Number | String | Unique identifier for the target chat or username of the target supergroup | +| userId | String | Unique identifier of the target user | +| [options] | Object | Additional Telegram query options | + + + +### telegramBot.promoteChatMember(chatId, userId, [options]) ⇒ Promise +Use this method to promote or demote a user in 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. Pass False for all boolean parameters to demote a user. +Returns True on success. + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**See**: https://core.telegram.org/bots/api#promotechatmember + +| Param | Type | Description | +| --- | --- | --- | +| chatId | Number | String | Unique identifier for the target chat or username of the target supergroup | +| userId | String | | +| [options] | Object | Additional Telegram query options | + + + +### telegramBot.exportChatInviteLink(chatId) ⇒ 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. + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**See**: https://core.telegram.org/bots/api#exportchatinvitelink + +| Param | Type | Description | +| --- | --- | --- | +| chatId | Number | String | Unique identifier for the target chat or username of the target supergroup | + + + +### telegramBot.setChatPhoto(chatId, photo) ⇒ 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. + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**See**: https://core.telegram.org/bots/api#setchatphoto + +| Param | Type | Description | +| --- | --- | --- | +| chatId | Number | String | Unique identifier for the message recipient | +| photo | stream.Stream | Buffer | A file path or a Stream. | + + + +### telegramBot.deleteChatPhoto(chatId) ⇒ 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. + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**See**: https://core.telegram.org/bots/api#deletechatphoto + +| Param | Type | Description | +| --- | --- | --- | +| chatId | Number | String | Unique identifier for the message recipient | + + + +### telegramBot.setChatTitle(chatId, title) ⇒ 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. + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**See**: https://core.telegram.org/bots/api#setchattitle + +| Param | Type | Description | +| --- | --- | --- | +| chatId | Number | String | Unique identifier for the message recipient | +| title | String | New chat title, 1-255 characters | + + + +### telegramBot.setChatDescription(chatId, description) ⇒ 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. + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**See**: https://core.telegram.org/bots/api#setchatdescription + +| Param | Type | Description | +| --- | --- | --- | +| chatId | Number | String | Unique identifier for the message recipient | +| description | String | New chat title, 1-255 characters | + + + +### telegramBot.pinChatMessage(chatId, messageId) ⇒ 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. + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**See**: https://core.telegram.org/bots/api#pinchatmessage + +| Param | Type | Description | +| --- | --- | --- | +| chatId | Number | String | Unique identifier for the message recipient | +| messageId | String | Identifier of a message to pin | + + + +### telegramBot.unpinChatMessage(chatId) ⇒ 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. + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**See**: https://core.telegram.org/bots/api#unpinchatmessage + +| Param | Type | Description | +| --- | --- | --- | +| chatId | Number | String | Unique identifier for the message recipient | + ### telegramBot.answerCallbackQuery(callbackQueryId, text, showAlert, [options]) ⇒ Promise diff --git a/src/telegram.js b/src/telegram.js index 3d3b609..d78b11a 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -844,6 +844,157 @@ class TelegramBot extends EventEmitter { return this._request('unbanChatMember', { form }); } + /** + * Use this method to restrict a user in a supergroup. + * The bot must be an administrator in the supergroup for this to work + * and must have the appropriate admin rights. Pass True for all boolean parameters + * to lift restrictions from a user. Returns True on success. + * + * @param {Number|String} chatId Unique identifier for the target chat or username of the target supergroup + * @param {String} userId Unique identifier of the target user + * @param {Object} [options] Additional Telegram query options + * @return {Promise} + * @see https://core.telegram.org/bots/api#restrictchatmember + */ + restrictChatMember(chatId, userId, form = {}) { + form.chat_id = chatId; + form.user_id = userId; + return this._request('restrictChatMember', { form }); + } + + /** + * Use this method to promote or demote a user in 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. Pass False for all boolean parameters to demote a user. + * Returns True on success. + * + * @param {Number|String} chatId Unique identifier for the target chat or username of the target supergroup + * @param {String} userId + * @param {Object} [options] Additional Telegram query options + * @return {Promise} + * @see https://core.telegram.org/bots/api#promotechatmember + */ + promoteChatMember(chatId, userId, form = {}) { + form.chat_id = chatId; + form.user_id = userId; + return this._request('promoteChatMember', { form }); + } + + /** + * 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. + * + * @param {Number|String} chatId Unique identifier for the target chat or username of the target supergroup + * @return {Promise} + * @see https://core.telegram.org/bots/api#exportchatinvitelink + */ + exportChatInviteLink(chatId, form = {}) { + form.chat_id = chatId; + return this._request('exportChatInviteLink', { form }); + } + + /** + * 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. + * + * @param {Number|String} chatId Unique identifier for the message recipient + * @param {stream.Stream|Buffer} photo A file path or a Stream. + * @return {Promise} + * @see https://core.telegram.org/bots/api#setchatphoto + */ + setChatPhoto(chatId, photo, options = {}) { + const opts = { + qs: options, + }; + opts.qs.chat_id = chatId; + try { + const sendData = this._formatSendData('photo', photo); + opts.formData = sendData[0]; + opts.qs.photo = sendData[1]; + } catch (ex) { + return Promise.reject(ex); + } + return this._request('setChatPhoto', opts); + } + + /** + * 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. + * + * @param {Number|String} chatId Unique identifier for the message recipient + * @return {Promise} + * @see https://core.telegram.org/bots/api#deletechatphoto + */ + deleteChatPhoto(chatId, form = {}) { + form.chat_id = chatId; + return this._request('deleteChatPhoto', { form }); + } + + /** + * 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. + * + * @param {Number|String} chatId Unique identifier for the message recipient + * @param {String} title New chat title, 1-255 characters + * @return {Promise} + * @see https://core.telegram.org/bots/api#setchattitle + */ + setChatTitle(chatId, title, form = {}) { + form.chat_id = chatId; + form.title = title; + return this._request('setChatTitle', { form }) + } + + /** + * 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. + * + * @param {Number|String} chatId Unique identifier for the message recipient + * @param {String} description New chat title, 1-255 characters + * @return {Promise} + * @see https://core.telegram.org/bots/api#setchatdescription + */ + setChatDescription(chatId, description, form = {}) { + form.chat_id = chatId; + form.description = description; + return this._request('setChatDescription', { form }) + } + + /** + * 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. + * + * @param {Number|String} chatId Unique identifier for the message recipient + * @param {String} messageId Identifier of a message to pin + * @return {Promise} + * @see https://core.telegram.org/bots/api#pinchatmessage + */ + pinChatMessage(chatId, messageId, form = {}) { + form.chat_id = chatId; + form.message_id = messageId; + return this._request('pinChatMessage', { form }); + } + + /** + * 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. + * + * @param {Number|String} chatId Unique identifier for the message recipient + * @return {Promise} + * @see https://core.telegram.org/bots/api#unpinchatmessage + */ + unpinChatMessage(chatId, form = {}) { + form.chat_id = chatId; + return this._request('unpinChatMessage', { form }); + } + /** * Use this method to send answers to callback queries sent from * inline keyboards. The answer will be displayed to the user as From 96b90c2d56c94a6078508d7a5aec10843dd84a21 Mon Sep 17 00:00:00 2001 From: GochoMugo Date: Wed, 5 Jul 2017 09:04:39 +0300 Subject: [PATCH 2/3] src/telegram: Add tests for Bot API v3.1 methods References: * PR: https://github.com/yagop/node-telegram-bot-api/pull/369 * PR-by: @kamikazechaser * Parent-PR: https://github.com/yagop/node-telegram-bot-api/pull/362 * Parent-PR-by: @Lord-Protector --- test/README.md | 1 + test/data/chat_photo.png | Bin 0 -> 12399 bytes test/telegram.js | 105 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 test/data/chat_photo.png diff --git a/test/README.md b/test/README.md index db6a07c..0e5a091 100644 --- a/test/README.md +++ b/test/README.md @@ -23,3 +23,4 @@ npm run test npm run eslint # static-analysis npm run mocha # mocha tests ``` +Note: The bot must be an administrator in the chat for this to work and must have the appropriate admin rights. \ No newline at end of file diff --git a/test/data/chat_photo.png b/test/data/chat_photo.png new file mode 100644 index 0000000000000000000000000000000000000000..ee0756db5e5f4ab4742c125e3e72bf41e2c246b3 GIT binary patch literal 12399 zcmaKTWmFv9wk-sAf;$8P1b252?$&6d-82@Q;1D1{0s(@%J2cQuAXwu8LU8Ng8Z2mV z!s9#Vo_pVq`(BMvwPma|*W7#0T5Hsgiqq3kBfzD>ML|I!P=Bp#@YEjub7NyZJ^iOO z$etQ%9~CnnLk}k(f1sBmih_fOogVL(08p$w&e0)45`S|?({dxU`cs;zF`2-{+B>uq=6y$lb;PDQ0_W=g* zxO=nw2SM4<+ujT8=>zs~XZi;bXy@VUBg6c}^xsQx^ZajEckln&rl$?#3jliZ3Gnj& zv!wqRYHR=hP2Jr7+uGa5!0~_h{;$B^MuDD=d!ANL^`xGEy8kWPr@?;<-_iX^?Oso^PHxj9MM2@-R999o3P2v_;d#={ zW>r2;3#HV?@>sOE0_|x@kFzr~#ZP12^_!FIrikDH6UZ#|TqWcixG#v0#vnFmMF|OeY-ywJQ<8aJTBO$wy)K#mP(J?fI9;*( z@GF0hdTjI2YDkC%UYhm${LiEG3{r%Fz*M|_U1%4kn#Ix;@&dBwK&9rtH2<6q zODH(0?A_U2&fHhYmGO$&T8C&%ue?y#p+<%7m7+xA%Od9O*ywNf31wP=tT%gPi8^#L z;+StbN*I&&=FLassTSH&wconFCj>&Yo?{ifwlnPS;YhLh@k)`cmj+Gzw)ArYJM|FxTUS-YzP;^WA=!TPcN=HJip9({4wO-0tk(}r zB5R@xQ_g*K7>l=WraC;<782|kbLQ|}Sw|^k>J?H%%X`^t8&qgsokG_8fB3%WEqZW` zqQemTQJ#*q)3_Cd8Tc+8Nz29M=Yk$)*NRt`CPsih4MgPPHxV>`iWztn$>m^#=Fy`D6Wl7f?!Y7Z8NI2p#zcW;p$Ik#f3{Tl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KO6en>ti!%X!Aba50WKFUt^!T*JL^)8791?6#$$&_fds=Xd|< zt3=WKgS3$7H+p_+3g|*#8?@oq)$kJFG}z*&bo@kE%Iymqd=p^_#CaF9Bc<8oYIl5g zcezM4_1r#|DC*Mdjx0LFd}Yai3slkqUkHu7NZ&t_T<;dIBPQ?7DQ*q6qRFHB$$Wo> z(S(cVuvR*zEN+JtHR=m=-dFctB! z#pI(3Nt9%<7EMMr;S77H2x)SFH7!oVJ%*&tJD zV>sLeiQm_7(M^zRxRX(jGNqUZ5%HG2AqrV=y<^f>9D}#28fkz87d^~05!bFY0MtNK z!3;1T&rR9^!`*TWR(weLveBBg?u)*sNi*};LA<0rQ>X&pwTFh%L2Fur6y5+tqf-p1 z(g_rk_2?g}5k{aNSJTLOlWm6()UvwsRYZM;bD&u`1eA$}OrPdQ!7hFxW-l)(^n vEAlp}566=YG7(^#nrMG&^0ylW4TbPk|8GCu-**4}0-&y { + assert(resp.match(/^https:\/\/t\.me\/joinchat\/.+$/i), 'is a telegram invite link'); + }); + }); + }); + + describe('#setChatPhoto', function setChatPhotoSuite() { + this.timeout(timeout); + before(function before() { + utils.handleRatelimit(bot, 'setChatPhoto', this); + }); + it('should set a chat photo from file', function test() { + const photo = `${__dirname}/data/chat_photo.png`; + return bot.setChatPhoto(GROUPID, photo).then(resp => { + assert.equal(resp, true); + }); + }); + it('should set a chat photo from fs.readStream', function test() { + const photo = fs.createReadStream(`${__dirname}/data/chat_photo.png`); + return bot.setChatPhoto(GROUPID, photo).then(resp => { + assert.equal(resp, true); + }); + }); + it('should set a chat photo from request Stream', function test() { + const photo = request(`${staticUrl}/chat_photo.png`); + return bot.setChatPhoto(GROUPID, photo).then(resp => { + assert.equal(resp, true); + }); + }); + it('should set a chat photo from a Buffer', function test() { + const photo = fs.readFileSync(`${__dirname}/data/chat_photo.png`); + return bot.setChatPhoto(GROUPID, photo).then(resp => { + assert.equal(resp, true); + }); + }); + }); + + describe('#deleteChatPhoto', function deleteChatPhotoSuite() { + before(function before() { + utils.handleRatelimit(bot, 'deleteChatPhoto', this); + }); + it('should delete the chat photo', function test() { + return bot.deleteChatPhoto(GROUPID).then(resp => { + assert.equal(resp, true); + }); + }); + }); + + describe('#setChatTitle', function setChatTitleSuite() { + before(function before() { + utils.handleRatelimit(bot, 'setChatTitle', this); + }); + it('should set the chat title', function test() { + return bot.setChatTitle(GROUPID, 'ntba test group').then(resp => { + assert.equal(resp, true); + }); + }); + }); + + describe('#setChatDescription', function setChatDescriptionSuite() { + before(function before() { + utils.handleRatelimit(bot, 'setChatDescription', this); + }); + it('should set the chat description', function test() { + return bot.setChatDescription(GROUPID, 'node-telegram-bot-api test group').then(resp => { + assert.equal(resp, true); + }); + }); + }); + + describe('#pinChatMessage', function pinChatMessageSuite() { + let messageId; + before(function before() { + utils.handleRatelimit(bot, 'pinChatMessage', this); + return bot.sendMessage(GROUPID, 'To be pinned').then(resp => { + messageId = resp.message_id; + }); + }); + it('should pin chat message', function test() { + return bot.pinChatMessage(GROUPID, messageId).then(resp => { + assert.equal(resp, true); + }); + }); + }); + + describe('#unpinChatMessage', function unpinChatMessageSuite() { + before(function before() { + utils.handleRatelimit(bot, 'unpinChatMessage', this); + }); + it('should unpin chat message', function test() { + return bot.unpinChatMessage(GROUPID).then(resp => { + assert.equal(resp, true); + }); + }); + }); + describe('#editMessageText', function editMessageTextSuite() { before(function before() { utils.handleRatelimit(bot, 'sendMessage', this); From 8ed0a2dcef7c5892da303814df5c86027efabb72 Mon Sep 17 00:00:00 2001 From: GochoMugo Date: Wed, 5 Jul 2017 11:38:39 +0300 Subject: [PATCH 3/3] test: Fix test for TelegramBot#setChatDescription() Bug: We MUST ensure we update the description. If the description is unchanged, an error is thrown by the API. Fix: Append a random number to the description. --- test/telegram.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/test/telegram.js b/test/telegram.js index d45f4ca..a087423 100644 --- a/test/telegram.js +++ b/test/telegram.js @@ -887,7 +887,9 @@ describe('TelegramBot', function telegramSuite() { utils.handleRatelimit(bot, 'setChatDescription', this); }); it('should set the chat description', function test() { - return bot.setChatDescription(GROUPID, 'node-telegram-bot-api test group').then(resp => { + const random = Math.floor(Math.random() * 1000); + const description = `node-telegram-bot-api test group (random: ${random})`; + return bot.setChatDescription(GROUPID, description).then(resp => { assert.equal(resp, true); }); });