From 19b5fc5bd36ecc0657c66ab1409bc89bb0a3e012 Mon Sep 17 00:00:00 2001 From: danielperez9430 Date: Tue, 7 Dec 2021 16:41:35 +0100 Subject: [PATCH 1/5] fix(Test): Update test for new chat invite link format --- test/telegram.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/telegram.js b/test/telegram.js index 95df8ef..5a11aad 100644 --- a/test/telegram.js +++ b/test/telegram.js @@ -904,7 +904,7 @@ describe('TelegramBot', function telegramSuite() { }); it('should export the group invite link', function test() { return bot.exportChatInviteLink(GROUPID).then(resp => { - assert(resp.match(/^https:\/\/t\.me\/joinchat\/.+$/i), 'is a telegram invite link'); + assert(resp.match(/^https:\/\/t\.me\/.+$/i), 'is a telegram invite link'); }); }); }); @@ -918,7 +918,7 @@ describe('TelegramBot', function telegramSuite() { }); it('should create a chat invite link', function test() { return bot.createChatInviteLink(GROUPID).then(resp => { - assert(resp.invite_link.match(/^https:\/\/t\.me\/joinchat\/.+$/i), 'is a telegram invite link'); + assert(resp.invite_link.match(/^https:\/\/t\.me\/.+$/i), 'is a telegram invite link'); inviteLink = resp.invite_link; }); }); From 5ff22148d86591108a9037da88fb221a9b2c58dd Mon Sep 17 00:00:00 2001 From: danielperez9430 Date: Tue, 7 Dec 2021 16:42:00 +0100 Subject: [PATCH 2/5] feat: banChatSenderChat and unbanChatSenderChat methods --- src/telegram.js | 38 ++++++++++++++++++++++++++++++++++++++ test/telegram.js | 4 ++++ 2 files changed, 42 insertions(+) diff --git a/src/telegram.js b/src/telegram.js index 7c84f20..de2a2ea 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -1148,6 +1148,44 @@ class TelegramBot extends EventEmitter { return this._request('setChatAdministratorCustomTitle', { form }); } + + /** + * Use this method to ban a channel chat in a supergroup or a channel. + * The owner of the chat will not be able to send messages and join live streams + * on behalf of the chat, unless it is unbanned first. + * The bot must be an administrator in the supergroup or channel for this to work + * and must have the appropriate administrator rights. + * Returns True on success. + * + * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup + * @param {Number} senderChatId Unique identifier of the target user + * @param {Object} [options] Additional Telegram query options + * @return {Boolean} + * @see https://core.telegram.org/bots/api#banchatsenderchat + */ + banChatSenderChat(chatId, senderChatId, form = {}) { + form.chat_id = chatId; + form.sender_chat_id = senderChatId; + return this._request('banChatSenderChat', { form }); + } + + /** + * Use this method to unban a previously banned channel chat in a supergroup or channel. + * The bot must be an administrator for this to work and must have the appropriate administrator rights. + * Returns True on success. + * + * @param {Number|String} chatId Unique identifier for the target group or username of the target supergroup + * @param {Number} senderChatId Unique identifier of the target user + * @param {Object} [options] Additional Telegram query options + * @return {Boolean} + * @see https://core.telegram.org/bots/api#unbanchatsenderchat + */ + unbanChatSenderChat(chatId, senderChatId, form = {}) { + form.chat_id = chatId; + form.sender_chat_id = senderChatId; + return this._request('unbanChatSenderChat', { form }); + } + /** * Use this method to set default chat permissions for all members. * The bot must be an administrator in the group or a supergroup for this to diff --git a/test/telegram.js b/test/telegram.js index 5a11aad..f9f3258 100644 --- a/test/telegram.js +++ b/test/telegram.js @@ -880,6 +880,10 @@ describe('TelegramBot', function telegramSuite() { }); }); + describe.skip('#banChatSenderChat', function banChatSenderChatSuite() { }); + + describe.skip('#unbanChatSenderChat', function banChatSenderChatSuite() { }); + describe('#setChatPermissions ', function setChatPermissionsSuite() { it('should set chat permissions', function test() { const ChatPermissions = { From bbbc6cb8b8601c0db41fe186116d8fef0bb88cfc Mon Sep 17 00:00:00 2001 From: danielperez9430 Date: Tue, 7 Dec 2021 16:43:16 +0100 Subject: [PATCH 3/5] feat: Support Telegram Bot API 5.5 --- CHANGELOG.md | 13 +++++++++++++ README.md | 2 +- doc/api.md | 34 ++++++++++++++++++++++++++++++++++ package.json | 2 +- 4 files changed, 49 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 61f564b..75ddf72 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,19 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [0.56.0][0.56.0] - 2021-12-07 + +Added: + +1. Support Bot API v5.5: (@danielperez9430) + + * Add method *banChatSenderChat()* + * Add method *unbanChatSenderChat()* + + Fixes: + + * Tests for support with new invite link format + ## [0.55.0][0.55.0] - 2021-11-06 Added: diff --git a/README.md b/README.md index 7e720ff..5ed73bc 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Node.js module to interact with the official [Telegram Bot API](https://core.telegram.org/bots/api). -[![Bot API](https://img.shields.io/badge/Bot%20API-v.5.4-00aced.svg?style=flat-square&logo=telegram)](https://core.telegram.org/bots/api) +[![Bot API](https://img.shields.io/badge/Bot%20API-v.5.5-00aced.svg?style=flat-square&logo=telegram)](https://core.telegram.org/bots/api) [![npm package](https://img.shields.io/npm/v/node-telegram-bot-api?logo=npm&style=flat-square)](https://www.npmjs.org/package/node-telegram-bot-api) [![Build Status](https://img.shields.io/travis/yagop/node-telegram-bot-api/master?style=flat-square&logo=travis)](https://travis-ci.org/yagop/node-telegram-bot-api) [![Coverage Status](https://img.shields.io/codecov/c/github/yagop/node-telegram-bot-api?style=flat-square&logo=codecov)](https://codecov.io/gh/yagop/node-telegram-bot-api) diff --git a/doc/api.md b/doc/api.md index 1da6c16..6741bfe 100644 --- a/doc/api.md +++ b/doc/api.md @@ -49,6 +49,8 @@ TelegramBot * [.restrictChatMember(chatId, userId, [options])](#TelegramBot+restrictChatMember) ⇒ Promise * [.promoteChatMember(chatId, userId, [options])](#TelegramBot+promoteChatMember) ⇒ Promise * [.setChatAdministratorCustomTitle(chatId, userId, customTitle, [options])](#TelegramBot+setChatAdministratorCustomTitle) ⇒ Promise + * [.banChatSenderChat(chatId, senderChatId, [options])](#TelegramBot+banChatSenderChat) ⇒ Boolean + * [.unbanChatSenderChat(chatId, senderChatId, [options])](#TelegramBot+unbanChatSenderChat) ⇒ Boolean * [.setChatPermissions(chatId, chatPermissions, [options])](#TelegramBot+setChatPermissions) ⇒ Promise * [.exportChatInviteLink(chatId, [options])](#TelegramBot+exportChatInviteLink) ⇒ Promise * [.createChatInviteLink(chatId, [options])](#TelegramBot+createChatInviteLink) ⇒ Object @@ -703,6 +705,38 @@ Returns True on success. | customTitle | String | New custom title for the administrator; 0-16 characters, emoji are not allowed | | [options] | Object | Additional Telegram query options | + + +### telegramBot.banChatSenderChat(chatId, senderChatId, [options]) ⇒ Promise +Use this method to ban a channel chat in a supergroup or a channel. +The owner of the chat will not be able to send messages and join live streams on behalf of the chat, unless it is unbanned first. +Returns True on success. + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**See**: https://core.telegram.org/bots/api#banchatsenderchat + +| Param | Type | Description | +| --- | --- | --- | +| chatId | Number \| String | Unique identifier for the target chat or username of the target channel | +| senderChatId | Number | Unique identifier of the target sender chat | +| [options] | Object | Additional Telegram query options | + + + +### telegramBot.unbanChatSenderChat(chatId, senderChatId, [options]) ⇒ Promise +Use this method to unban a previously banned channel chat in a supergroup or channel. +The bot must be an administrator for this to work and must have the appropriate administrator rights. +Returns True on success. + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**See**: https://core.telegram.org/bots/api#unbanchatsenderchat + +| Param | Type | Description | +| --- | --- | --- | +| chatId | Number \| String | Unique identifier for the target chat or username of the target channel | +| senderChatId | Number | Unique identifier of the target sender chat | +| [options] | Object | Additional Telegram query options | + ### telegramBot.setChatPermissions(chatId, chatPermissions, [options]) ⇒ Promise diff --git a/package.json b/package.json index 5bf2bce..4d0a5d2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-telegram-bot-api", - "version": "0.55.0", + "version": "0.56.0", "description": "Telegram Bot API", "main": "./index.js", "directories": { From c6cb87ec12a06eb785d7aa430578cfcaa46928e1 Mon Sep 17 00:00:00 2001 From: danielperez9430 Date: Thu, 9 Dec 2021 02:27:38 +0100 Subject: [PATCH 4/5] fix: Bug with docs --- src/telegram.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/telegram.js b/src/telegram.js index de2a2ea..3a03d3a 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -1545,8 +1545,7 @@ class TelegramBot extends EventEmitter { * 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. + * 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) @@ -1571,7 +1570,7 @@ class TelegramBot extends EventEmitter { const [formData] = this._formatSendData( attachName, media.media.replace('attach://', ''), - media.fileOptions, + media.fileOptions ); if (formData) { From 1a7f41c9304a41d4c360185c2921339028d21c60 Mon Sep 17 00:00:00 2001 From: danielperez9430 Date: Thu, 9 Dec 2021 02:27:50 +0100 Subject: [PATCH 5/5] docs: Generate new docs --- doc/api.md | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/doc/api.md b/doc/api.md index 6741bfe..7729dcd 100644 --- a/doc/api.md +++ b/doc/api.md @@ -707,9 +707,12 @@ Returns True on success. -### telegramBot.banChatSenderChat(chatId, senderChatId, [options]) ⇒ Promise +### telegramBot.banChatSenderChat(chatId, senderChatId, [options]) ⇒ Boolean Use this method to ban a channel chat in a supergroup or a channel. -The owner of the chat will not be able to send messages and join live streams on behalf of the chat, unless it is unbanned first. +The owner of the chat will not be able to send messages and join live streams +on behalf of the chat, unless it is unbanned first. +The bot must be an administrator in the supergroup or channel for this to work +and must have the appropriate administrator rights. Returns True on success. **Kind**: instance method of [TelegramBot](#TelegramBot) @@ -717,13 +720,13 @@ Returns True on success. | Param | Type | Description | | --- | --- | --- | -| chatId | Number \| String | Unique identifier for the target chat or username of the target channel | -| senderChatId | Number | Unique identifier of the target sender chat | +| chatId | Number \| String | Unique identifier for the target group or username of the target supergroup | +| senderChatId | Number | Unique identifier of the target user | | [options] | Object | Additional Telegram query options | -### telegramBot.unbanChatSenderChat(chatId, senderChatId, [options]) ⇒ Promise +### telegramBot.unbanChatSenderChat(chatId, senderChatId, [options]) ⇒ Boolean Use this method to unban a previously banned channel chat in a supergroup or channel. The bot must be an administrator for this to work and must have the appropriate administrator rights. Returns True on success. @@ -733,8 +736,8 @@ Returns True on success. | Param | Type | Description | | --- | --- | --- | -| chatId | Number \| String | Unique identifier for the target chat or username of the target channel | -| senderChatId | Number | Unique identifier of the target sender chat | +| chatId | Number \| String | Unique identifier for the target group or username of the target supergroup | +| senderChatId | Number | Unique identifier of the target user | | [options] | Object | Additional Telegram query options | @@ -822,7 +825,7 @@ Returns the revoked invite link as ChatInviteLink object. ### telegramBot.approveChatJoinRequest(chatId, userId, [options]) ⇒ Boolean -Use this method to approve a chat join request. +Use this method to approve a chat join request. The bot must be an administrator in the chat for this to work and must have the can_invite_users administrator right. Returns True on success. @@ -1066,8 +1069,7 @@ Otherwise, message type can be changed arbitrarily. When inline message is edite 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. +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