Skip to content

Commit 280a58c

Browse files
Support for Telegram Bot API 6.0
* Add method *setChatMenuButton()* * Add method *getChatMenuButton()* * Add method *setMyDefaultAdministratorRights()* * Add method *getMyDefaultAdministratorRights()* * Add method *answerWebAppQuery()* * Renamed the fields voice_chat_scheduled, voice_chat_started, voice_chat_ended, and voice_chat_participants_invited to video_chat_scheduled, video_chat_started, video_chat_ended, and video_chat_participants_invited Tests: * answerWebAppQuery * setChatMenuButton * getChatMenuButton * setMyDefaultAdministratorRights * getMyDefaultAdministratorRights
1 parent 0f33cb5 commit 280a58c

File tree

5 files changed

+236
-10
lines changed

5 files changed

+236
-10
lines changed

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,28 @@
33
All notable changes to this project will be documented in this file.
44
This project adheres to [Semantic Versioning](http://semver.org/).
55

6+
## [0.57.0][0.57.0] - 2022-04-23
7+
8+
Added:
9+
10+
1. Support Bot API v6: (@danielperez9430)
11+
12+
* Add method *setChatMenuButton()*
13+
* Add method *getChatMenuButton()*
14+
* Add method *setMyDefaultAdministratorRights()*
15+
* Add method *getMyDefaultAdministratorRights()*
16+
* Add method *answerWebAppQuery()*
17+
* Renamed the fields voice_chat_scheduled, voice_chat_started, voice_chat_ended, and voice_chat_participants_invited to video_chat_scheduled, video_chat_started, video_chat_ended, and video_chat_participants_invited
18+
19+
20+
Tests:
21+
22+
* answerWebAppQuery
23+
* setChatMenuButton
24+
* getChatMenuButton
25+
* setMyDefaultAdministratorRights
26+
* getMyDefaultAdministratorRights
27+
628
## [0.56.0][0.56.0] - 2021-12-07
729

830
Added:

doc/api.md

Lines changed: 76 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,13 @@ TelegramBot
6666
* [.unpinChatMessage(chatId, [options])](#TelegramBot+unpinChatMessage) ⇒ <code>Promise</code>
6767
* [.unpinAllChatMessages(chatId, [options])](#TelegramBot+unpinAllChatMessages) ⇒ <code>Promise</code>
6868
* [.answerCallbackQuery(callbackQueryId, [options])](#TelegramBot+answerCallbackQuery) ⇒ <code>Promise</code>
69+
* [.answerWebAppQuery(webAppQueryId, result, [options])](#TelegramBot+answerWebAppQuery) ⇒ <code>Promise</code>
6970
* [.setMyCommands(commands, [options])](#TelegramBot+setMyCommands) ⇒ <code>Promise</code>
7071
* [.getMyCommands([options])](#TelegramBot+getMyCommands) ⇒ <code>Promise</code>
72+
* [.setChatMenuButton([options])](#TelegramBot+setChatMenuButton) ⇒ <code>Promise</code>
73+
* [.getChatMenuButton([options])](#TelegramBot+getChatMenuButton) ⇒ <code>Promise</code>
74+
* [.setMyDefaultAdministratorRights([options])](#TelegramBot+setMyDefaultAdministratorRights) ⇒ <code>Promise</code>
75+
* [.getMyDefaultAdministratorRights([options])](#TelegramBot+getMyDefaultAdministratorRights) ⇒ <code>Promise</code>
7176
* [.deleteMyCommands([options])](#TelegramBot+deleteMyCommands) ⇒ <code>Promise</code>
7277
* [.editMessageText(text, [options])](#TelegramBot+editMessageText) ⇒ <code>Promise</code>
7378
* [.editMessageCaption(caption, [options])](#TelegramBot+editMessageCaption) ⇒ <code>Promise</code>
@@ -985,11 +990,26 @@ that are being deprecated.
985990
| callbackQueryId | <code>String</code> | Unique identifier for the query to be answered |
986991
| [options] | <code>Object</code> | Additional Telegram query options |
987992

993+
<a name="TelegramBot+answerWebAppQuery"></a>
994+
995+
### telegramBot.answerWebAppQuery(webAppQueryId, result, [options]) ⇒ <code>Promise</code>
996+
Use this method to set the result of an interaction with a Web App and send a corresponding message on behalf of the user to the chat from which the query originated.
997+
On success, a SentWebAppMessage object is returned.
998+
999+
**Kind**: instance method of [<code>TelegramBot</code>](#TelegramBot)
1000+
**See**: https://core.telegram.org/bots/api#answercallbackquery
1001+
1002+
| Param | Type | Description |
1003+
| --- | --- | --- |
1004+
| webAppQueryId | <code>String</code> | Unique identifier for the query to be answered |
1005+
| result | <code>InlineQueryResult</code> | object that represents one result of an inline query |
1006+
| [options] | <code>Object</code> | Additional Telegram query options |
1007+
9881008
<a name="TelegramBot+setMyCommands"></a>
9891009

9901010
### telegramBot.setMyCommands(commands, [options]) ⇒ <code>Promise</code>
991-
Returns True on success.
9921011
Use this method to change the list of the bot's commands.
1012+
Returns True on success.
9931013

9941014
**Kind**: instance method of [<code>TelegramBot</code>](#TelegramBot)
9951015
**See**: https://core.telegram.org/bots/api#setmycommands
@@ -1002,7 +1022,8 @@ Use this method to change the list of the bot's commands.
10021022
<a name="TelegramBot+getMyCommands"></a>
10031023

10041024
### telegramBot.getMyCommands([options]) ⇒ <code>Promise</code>
1005-
Returns Array of BotCommand on success.
1025+
Use this method to get the current list of the bot's commands for the given scope and user language.
1026+
Returns Array of BotCommand on success. If commands aren't set, an empty list is returned.
10061027

10071028
**Kind**: instance method of [<code>TelegramBot</code>](#TelegramBot)
10081029
**See**: https://core.telegram.org/bots/api#getmycommands
@@ -1011,6 +1032,59 @@ Returns Array of BotCommand on success.
10111032
| --- | --- | --- |
10121033
| [options] | <code>Object</code> | Additional Telegram query options |
10131034

1035+
<a name="TelegramBot+setChatMenuButton"></a>
1036+
1037+
### telegramBot.setChatMenuButton([options]) ⇒ <code>Promise</code>
1038+
Use this method to change the bot's menu button in a private chat, or the default menu button.
1039+
Returns True on success.
1040+
1041+
**Kind**: instance method of [<code>TelegramBot</code>](#TelegramBot)
1042+
**See**: https://core.telegram.org/bots/api#setchatmenubutton
1043+
1044+
| Param | Type | Description |
1045+
| --- | --- | --- |
1046+
| [options] | <code>Object</code> | Additional Telegram query options |
1047+
1048+
<a name="TelegramBot+getChatMenuButton"></a>
1049+
1050+
### telegramBot.getChatMenuButton([options]) ⇒ <code>Promise</code>
1051+
Use this method to get the current value of the bot's menu button in a private chat, or the default menu button.
1052+
Returns MenuButton on success.
1053+
1054+
**Kind**: instance method of [<code>TelegramBot</code>](#TelegramBot)
1055+
**See**: https://core.telegram.org/bots/api#getchatmenubutton
1056+
1057+
| Param | Type | Description |
1058+
| --- | --- | --- |
1059+
| [options] | <code>Object</code> | Additional Telegram query options |
1060+
1061+
<a name="TelegramBot+setMyDefaultAdministratorRights"></a>
1062+
1063+
### telegramBot.setMyDefaultAdministratorRights([options]) ⇒ <code>Promise</code>
1064+
Use this method to change the default administrator rights requested by the bot when it's added as an administrator to groups or channels.
1065+
These rights will be suggested to users, but they are are free to modify the list before adding the bot.
1066+
Returns True on success.
1067+
1068+
**Kind**: instance method of [<code>TelegramBot</code>](#TelegramBot)
1069+
**See**: https://core.telegram.org/bots/api#getchatmenubutton
1070+
1071+
| Param | Type | Description |
1072+
| --- | --- | --- |
1073+
| [options] | <code>Object</code> | Additional Telegram query options |
1074+
1075+
<a name="TelegramBot+getMyDefaultAdministratorRights"></a>
1076+
1077+
### telegramBot.getMyDefaultAdministratorRights([options]) ⇒ <code>Promise</code>
1078+
Use this method to get the current default administrator rights of the bot.
1079+
Returns ChatAdministratorRights on success.
1080+
1081+
**Kind**: instance method of [<code>TelegramBot</code>](#TelegramBot)
1082+
**See**: https://core.telegram.org/bots/api#getmydefaultadministratorrights
1083+
1084+
| Param | Type | Description |
1085+
| --- | --- | --- |
1086+
| [options] | <code>Object</code> | Additional Telegram query options |
1087+
10141088
<a name="TelegramBot+deleteMyCommands"></a>
10151089

10161090
### telegramBot.deleteMyCommands([options]) ⇒ <code>Promise</code>

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "node-telegram-bot-api",
3-
"version": "0.56.0",
3+
"version": "0.57.0",
44
"description": "Telegram Bot API",
55
"main": "./index.js",
66
"directories": {

src/telegram.js

Lines changed: 71 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@ const _messageTypes = [
4848
'video',
4949
'video_note',
5050
'voice',
51-
'voice_chat_started',
52-
'voice_chat_ended',
53-
'voice_chat_participants_invited',
54-
'voice_chat_scheduled',
51+
'video_chat_started',
52+
'video_chat_ended',
53+
'video_chat_participants_invited',
54+
'video_chat_scheduled',
5555
'message_auto_delete_timer_changed',
5656
'chat_invite_link',
57-
'chat_member_updated'
57+
'chat_member_updated',
58+
'web_app_data',
5859
];
5960
const _deprecatedMessageTypes = [
6061
'new_chat_participant', 'left_chat_participant'
@@ -1469,8 +1470,25 @@ class TelegramBot extends EventEmitter {
14691470
}
14701471

14711472
/**
1472-
* Returns True on success.
1473+
* Use this method to set the result of an interaction with a Web App and send a corresponding message on behalf of the user to the chat from which the query originated.
1474+
* On success, a SentWebAppMessage object is returned.
1475+
*
1476+
* @param {String} webAppQueryId Unique identifier for the query to be answered
1477+
* @param {InlineQueryResult} result object that represents one result of an inline query
1478+
* @param {Object} [options] Additional Telegram query options
1479+
* @return {Promise}
1480+
* @see https://core.telegram.org/bots/api#answercallbackquery
1481+
*/
1482+
answerWebAppQuery(webAppQueryId, result, form = {}) {
1483+
form.web_app_query_id = webAppQueryId;
1484+
form.result = stringify(result);
1485+
return this._request('answerCallbackQuery', { form });
1486+
}
1487+
1488+
1489+
/**
14731490
* Use this method to change the list of the bot's commands.
1491+
* Returns True on success.
14741492
* @param {Array} commands Poll options, between 2-10 options
14751493
* @param {Object} [options] Additional Telegram query options
14761494
* @return {Promise}
@@ -1482,7 +1500,8 @@ class TelegramBot extends EventEmitter {
14821500
}
14831501

14841502
/**
1485-
* Returns Array of BotCommand on success.
1503+
* Use this method to get the current list of the bot's commands for the given scope and user language.
1504+
* Returns Array of BotCommand on success. If commands aren't set, an empty list is returned.
14861505
* @param {Object} [options] Additional Telegram query options
14871506
* @return {Promise}
14881507
* @see https://core.telegram.org/bots/api#getmycommands
@@ -1491,6 +1510,51 @@ class TelegramBot extends EventEmitter {
14911510
return this._request('getMyCommands', { form });
14921511
}
14931512

1513+
/**
1514+
* Use this method to change the bot's menu button in a private chat, or the default menu button.
1515+
* Returns True on success.
1516+
* @param {Object} [options] Additional Telegram query options
1517+
* @return {Promise}
1518+
* @see https://core.telegram.org/bots/api#setchatmenubutton
1519+
*/
1520+
setChatMenuButton(form = {}) {
1521+
return this._request('setChatMenuButton', { form });
1522+
}
1523+
1524+
/**
1525+
* Use this method to get the current value of the bot's menu button in a private chat, or the default menu button.
1526+
* Returns MenuButton on success.
1527+
* @param {Object} [options] Additional Telegram query options
1528+
* @return {Promise}
1529+
* @see https://core.telegram.org/bots/api#getchatmenubutton
1530+
*/
1531+
getChatMenuButton(form = {}) {
1532+
return this._request('getChatMenuButton', { form });
1533+
}
1534+
1535+
/**
1536+
* Use this method to change the default administrator rights requested by the bot when it's added as an administrator to groups or channels.
1537+
* These rights will be suggested to users, but they are are free to modify the list before adding the bot.
1538+
* Returns True on success.
1539+
* @param {Object} [options] Additional Telegram query options
1540+
* @return {Promise}
1541+
* @see https://core.telegram.org/bots/api#getchatmenubutton
1542+
*/
1543+
setMyDefaultAdministratorRights(form = {}) {
1544+
return this._request('setMyDefaultAdministratorRights', { form });
1545+
}
1546+
1547+
/**
1548+
* Use this method to get the current default administrator rights of the bot.
1549+
* Returns ChatAdministratorRights on success.
1550+
* @param {Object} [options] Additional Telegram query options
1551+
* @return {Promise}
1552+
* @see https://core.telegram.org/bots/api#getmydefaultadministratorrights
1553+
*/
1554+
getMyDefaultAdministratorRights(form = {}) {
1555+
return this._request('getMyDefaultAdministratorRights', { form });
1556+
}
1557+
14941558
/**
14951559
* Returns True on success.
14961560
* Use this method to delete the list of the bot's commands for the given scope and user language.

test/telegram.js

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -864,6 +864,72 @@ describe('TelegramBot', function telegramSuite() {
864864
});
865865
});
866866

867+
868+
describe('#setChatMenuButton', function setChatMenuButtonSuite() {
869+
it('should set chat menu button', function test() {
870+
return bot.setChatMenuButton({
871+
chat_id: USERID,
872+
menu_button: JSON.stringify({ type: 'web_app', text: 'Hello', web_app: { url: 'https://webappcontent.telegram.org/cafe' } }),
873+
})
874+
.then(resp => {
875+
assert.ok(is.boolean(resp));
876+
});
877+
});
878+
});
879+
880+
describe('#getChatMenuButton', function getChatMenuButtonSuite() {
881+
it('should get chat menu button', function test() {
882+
return bot.getChatMenuButton().then(resp => {
883+
assert.ok(is.equal(resp, {
884+
type: 'web_app',
885+
text: 'Hello',
886+
web_app: { url: 'https://webappcontent.telegram.org/cafe' }
887+
}));
888+
});
889+
});
890+
});
891+
892+
describe('#setMyDefaultAdministratorRights', function setMyDefaultAdministratorRightsSuite() {
893+
it('should set default administrator rights', function test() {
894+
return bot.setMyDefaultAdministratorRights({
895+
rights: JSON.stringify({
896+
can_manage_chat: true,
897+
can_change_info: true,
898+
can_delete_messages: false,
899+
can_invite_users: true,
900+
can_restrict_members: false,
901+
can_pin_messages: true,
902+
can_promote_members: false,
903+
can_manage_video_chats: false,
904+
is_anonymous: false
905+
}),
906+
for_channels: false
907+
}).then(resp => {
908+
assert.ok(is.boolean(resp));
909+
});
910+
});
911+
});
912+
913+
describe('#getMyDefaultAdministratorRights ', function getMyDefaultAdministratorRightsSuite() {
914+
it('should get my default administrator rights', function test() {
915+
return bot.getMyDefaultAdministratorRights({
916+
for_channels: false
917+
}).then(resp => {
918+
assert.ok(is.equal(resp, {
919+
can_manage_chat: true,
920+
can_change_info: true,
921+
can_delete_messages: false,
922+
can_invite_users: true,
923+
can_restrict_members: false,
924+
can_pin_messages: true,
925+
can_promote_members: false,
926+
can_manage_video_chats: false,
927+
is_anonymous: false
928+
}));
929+
});
930+
});
931+
});
932+
867933
describe('#deleteMyCommands', function deleteMyCommandsSuite() {
868934
it('should delete bot commands', function test() {
869935
return bot.deleteMyCommands().then(resp => {

0 commit comments

Comments
 (0)