From 921cb65fce5d98de35d4fea95428b997f9c2cc2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=C3=A9rez=20Fern=C3=A1ndez?= Date: Sun, 7 Nov 2021 16:02:53 +0100 Subject: [PATCH 1/8] docs: Update api.md --- doc/api.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/doc/api.md b/doc/api.md index fb78579..b863fb7 100644 --- a/doc/api.md +++ b/doc/api.md @@ -782,6 +782,40 @@ Returns the revoked invite link as ChatInviteLink object. | chatId | Number \| String | Unique identifier for the target chat or username of the target supergroup | | [options] | Object | Additional Telegram query options | + + +### telegramBot.approveChatJoinRequest(chatId, userId, [options]) ⇒ Boolean +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. + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**Returns**: Boolean - True on success +**See**: https://core.telegram.org/bots/api#approvechatjoinrequest + +| Param | Type | Description | +| --- | --- | --- | +| chatId | Number \| String | Unique identifier for the target chat or username of the target supergroup | +| userId | Number | Unique identifier of the target user | +| [options] | Object | Additional Telegram query options | + + + +### telegramBot.declineChatJoinRequest(chatId, userId, [options]) ⇒ Boolean +Use this method to decline 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. + +**Kind**: instance method of [TelegramBot](#TelegramBot) +**Returns**: Boolean - True on success +**See**: https://core.telegram.org/bots/api#declinechatjoinrequest + +| Param | Type | Description | +| --- | --- | --- | +| chatId | Number \| String | Unique identifier for the target chat or username of the target supergroup | +| userId | Number | Unique identifier of the target user | +| [options] | Object | Additional Telegram query options | + ### telegramBot.setChatPhoto(chatId, photo, [options], [fileOptions]) ⇒ Promise From b60f065a838bb5a363bcc73d129509c3497b17ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=C3=A9rez=20Fern=C3=A1ndez?= Date: Sun, 7 Nov 2021 16:06:51 +0100 Subject: [PATCH 2/8] feat: Add new method "approveChatJoinRequest" and "declineChatJoinRequest" --- src/telegram.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/telegram.js b/src/telegram.js index 15eb07b..330b67f 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -1225,6 +1225,40 @@ class TelegramBot extends EventEmitter { return this._request('revokeChatInviteLink', { form }); } + /** + * 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. + * + * @param {Number|String} chatId Unique identifier for the target chat or username of the target supergroup + * @param {Number} userId Unique identifier of the target user + * @param {Object} [options] Additional Telegram query options + * @return {Boolean} True on success + * @see https://core.telegram.org/bots/api#approvechatjoinrequest + */ + approveChatJoinRequest(chatId, userId, form = {}) { + form.chat_id = chatId; + form.user_id = userId; + return this._request('approveChatJoinRequest', { form }); + } + + /** + * Use this method to decline 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. + * + * @param {Number|String} chatId Unique identifier for the target chat or username of the target supergroup + * @param {Number} userId Unique identifier of the target user + * @param {Object} [options] Additional Telegram query options + * @return {Boolean} True on success + * @see https://core.telegram.org/bots/api#declinechatjoinrequest + */ + declineChatJoinRequest(chatId, userId, form = {}) { + form.chat_id = chatId; + form.user_id = userId; + return this._request('declineChatJoinRequest', { form }); + } + /** * Use this method to set a new profile photo for the chat. Photos can't be changed for private chats. From 15c878ea8937fb6869b82c3f2bece568b9e97697 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=C3=A9rez=20Fern=C3=A1ndez?= Date: Sun, 7 Nov 2021 16:07:21 +0100 Subject: [PATCH 3/8] docs: Update api.md --- doc/api.md | 5 ++++- src/telegram.js | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/doc/api.md b/doc/api.md index b863fb7..1da6c16 100644 --- a/doc/api.md +++ b/doc/api.md @@ -54,6 +54,8 @@ TelegramBot * [.createChatInviteLink(chatId, [options])](#TelegramBot+createChatInviteLink) ⇒ Object * [.editChatInviteLink(chatId, inviteLink, [options])](#TelegramBot+editChatInviteLink) ⇒ Object * [.revokeChatInviteLink(chatId, [options])](#TelegramBot+revokeChatInviteLink) ⇒ Object + * [.approveChatJoinRequest(chatId, userId, [options])](#TelegramBot+approveChatJoinRequest) ⇒ Boolean + * [.declineChatJoinRequest(chatId, userId, [options])](#TelegramBot+declineChatJoinRequest) ⇒ Boolean * [.setChatPhoto(chatId, photo, [options], [fileOptions])](#TelegramBot+setChatPhoto) ⇒ Promise * [.deleteChatPhoto(chatId, [options])](#TelegramBot+deleteChatPhoto) ⇒ Promise * [.setChatTitle(chatId, title, [options])](#TelegramBot+setChatTitle) ⇒ Promise @@ -584,7 +586,8 @@ Send chat action. `typing` for text messages, `upload_photo` for photos, `record_video` or `upload_video` for videos, `record_voice` or `upload_voice` for audio files, `upload_document` for general files, -`find_location` for location data. +`choose_sticker` for stickers, `find_location` for location data, +`record_video_note` or `upload_video_note` for video notes. **Kind**: instance method of [TelegramBot](#TelegramBot) **See**: https://core.telegram.org/bots/api#sendchataction diff --git a/src/telegram.js b/src/telegram.js index 330b67f..e4b7b2c 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -1017,7 +1017,8 @@ class TelegramBot extends EventEmitter { * `typing` for text messages, * `upload_photo` for photos, `record_video` or `upload_video` for videos, * `record_voice` or `upload_voice` for audio files, `upload_document` for general files, - * `find_location` for location data. + * `choose_sticker` for stickers, `find_location` for location data, + * `record_video_note` or `upload_video_note` for video notes. * * @param {Number|String} chatId Unique identifier for the message recipient * @param {String} action Type of action to broadcast. From 6c0f2e73c0c040d2116bb984eb68751f97de2e66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=C3=A9rez=20Fern=C3=A1ndez?= Date: Sun, 7 Nov 2021 16:07:50 +0100 Subject: [PATCH 4/8] feat: Add support for new event "chat_join_request" --- src/telegram.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/telegram.js b/src/telegram.js index e4b7b2c..b204873 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -624,6 +624,7 @@ class TelegramBot extends EventEmitter { const pollAnswer = update.poll_answer; const chatMember = update.chat_member; const myChatMember = update.my_chat_member; + const chatJoinRequest = update.chat_join_request; if (message) { debug('Process Update message %j', message); @@ -713,6 +714,9 @@ class TelegramBot extends EventEmitter { } else if (myChatMember) { debug('Process Update my_chat_member %j', myChatMember); this.emit('my_chat_member', myChatMember); + } else if (chatJoinRequest) { + debug('Process Update my_chat_member %j', chatJoinRequest); + this.emit('chat_join_request', chatJoinRequest); } } From a1e73481db7ac2e3a2dc574baef3c641477cbd59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=C3=A9rez=20Fern=C3=A1ndez?= Date: Sun, 7 Nov 2021 16:08:22 +0100 Subject: [PATCH 5/8] docs: Update changelod and readme --- CHANGELOG.md | 11 +++++++++++ README.md | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f659140..9389ea6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,17 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). +## [0.55.0][0.55.0] - 2021-11-06 + +Added: + +1. Support Bot API v5.4: (@danielperez9430) + + * Add method *approveChatJoinRequest()* + * Add method *declineChatJoinRequest()* + * Add support for new updates: + * *chat_join_request* + ## [0.54.0][0.54.0] - 2021-06-29 Added: diff --git a/README.md b/README.md index 36ac782..7e720ff 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.2-00aced.svg?style=flat-square&logo=telegram)](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) [![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) From d87e8d258d39e5328dff728d13437c6889180fbe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=C3=A9rez=20Fern=C3=A1ndez?= Date: Sun, 7 Nov 2021 16:08:57 +0100 Subject: [PATCH 6/8] chore: Update package.json version to 0.55.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 03cdc3c..5bf2bce 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "node-telegram-bot-api", - "version": "0.54.0", + "version": "0.55.0", "description": "Telegram Bot API", "main": "./index.js", "directories": { From b9e867573681db83842c1b2e0a5712ff12892241 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=C3=A9rez=20Fern=C3=A1ndez?= Date: Sun, 7 Nov 2021 18:55:14 +0100 Subject: [PATCH 7/8] fix: editMessageMedia - Now you can send a local file --- src/telegram.js | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/src/telegram.js b/src/telegram.js index b204873..7c84f20 100644 --- a/src/telegram.js +++ b/src/telegram.js @@ -1231,7 +1231,7 @@ class TelegramBot extends EventEmitter { } /** - * 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. * @@ -1516,7 +1516,43 @@ class TelegramBot extends EventEmitter { * @see https://core.telegram.org/bots/api#editmessagemedia */ editMessageMedia(media, form = {}) { + const regexAttach = /attach:\/\/.+/; + + if (typeof media.media === 'string' && regexAttach.test(media.media)) { + const opts = { + qs: form, + }; + + opts.formData = {}; + + const payload = Object.assign({}, media); + delete payload.media; + + try { + const attachName = String(0); + const [formData] = this._formatSendData( + attachName, + media.media.replace('attach://', ''), + media.fileOptions, + ); + + if (formData) { + opts.formData[attachName] = formData[attachName]; + payload.media = `attach://${attachName}`; + } else { + throw new errors.FatalError(`Failed to process the replacement action for your ${media.type}`); + } + } catch (ex) { + return Promise.reject(ex); + } + + opts.qs.media = JSON.stringify(payload); + + return this._request('editMessageMedia', opts); + } + form.media = stringify(media); + return this._request('editMessageMedia', { form }); } From e119612b5f30065d5d9416091069e15b19f50c27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20P=C3=A9rez=20Fern=C3=A1ndez?= Date: Sun, 7 Nov 2021 18:56:42 +0100 Subject: [PATCH 8/8] docs(Changelog) --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9389ea6..61f564b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,10 @@ Added: * Add method *declineChatJoinRequest()* * Add support for new updates: * *chat_join_request* + + Fixes: + + * Method *editMessageMedia*: Now you can send a local file (`"attach://" + filePatch`) ## [0.54.0][0.54.0] - 2021-06-29