Skip to content

Commit 00ffca5

Browse files
chore: Code style and order of the methods
1 parent cceea22 commit 00ffca5

File tree

2 files changed

+67
-100
lines changed

2 files changed

+67
-100
lines changed

doc/api.md

Lines changed: 33 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ TelegramBot
5858
* [.sendPoll(chatId, question, pollOptions, [options])](#TelegramBot+sendPoll) ⇒ <code>Promise</code>
5959
* [.sendDice(chatId, [options])](#TelegramBot+sendDice) ⇒ <code>Promise</code>
6060
* [.sendChatAction(chatId, action, [options])](#TelegramBot+sendChatAction) ⇒ <code>Promise</code>
61+
* [.setMessageReaction(chatId, messageId, [options])](#TelegramBot+setMessageReaction) ⇒ <code>[ &#x27;Promise&#x27; ].&lt;Boolean&gt;</code>
6162
* [.getUserProfilePhotos(userId, [options])](#TelegramBot+getUserProfilePhotos) ⇒ <code>Promise</code>
6263
* [.getFile(fileId, [options])](#TelegramBot+getFile) ⇒ <code>Promise</code>
6364
* [.banChatMember(chatId, userId, [options])](#TelegramBot+banChatMember) ⇒ <code>Promise</code>
@@ -120,7 +121,6 @@ TelegramBot
120121
* [.editMessageMedia(media, [options])](#TelegramBot+editMessageMedia) ⇒ <code>Promise</code>
121122
* [.editMessageReplyMarkup(replyMarkup, [options])](#TelegramBot+editMessageReplyMarkup) ⇒ <code>Promise</code>
122123
* [.stopPoll(chatId, pollId, [options])](#TelegramBot+stopPoll) ⇒ <code>Promise</code>
123-
* [.deleteMessage(chatId, messageId, [options])](#TelegramBot+deleteMessage) ⇒ <code>Promise</code>
124124
* [.sendSticker(chatId, sticker, [options], [fileOptions])](#TelegramBot+sendSticker) ⇒ <code>Promise</code>
125125
* [.getStickerSet(name, [options])](#TelegramBot+getStickerSet) ⇒ <code>Promise</code>
126126
* [.getCustomEmojiStickers(custom_emoji_ids, [options])](#TelegramBot+getCustomEmojiStickers) ⇒ <code>Promise</code>
@@ -145,9 +145,8 @@ TelegramBot
145145
* [.sendGame(chatId, gameShortName, [options])](#TelegramBot+sendGame) ⇒ <code>Promise</code>
146146
* [.setGameScore(userId, score, [options])](#TelegramBot+setGameScore) ⇒ <code>Promise</code>
147147
* [.getGameHighScores(userId, [options])](#TelegramBot+getGameHighScores) ⇒ <code>Promise</code>
148-
* [.setMessageReaction(chatId, messageId, [options])](#TelegramBot+setMessageReaction) ⇒ <code>[ &#x27;Promise&#x27; ].&lt;Boolean&gt;</code>
148+
* [.deleteMessage(chatId, messageId, [options])](#TelegramBot+deleteMessage) ⇒ <code>Promise</code>
149149
* [.deleteMessages(chatId, messageIds, [options])](#TelegramBot+deleteMessages) ⇒ <code>[ &#x27;Promise&#x27; ].&lt;Boolean&gt;</code>
150-
* [.copyMessages(chatId, fromChatId, messageIds, [options])](#TelegramBot+copyMessages) ⇒ <code>[ &#x27;Promise&#x27; ].&lt;Array.&lt;TelegramBot.MessageId&gt;&gt;</code>
151150
* _static_
152151
* [.errors](#TelegramBot.errors) : <code>Object</code>
153152
* [.messageTypes](#TelegramBot.messageTypes) : <code>[ &#x27;Array&#x27; ].&lt;String&gt;</code>
@@ -582,7 +581,7 @@ Returns the MessageId of the sent message on success.
582581
| --- | --- | --- |
583582
| chatId | <code>Number</code> \| <code>String</code> | Unique identifier for the target chat |
584583
| fromChatId | <code>Number</code> \| <code>String</code> | Unique identifier for the chat where the original message was sent |
585-
| messageIds | <code>Array</code> | Identifiers of 1-100 messages in the chat from_chat_id to copy. The identifiers must be specified in a strictly increasing order. |
584+
| messageIds | <code>Array</code> | Identifiers of 1-100 messages in the chat from_chat_id to copy. The identifiers must be specified in a strictly increasing order. |
586585
| [options] | <code>Object</code> | Additional Telegram query options |
587586

588587
<a name="TelegramBot+sendPhoto"></a>
@@ -903,6 +902,24 @@ Use this method when you need to tell the user that something is happening on th
903902
| action | <code>String</code> | Type of action to broadcast. |
904903
| [options] | <code>Object</code> | Additional Telegram query options |
905904

905+
<a name="TelegramBot+setMessageReaction"></a>
906+
907+
### telegramBot.setMessageReaction(chatId, messageId, [options]) ⇒ <code>[ &#x27;Promise&#x27; ].&lt;Boolean&gt;</code>
908+
Use this method to change the chosen reactions on a message.
909+
- Service messages can't be reacted to.
910+
- Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel.
911+
- In albums, bots must react to the first message.
912+
913+
**Kind**: instance method of [<code>TelegramBot</code>](#TelegramBot)
914+
**Returns**: <code>[ &#x27;Promise&#x27; ].&lt;Boolean&gt;</code> - True on success
915+
**See**: https://core.telegram.org/bots/api#setMessageReaction
916+
917+
| Param | Type | Description |
918+
| --- | --- | --- |
919+
| chatId | <code>Number</code> \| <code>String</code> | Unique identifier for the target chat or username of the target channel (in the format @channelusername) |
920+
| messageId | <code>Number</code> | Unique identifier of the target message |
921+
| [options] | <code>Object</code> | Additional Telegram query options |
922+
906923
<a name="TelegramBot+getUserProfilePhotos"></a>
907924

908925
### telegramBot.getUserProfilePhotos(userId, [options]) ⇒ <code>Promise</code>
@@ -1903,28 +1920,6 @@ Use this method to stop a poll which was sent by the bot.
19031920
| pollId | <code>Number</code> | Identifier of the original message with the poll |
19041921
| [options] | <code>Object</code> | Additional Telegram query options |
19051922

1906-
<a name="TelegramBot+deleteMessage"></a>
1907-
1908-
### telegramBot.deleteMessage(chatId, messageId, [options]) ⇒ <code>Promise</code>
1909-
Use this method to delete a message, including service messages, with the following limitations:
1910-
- A message can only be deleted if it was sent less than 48 hours ago.
1911-
- A dice message can only be deleted if it was sent more than 24 hours ago.
1912-
- Bots can delete outgoing messages in groups and supergroups.
1913-
- Bots can delete incoming messages in groups, supergroups and channels.
1914-
- Bots granted `can_post_messages` permissions can delete outgoing messages in channels.
1915-
- If the bot is an administrator of a group, it can delete any message there.
1916-
- If the bot has `can_delete_messages` permission in a supergroup, it can delete any message there.
1917-
1918-
**Kind**: instance method of [<code>TelegramBot</code>](#TelegramBot)
1919-
**Returns**: <code>Promise</code> - True on success
1920-
**See**: https://core.telegram.org/bots/api#deletemessage
1921-
1922-
| Param | Type | Description |
1923-
| --- | --- | --- |
1924-
| chatId | <code>Number</code> \| <code>String</code> | Unique identifier for the target chat or username of the target channel (in the format @channelusername) |
1925-
| messageId | <code>Number</code> | Unique identifier of the target message |
1926-
| [options] | <code>Object</code> | Additional Telegram query options |
1927-
19281923
<a name="TelegramBot+sendSticker"></a>
19291924

19301925
### telegramBot.sendSticker(chatId, sticker, [options], [fileOptions]) ⇒ <code>Promise</code>
@@ -2342,17 +2337,21 @@ Will return the score of the specified user and several of their neighbors in a
23422337
| userId | <code>Number</code> | Unique identifier of the target user |
23432338
| [options] | <code>Object</code> | Additional Telegram query options |
23442339

2345-
<a name="TelegramBot+setMessageReaction"></a>
2340+
<a name="TelegramBot+deleteMessage"></a>
23462341

2347-
### telegramBot.setMessageReaction(chatId, messageId, [options]) ⇒ <code>[ &#x27;Promise&#x27; ].&lt;Boolean&gt;</code>
2348-
Use this method to change the chosen reactions on a message.
2349-
- Service messages can't be reacted to.
2350-
- Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel.
2351-
- In albums, bots must react to the first message.
2342+
### telegramBot.deleteMessage(chatId, messageId, [options]) ⇒ <code>Promise</code>
2343+
Use this method to delete a message, including service messages, with the following limitations:
2344+
- A message can only be deleted if it was sent less than 48 hours ago.
2345+
- A dice message can only be deleted if it was sent more than 24 hours ago.
2346+
- Bots can delete outgoing messages in groups and supergroups.
2347+
- Bots can delete incoming messages in groups, supergroups and channels.
2348+
- Bots granted `can_post_messages` permissions can delete outgoing messages in channels.
2349+
- If the bot is an administrator of a group, it can delete any message there.
2350+
- If the bot has `can_delete_messages` permission in a supergroup, it can delete any message there.
23522351

23532352
**Kind**: instance method of [<code>TelegramBot</code>](#TelegramBot)
2354-
**Returns**: <code>[ &#x27;Promise&#x27; ].&lt;Boolean&gt;</code> - True on success
2355-
**See**: https://core.telegram.org/bots/api#setMessageReaction
2353+
**Returns**: <code>Promise</code> - True on success
2354+
**See**: https://core.telegram.org/bots/api#deletemessage
23562355

23572356
| Param | Type | Description |
23582357
| --- | --- | --- |
@@ -2375,22 +2374,6 @@ Use this method to delete multiple messages simultaneously. If some of the speci
23752374
| messageIds | <code>[ &#x27;Array&#x27; ].&lt;(Number\|String)&gt;</code> | Identifiers of 1-100 messages to delete. See deleteMessage for limitations on which messages can be deleted |
23762375
| [options] | <code>Object</code> | Additional Telegram query options |
23772376

2378-
<a name="TelegramBot+copyMessages"></a>
2379-
2380-
### telegramBot.copyMessages(chatId, fromChatId, messageIds, [options]) ⇒ <code>[ &#x27;Promise&#x27; ].&lt;Array.&lt;TelegramBot.MessageId&gt;&gt;</code>
2381-
Use this method to copy messages of any kind. If some of the specified messages can't be found or copied, they are skipped. Service messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessages, but the copied messages don't have a link to the original message. Album grouping is kept for copied messages.
2382-
2383-
**Kind**: instance method of [<code>TelegramBot</code>](#TelegramBot)
2384-
**Returns**: <code>[ &#x27;Promise&#x27; ].&lt;Array.&lt;TelegramBot.MessageId&gt;&gt;</code> - On success, an array of MessageId of the sent messages is returned.
2385-
**See**: https://core.telegram.org/bots/api#copyMessages
2386-
2387-
| Param | Type | Description |
2388-
| --- | --- | --- |
2389-
| chatId | <code>Number</code> \| <code>String</code> | Unique identifier for the target chat or username of the target channel (in the format @channelusername) |
2390-
| fromChatId | <code>Number</code> \| <code>String</code> | Unique identifier for the chat where the original message was sent (or channel username in the format `@channelusername`) |
2391-
| messageIds | <code>[ &#x27;Array&#x27; ].&lt;(Number\|String)&gt;</code> | Identifiers of 1-100 messages in the chat from_chat_id to copy. The identifiers must be specified in a strictly increasing order. |
2392-
| [options] | <code>Object</code> | Additional Telegram query options |
2393-
23942377
<a name="TelegramBot.errors"></a>
23952378

23962379
### TelegramBot.errors : <code>Object</code>

src/telegram.js

Lines changed: 34 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -977,7 +977,7 @@ class TelegramBot extends EventEmitter {
977977
* Use this method to copy messages of any kind. If some of the specified messages can't be found or copied, they are skipped.
978978
* Service messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied.
979979
* Returns the MessageId of the sent message on success.
980-
* @param {Number|String} chatId Unique identifier for the target chat
980+
* @param {Number|String} chatId Unique identifier for the target chat
981981
* @param {Number|String} fromChatId Unique identifier for the chat where the
982982
* original message was sent
983983
* @param {Array} messageIds Identifiers of 1-100 messages in the chat from_chat_id to copy.
@@ -1401,6 +1401,25 @@ class TelegramBot extends EventEmitter {
14011401
return this._request('sendChatAction', { form });
14021402
}
14031403

1404+
/**
1405+
* Use this method to change the chosen reactions on a message.
1406+
* - Service messages can't be reacted to.
1407+
* - Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel.
1408+
* - In albums, bots must react to the first message.
1409+
*
1410+
* @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
1411+
* @param {Number} messageId Unique identifier of the target message
1412+
* @param {Object} [options] Additional Telegram query options
1413+
* @return {Promise<Boolean>} True on success
1414+
* @see https://core.telegram.org/bots/api#setMessageReaction
1415+
*/
1416+
setMessageReaction(chatId, messageId, form = {}) {
1417+
form.chat_id = chatId;
1418+
form.message_id = messageId;
1419+
form.reaction = stringify(form.reaction);
1420+
return this._request('setMessageReaction', { form });
1421+
}
1422+
14041423
/**
14051424
* Use this method to get a list of profile pictures for a user.
14061425
* Returns a [UserProfilePhotos](https://core.telegram.org/bots/api#userprofilephotos) object.
@@ -2446,28 +2465,6 @@ class TelegramBot extends EventEmitter {
24462465
return this._request('stopPoll', { form });
24472466
}
24482467

2449-
/**
2450-
* Use this method to delete a message, including service messages, with the following limitations:
2451-
* - A message can only be deleted if it was sent less than 48 hours ago.
2452-
* - A dice message can only be deleted if it was sent more than 24 hours ago.
2453-
* - Bots can delete outgoing messages in groups and supergroups.
2454-
* - Bots can delete incoming messages in groups, supergroups and channels.
2455-
* - Bots granted `can_post_messages` permissions can delete outgoing messages in channels.
2456-
* - If the bot is an administrator of a group, it can delete any message there.
2457-
* - If the bot has `can_delete_messages` permission in a supergroup, it can delete any message there.
2458-
*
2459-
* @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
2460-
* @param {Number} messageId Unique identifier of the target message
2461-
* @param {Object} [options] Additional Telegram query options
2462-
* @return {Promise} True on success
2463-
* @see https://core.telegram.org/bots/api#deletemessage
2464-
*/
2465-
deleteMessage(chatId, messageId, form = {}) {
2466-
form.chat_id = chatId;
2467-
form.message_id = messageId;
2468-
return this._request('deleteMessage', { form });
2469-
}
2470-
24712468
/**
24722469
* Use this method to send static .WEBP, [animated](https://telegram.org/blog/animated-stickers) .TGS,
24732470
* or [video](https://telegram.org/blog/video-stickers-better-reactions) .WEBM stickers.
@@ -2967,23 +2964,27 @@ class TelegramBot extends EventEmitter {
29672964
return this._request('getGameHighScores', { form });
29682965
}
29692966

2970-
/**
2971-
* Use this method to change the chosen reactions on a message.
2972-
* - Service messages can't be reacted to.
2973-
* - Automatically forwarded messages from a channel to its discussion group have the same available reactions as messages in the channel.
2974-
* - In albums, bots must react to the first message.
2967+
2968+
/**
2969+
* Use this method to delete a message, including service messages, with the following limitations:
2970+
* - A message can only be deleted if it was sent less than 48 hours ago.
2971+
* - A dice message can only be deleted if it was sent more than 24 hours ago.
2972+
* - Bots can delete outgoing messages in groups and supergroups.
2973+
* - Bots can delete incoming messages in groups, supergroups and channels.
2974+
* - Bots granted `can_post_messages` permissions can delete outgoing messages in channels.
2975+
* - If the bot is an administrator of a group, it can delete any message there.
2976+
* - If the bot has `can_delete_messages` permission in a supergroup, it can delete any message there.
29752977
*
29762978
* @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
29772979
* @param {Number} messageId Unique identifier of the target message
29782980
* @param {Object} [options] Additional Telegram query options
2979-
* @return {Promise<Boolean>} True on success
2980-
* @see https://core.telegram.org/bots/api#setMessageReaction
2981+
* @return {Promise} True on success
2982+
* @see https://core.telegram.org/bots/api#deletemessage
29812983
*/
2982-
setMessageReaction(chatId, messageId, form = {}) {
2984+
deleteMessage(chatId, messageId, form = {}) {
29832985
form.chat_id = chatId;
29842986
form.message_id = messageId;
2985-
form.reaction = stringify(form.reaction);
2986-
return this._request('setMessageReaction', { form });
2987+
return this._request('deleteMessage', { form });
29872988
}
29882989

29892990
/**
@@ -3001,23 +3002,6 @@ class TelegramBot extends EventEmitter {
30013002
return this._request('deleteMessages', { form });
30023003
}
30033004

3004-
/**
3005-
* Use this method to copy messages of any kind. If some of the specified messages can't be found or copied, they are skipped. Service messages, giveaway messages, giveaway winners messages, and invoice messages can't be copied. A quiz poll can be copied only if the value of the field correct_option_id is known to the bot. The method is analogous to the method forwardMessages, but the copied messages don't have a link to the original message. Album grouping is kept for copied messages.
3006-
*
3007-
* @param {Number|String} chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername)
3008-
* @param {Number|String} fromChatId Unique identifier for the chat where the
3009-
* original message was sent (or channel username in the format `@channelusername`)
3010-
* @param {Array<Number|String>} messageIds Identifiers of 1-100 messages in the chat from_chat_id to copy. The identifiers must be specified in a strictly increasing order.
3011-
* @param {Object} [options] Additional Telegram query options
3012-
* @return {Promise<Array<TelegramBot.MessageId>>} On success, an array of MessageId of the sent messages is returned.
3013-
* @see https://core.telegram.org/bots/api#copyMessages
3014-
*/
3015-
copyMessages(chatId, from_chat_id, messageIds, form = {}) {
3016-
form.chat_id = chatId;
3017-
form.from_chat_id = from_chat_id;
3018-
form.message_ids = stringify(messageIds);
3019-
return this._request('copyMessages', { form });
3020-
}
30213005
}
30223006

30233007
module.exports = TelegramBot;

0 commit comments

Comments
 (0)