From 9f29616ce9282b6c7f74a07fcc085be7bdd33845 Mon Sep 17 00:00:00 2001 From: Josh Dies Date: Fri, 8 Jan 2021 06:57:53 +0300 Subject: [PATCH 01/35] add copyMessage method --- context.js | 11 +++++++++++ telegram.js | 9 +++++++++ test/telegraf.js | 2 ++ typings/telegram.d.ts | 15 +++++++++++++++ 4 files changed, 37 insertions(+) diff --git a/context.js b/context.js index 02f421079..1f2698d9b 100644 --- a/context.js +++ b/context.js @@ -590,6 +590,17 @@ class TelegrafContext { this.assert(message, 'forwardMessage') return this.telegram.forwardMessage(chatId, this.chat.id, message.message_id, extra) } + + copyMessage (chatId, extra) { + this.assert(this.message, 'copyMessage') + const message = this.message || + this.editedMessage || + this.channelPost || + this.editedChannelPost || + (this.callbackQuery && this.callbackQuery.message) + this.assert(message, 'copyMessage') + return this.telegram.copyMessage(chatId, message.chat.id, message.message_id, extra) + } } module.exports = TelegrafContext diff --git a/telegram.js b/telegram.js index 1224b766e..26a8a03fa 100644 --- a/telegram.js +++ b/telegram.js @@ -428,6 +428,15 @@ class Telegram extends ApiClient { } return this.callApi(replicators.copyMethods[type], opts) } + + copyMessage (chatId, fromChatId, messageId, extra) { + return this.callApi('copyMessage', { + chat_id: chatId, + from_chat_id: fromChatId, + message_id: messageId, + ...extra + }) + } } module.exports = Telegram diff --git a/test/telegraf.js b/test/telegraf.js index 92d894009..d7a533875 100644 --- a/test/telegraf.js +++ b/test/telegraf.js @@ -102,6 +102,7 @@ test.cb('should provide shortcuts for `message` update', (t) => { t.true('editMessageLiveLocation' in ctx) t.true('stopMessageLiveLocation' in ctx) t.true('forwardMessage' in ctx) + t.true('copyMessage' in ctx) t.end() }) bot.handleUpdate({ message: BaseTextMessage }) @@ -156,6 +157,7 @@ test.cb('should provide shortcuts for `callback_query` update', (t) => { t.true('editMessageLiveLocation' in ctx) t.true('stopMessageLiveLocation' in ctx) t.true('forwardMessage' in ctx) + t.true('copyMessage' in ctx) t.end() }) bot.handleUpdate({ callback_query: BaseTextMessage }) diff --git a/typings/telegram.d.ts b/typings/telegram.d.ts index 4d7a20699..5bd164c71 100644 --- a/typings/telegram.d.ts +++ b/typings/telegram.d.ts @@ -246,6 +246,21 @@ export declare class Telegram extends ApiClient { extra?: object ): Promise + /** + * Use this method to send copy of exists message. + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param fromChatId Unique identifier for the chat where the original message was sent (or channel username in the format @channelusername) + * @param messageId Message identifier in the chat specified in from_chat_id + * @param extra Additional params to send modified copy of message + * @returns the MessageId of the sent message on success + */ + copyMessage( + chatId: number | string, + fromChatId: number | string, + messageId: number, + extra?: object + ): 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. * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) From 52d31f82267f9a7c0438d9de4c9901cc6a5a43d2 Mon Sep 17 00:00:00 2001 From: Josh Dies Date: Fri, 8 Jan 2021 07:18:05 +0300 Subject: [PATCH 02/35] duplicate assignment --- context.js | 1 - 1 file changed, 1 deletion(-) diff --git a/context.js b/context.js index 1f2698d9b..761ec7bd7 100644 --- a/context.js +++ b/context.js @@ -592,7 +592,6 @@ class TelegrafContext { } copyMessage (chatId, extra) { - this.assert(this.message, 'copyMessage') const message = this.message || this.editedMessage || this.channelPost || From 8146103e47ada59d5fb36bc60c6dfba7589f6404 Mon Sep 17 00:00:00 2001 From: Josh Dies Date: Fri, 8 Jan 2021 07:38:36 +0300 Subject: [PATCH 03/35] add context copyMessage typings --- typings/context.d.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/typings/context.d.ts b/typings/context.d.ts index 7021badde..173453ed2 100644 --- a/typings/context.d.ts +++ b/typings/context.d.ts @@ -348,6 +348,17 @@ export declare class TelegrafContext { */ replyWithDice(extra?: tt.ExtraDice): Promise + /** + * Use this method to send copy of exists message. + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param extra Additional params to send modified copy of message + * @returns the MessageId of the sent message on success + */ + copyMessage( + chatId: number | string, + extra?: object + ): Promise + // ------------------------------------------------------------------------------------------ // // ------------------------------------------------------------------------------------------ // // ------------------------------------------------------------------------------------------ // From 1efd56666f7eeb1f3c1d844005205daa5b60ec8c Mon Sep 17 00:00:00 2001 From: Josh Dies Date: Thu, 14 Jan 2021 04:26:45 +0300 Subject: [PATCH 04/35] Bot API 5.0 - Webhooks --- docs/README.md | 10 ++++++---- telegram.js | 13 ++++--------- typings/telegram-types.d.ts | 22 ++++++++++++++++++++++ typings/telegram.d.ts | 13 ++++++------- 4 files changed, 38 insertions(+), 20 deletions(-) diff --git a/docs/README.md b/docs/README.md index 6d0af7c7a..a75e7e8b1 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1808,6 +1808,10 @@ Removes webhook integration. `telegram.deleteWebhook() => Promise` [Official documentation](https://core.telegram.org/bots/api#deletewebhook) +| Param | Type | Description | +| --- | --- | --- | +| [extra] | `object` | [Extra parameters](https://core.telegram.org/bots/api#deletewebhook) | + ##### sendAudio Sends audio. @@ -2106,15 +2110,13 @@ Use this method to upload a .png file with a sticker for later use in createNewS Specifies an url to receive incoming updates via an outgoing webhook. -`telegram.setWebhook(url, [cert], [maxConnections], [allowedUpdates]) => Promise` +`telegram.setWebhook(url, [extra]) => Promise` [Official documentation](https://core.telegram.org/bots/api#setwebhook) | Param | Type | Description | | --- | --- | --- | | url | `string` | Public url for webhook | -| [cert] | `File` | SSL public certificate | -| [maxConnections] | `number` | Maximum allowed number of simultaneous HTTPS connections to the webhook | -| [allowedUpdates] | `string[]` | List the types of updates you want your bot to receive | +| [extra] | `object` | [Extra parameters](https://core.telegram.org/bots/api#setwebhook) | ##### unbanChatMember diff --git a/telegram.js b/telegram.js index 26a8a03fa..7d723df8e 100644 --- a/telegram.js +++ b/telegram.js @@ -54,17 +54,12 @@ class Telegram extends ApiClient { }) } - setWebhook (url, certificate, maxConnections, allowedUpdates) { - return this.callApi('setWebhook', { - url, - certificate, - max_connections: maxConnections, - allowed_updates: allowedUpdates - }) + setWebhook (url, extra) { + return this.callApi('setWebhook', { url, ...extra }) } - deleteWebhook () { - return this.callApi('deleteWebhook') + deleteWebhook (extra) { + return this.callApi('deleteWebhook', extra) } sendMessage (chatId, text, extra) { diff --git a/typings/telegram-types.d.ts b/typings/telegram-types.d.ts index decfa226b..74ccc5d6b 100644 --- a/typings/telegram-types.d.ts +++ b/typings/telegram-types.d.ts @@ -207,6 +207,28 @@ export interface ChatPermissions { can_pin_messages?: boolean } +export interface ExtraSetWebhook { + /** SSL public certificate */ + certificate?: InputFile + + /** The fixed IP address which will be used to send webhook requests instead of the IP address resolved through DNS */ + ip_address?: string + + /** Maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery, 1-100. Defaults to 40. */ + max_connections?: number + + /** List the types of updates you want your bot to receive */ + allowed_updates?: UpdateType[] + + /** Pass True to drop all pending updates */ + drop_pending_updates?: boolean +} + +export interface ExtraDeleteWebhook { + /** Pass True to drop all pending updates */ + drop_pending_updates?: boolean +} + export interface ExtraRestrictChatMember { /** New user permissions */ permissions: ChatPermissions diff --git a/typings/telegram.d.ts b/typings/telegram.d.ts index 5bd164c71..8545b2904 100644 --- a/typings/telegram.d.ts +++ b/typings/telegram.d.ts @@ -601,23 +601,22 @@ export declare class Telegram extends ApiClient { /** * Use this method to specify a url and receive incoming updates via an outgoing webhook * @param url HTTPS url to send updates to. Use an empty string to remove webhook integration - * @param cert Upload your public key certificate so that the root certificate in use can be checked - * @param maxConnections Maximum allowed number of simultaneous HTTPS connections to the webhook for update delivery, 1-100 - * @param allowedUpdates List the types of updates you want your bot to receive + * @param extra Additional params to set webhook * @returns True on success */ setWebhook( url: string, - cert?: tt.InputFile, - maxConnections?: number, - allowedUpdates?: string[] + extra?: tt.ExtraSetWebhook ): Promise /** * Use this method to delete webhook + * @param extra Additional params to delete webhook * @returns True on success */ - deleteWebhook(): Promise + deleteWebhook( + extra?: tt.ExtraDeleteWebhook + ): Promise /** * Use this method to get information about set webhook From 909f33772d1d6771cdc4d8f806ba8f0f714ba2b1 Mon Sep 17 00:00:00 2001 From: Josh Dies Date: Thu, 14 Jan 2021 05:27:50 +0300 Subject: [PATCH 05/35] Bot API 5.0 - unbanChatMember --- docs/README.md | 2 +- telegram.js | 4 ++-- typings/context.d.ts | 3 ++- typings/telegram-types.d.ts | 5 +++++ typings/telegram.d.ts | 3 ++- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/docs/README.md b/docs/README.md index a75e7e8b1..455f2adde 100644 --- a/docs/README.md +++ b/docs/README.md @@ -2129,7 +2129,7 @@ Use this method to unban a previously kicked user in a supergroup. | --- | --- | --- | | chatId | `number/string` | Chat id | | userId | `number` | User id | - +| [extra] | `object` | [Extra parameters](https://core.telegram.org/bots/api#unbanchatmember) | ##### setPassportDataErrors diff --git a/telegram.js b/telegram.js index 7d723df8e..aff289459 100644 --- a/telegram.js +++ b/telegram.js @@ -234,8 +234,8 @@ class Telegram extends ApiClient { return this.callApi('leaveChat', { chat_id: chatId }) } - unbanChatMember (chatId, userId) { - return this.callApi('unbanChatMember', { chat_id: chatId, user_id: userId }) + unbanChatMember (chatId, userId, extra) { + return this.callApi('unbanChatMember', { chat_id: chatId, user_id: userId, ...extra }) } answerCbQuery (callbackQueryId, text, showAlert, extra) { diff --git a/typings/context.d.ts b/typings/context.d.ts index 173453ed2..926c6ff8d 100644 --- a/typings/context.d.ts +++ b/typings/context.d.ts @@ -471,9 +471,10 @@ export declare class TelegrafContext { /** * Use this method to unban a user from 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 * @param userId Unique identifier of the target user + * @param extra Extra params * @returns True on success */ - unbanChatMember(userId: number): Promise + unbanChatMember(userId: number, extra?: tt.ExtraUnban): 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. diff --git a/typings/telegram-types.d.ts b/typings/telegram-types.d.ts index 74ccc5d6b..823f882e4 100644 --- a/typings/telegram-types.d.ts +++ b/typings/telegram-types.d.ts @@ -570,6 +570,11 @@ export interface ExtraStopPoll { reply_markup?: TT.InlineKeyboardMarkup } +export interface ExtraUnban { + /** Do nothing if the user is not banned */ + only_if_banned?: Boolean +} + export interface IncomingMessage extends TT.Message { audio?: TT.Audio entities?: TT.MessageEntity[] diff --git a/typings/telegram.d.ts b/typings/telegram.d.ts index 8545b2904..895bf8c11 100644 --- a/typings/telegram.d.ts +++ b/typings/telegram.d.ts @@ -655,9 +655,10 @@ export declare class Telegram extends ApiClient { * Use this method to unban a user from 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 * @param chatId Unique identifier for the target group or username of the target supergroup or channel (in the format @username) * @param userId Unique identifier of the target user + * @param extra Extra params * @returns True on success */ - unbanChatMember(chatId: number | string, userId: number): Promise + unbanChatMember(chatId: number | string, userId: number, extra?: tt.ExtraUnban): 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. From 5dd9bda5f81c0cd5bb2e3d52a03a5e08ce1b49cf Mon Sep 17 00:00:00 2001 From: Josh Dies Date: Thu, 14 Jan 2021 05:47:32 +0300 Subject: [PATCH 06/35] add sendDocument params --- typings/telegram-types.d.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/typings/telegram-types.d.ts b/typings/telegram-types.d.ts index 823f882e4..8a9c39713 100644 --- a/typings/telegram-types.d.ts +++ b/typings/telegram-types.d.ts @@ -343,6 +343,21 @@ export interface ExtraDocument extends ExtraReplyMessage { * Document caption (may also be used when resending documents by file_id), 0-1024 characters */ caption?: string + + /** + * List of special entities that appear in the caption, which can be specified instead of parse_mode + */ + caption_entities?: TT.MessageEntity + + /** + * Disables automatic server-side content type detection for files uploaded using multipart/form-data + */ + disable_content_type_detection?: Boolean + + /** + * Pass True, if the message should be sent even if the specified replied-to message is not found + */ + allow_sending_without_reply?: Boolean /** * Does not exist, see https://core.telegram.org/bots/api#senddocument From e81dadbb4c55ff8483a2f0c4316101ee99701a08 Mon Sep 17 00:00:00 2001 From: Josh Dies Date: Thu, 14 Jan 2021 06:09:57 +0300 Subject: [PATCH 07/35] add param to unpinChatMessage --- docs/README.md | 1 + telegram.js | 4 ++-- typings/context.d.ts | 3 ++- typings/telegram-types.d.ts | 7 +++++++ typings/telegram.d.ts | 3 ++- 5 files changed, 14 insertions(+), 4 deletions(-) diff --git a/docs/README.md b/docs/README.md index 455f2adde..c55c52826 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1789,6 +1789,7 @@ Use this method to unpin a message in a supergroup chat. | Param | Type | Description | | --- | --- | --- | | chatId | `number/string` | Chat id | +| [extra] | `object` | [Extra parameters](https://core.telegram.org/bots/api#unpinchatmessage)| ##### leaveChat diff --git a/telegram.js b/telegram.js index aff289459..5575f4ec8 100644 --- a/telegram.js +++ b/telegram.js @@ -226,8 +226,8 @@ class Telegram extends ApiClient { return this.callApi('pinChatMessage', { chat_id: chatId, message_id: messageId, ...extra }) } - unpinChatMessage (chatId) { - return this.callApi('unpinChatMessage', { chat_id: chatId }) + unpinChatMessage (chatId, extra) { + return this.callApi('unpinChatMessage', { chat_id: chatId, ...extra }) } leaveChat (chatId) { diff --git a/typings/context.d.ts b/typings/context.d.ts index 926c6ff8d..bebf4e2c2 100644 --- a/typings/context.d.ts +++ b/typings/context.d.ts @@ -145,8 +145,9 @@ export declare class TelegrafContext { /** * Use this method to unpin a message in a group, a supergroup, or a channel. * @returns True on success + * @param extra Extra params */ - unpinChatMessage(): Promise + unpinChatMessage(extra?: tt.ExtraUnpinMessage): Promise /** * Use this method to reply on messages in the same chat. diff --git a/typings/telegram-types.d.ts b/typings/telegram-types.d.ts index 8a9c39713..917d2a84f 100644 --- a/typings/telegram-types.d.ts +++ b/typings/telegram-types.d.ts @@ -295,6 +295,13 @@ export interface ExtraEditMessage extends ExtraReplyMessage { // no specified properties } +export interface ExtraUnpinMessage { + /** + * Identifier of a message to unpin. If not specified, the most recent pinned message (by sending date) will be unpinned. + */ + message_id?: number +} + export interface ExtraAudio extends ExtraReplyMessage { /** * Audio caption, 0-1024 characters diff --git a/typings/telegram.d.ts b/typings/telegram.d.ts index 895bf8c11..3a3a2d346 100644 --- a/typings/telegram.d.ts +++ b/typings/telegram.d.ts @@ -346,9 +346,10 @@ export declare class Telegram extends ApiClient { /** * Use this method to unpin a message in a group, a supergroup, or a channel. * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param extra Extra params * @returns True on success */ - unpinChatMessage(chatId: number | string): Promise + unpinChatMessage(chatId: number | string, extra?: tt.ExtraUnpinMessage): Promise /** * Use this method to send text messages From 281bd15154253569c27fb9470872c9b481a0f147 Mon Sep 17 00:00:00 2001 From: Josh Dies Date: Thu, 14 Jan 2021 06:29:19 +0300 Subject: [PATCH 08/35] Bot API 5.0 - unpinAllChatMessages --- context.js | 5 +++++ docs/README.md | 13 +++++++++++++ telegram.js | 4 ++++ test/telegraf.js | 2 ++ typings/context.d.ts | 6 ++++++ typings/telegram.d.ts | 7 +++++++ 6 files changed, 37 insertions(+) diff --git a/context.js b/context.js index 761ec7bd7..6e4b151d9 100644 --- a/context.js +++ b/context.js @@ -380,6 +380,11 @@ class TelegrafContext { return this.telegram.unpinChatMessage(this.chat.id, ...args) } + unpinAllChatMessages () { + this.assert(this.chat, 'unpinAllChatMessages') + return this.telegram.unpinAllChatMessages(this.chat.id) + } + leaveChat (...args) { this.assert(this.chat, 'leaveChat') return this.telegram.leaveChat(this.chat.id, ...args) diff --git a/docs/README.md b/docs/README.md index c55c52826..18d817b95 100644 --- a/docs/README.md +++ b/docs/README.md @@ -280,6 +280,7 @@ Context shortcuts for **message** update: | `setStickerSetThumb` | [`telegram.setStickerSetThumb`](#setstickersetthumb) | | `stopPoll` | [`telegram.stopPoll`](#stoppoll) | | `unpinChatMessage` | [`telegram.unpinChatMessage`](#unpinchatmessage) | +| `unpinAllChatMessages` | [`telegram.unpinAllChatMessages`](#unpinallchatmessages) | | `uploadStickerFile` | [`telegram.uploadStickerFile`](#uploadstickerfile) | | `unbanChatMember` | [`telegram.unbanChatMember`](#unbanchatmember) | @@ -332,6 +333,7 @@ Context shortcuts for **callback_query** update: | `setStickerSetThumb` | [`telegram.setStickerSetThumb`](#setstickersetthumb) | | `stopPoll` | [`telegram.stopPoll`](#stoppoll) | | `unpinChatMessage` | [`telegram.unpinChatMessage`](#unpinchatmessage) | +| `unpinAllChatMessages` | [`telegram.unpinAllChatMessages`](#unpinallchatmessages) | | `uploadStickerFile` | [`telegram.uploadStickerFile`](#uploadstickerfile) | | `unbanChatMember` | [`telegram.unbanChatMember`](#unbanchatmember) | @@ -1791,6 +1793,17 @@ Use this method to unpin a message in a supergroup chat. | chatId | `number/string` | Chat id | | [extra] | `object` | [Extra parameters](https://core.telegram.org/bots/api#unpinchatmessage)| +##### unpinAllChatMessages + +Use this method to clear the list of pinned messages in a chat + +`telegram.unpinAllChatMessages(chatId) => Promise` +[Official documentation](https://core.telegram.org/bots/api#unpinallchatmessages) + +| Param | Type | Description | +| --- | --- | --- | +| chatId | `number/string` | Chat id | + ##### leaveChat Use this method for your bot to leave a group, supergroup or channel. diff --git a/telegram.js b/telegram.js index 5575f4ec8..3d282ba13 100644 --- a/telegram.js +++ b/telegram.js @@ -230,6 +230,10 @@ class Telegram extends ApiClient { return this.callApi('unpinChatMessage', { chat_id: chatId, ...extra }) } + unpinAllChatMessages (chatId) { + return this.callApi('unpinAllChatMessages', { chat_id: chatId }) + } + leaveChat (chatId) { return this.callApi('leaveChat', { chat_id: chatId }) } diff --git a/test/telegraf.js b/test/telegraf.js index d7a533875..f48e7e944 100644 --- a/test/telegraf.js +++ b/test/telegraf.js @@ -86,6 +86,7 @@ test.cb('should provide shortcuts for `message` update', (t) => { t.true('setChatDescription' in ctx) t.true('pinChatMessage' in ctx) t.true('unpinChatMessage' in ctx) + t.true('unpinAllChatMessages' in ctx) t.true('leaveChat' in ctx) t.true('getChatAdministrators' in ctx) t.true('getChatMember' in ctx) @@ -142,6 +143,7 @@ test.cb('should provide shortcuts for `callback_query` update', (t) => { t.true('setChatDescription' in ctx) t.true('pinChatMessage' in ctx) t.true('unpinChatMessage' in ctx) + t.true('unpinAllChatMessages' in ctx) t.true('leaveChat' in ctx) t.true('getChatAdministrators' in ctx) t.true('getChatMember' in ctx) diff --git a/typings/context.d.ts b/typings/context.d.ts index bebf4e2c2..d53bf6d30 100644 --- a/typings/context.d.ts +++ b/typings/context.d.ts @@ -149,6 +149,12 @@ export declare class TelegrafContext { */ unpinChatMessage(extra?: tt.ExtraUnpinMessage): Promise + /** + * Use this method to clear the list of pinned messages in a chat + * @returns True on success + */ + unpinAllChatMessages(): Promise + /** * Use this method to reply on messages in the same chat. * @param text Text of the message to be sent diff --git a/typings/telegram.d.ts b/typings/telegram.d.ts index 3a3a2d346..d613cf7b0 100644 --- a/typings/telegram.d.ts +++ b/typings/telegram.d.ts @@ -351,6 +351,13 @@ export declare class Telegram extends ApiClient { */ unpinChatMessage(chatId: number | string, extra?: tt.ExtraUnpinMessage): Promise + /** + * Use this method to clear the list of pinned messages in a chat + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @returns True on success + */ + unpinAllChatMessages(chatId: number | string): Promise + /** * Use this method to send text messages * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) From b6cacbb7477aab7a3c7f90e88e6f3d4d65b42c7f Mon Sep 17 00:00:00 2001 From: Josh Dies Date: Thu, 14 Jan 2021 12:07:37 +0300 Subject: [PATCH 09/35] correct params in sendMediaGroup --- typings/telegram-types.d.ts | 5 +++++ typings/telegram.d.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/typings/telegram-types.d.ts b/typings/telegram-types.d.ts index 917d2a84f..d8bbc4a49 100644 --- a/typings/telegram-types.d.ts +++ b/typings/telegram-types.d.ts @@ -450,6 +450,11 @@ export interface ExtraMediaGroup extends ExtraReplyMessage { * Does not exist, see https://core.telegram.org/bots/api#sendmediagroup */ reply_markup?: never + + /** + * Pass True, if the message should be sent even if the specified replied-to message is not found + */ + allow_sending_without_reply?: Boolean } export interface ExtraAnimation extends ExtraReplyMessage { diff --git a/typings/telegram.d.ts b/typings/telegram.d.ts index d613cf7b0..ec8ff3b8b 100644 --- a/typings/telegram.d.ts +++ b/typings/telegram.d.ts @@ -482,7 +482,7 @@ export declare class Telegram extends ApiClient { */ sendMediaGroup( chatId: number | string, - media: tt.MessageMedia[], + media: (tt.InputMediaAudio | tt.InputMediaDocument | tt.InputMediaPhoto | tt.InputMediaVideo)[], extra?: tt.ExtraMediaGroup ): Promise> From 1389203aad195ea2d4ab2133a5e81e8117d4b774 Mon Sep 17 00:00:00 2001 From: Josh Dies Date: Thu, 14 Jan 2021 15:18:30 +0300 Subject: [PATCH 10/35] correct params in sendLocation --- typings/telegram-types.d.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/typings/telegram-types.d.ts b/typings/telegram-types.d.ts index d8bbc4a49..a8dbfa997 100644 --- a/typings/telegram-types.d.ts +++ b/typings/telegram-types.d.ts @@ -407,11 +407,31 @@ export interface ExtraInvoice extends ExtraReplyMessage { } export interface ExtraLocation extends ExtraReplyMessage { + /** + * The radius of uncertainty for the location, measured in meters; 0-1500 + */ + horizontal_accuracy?: number + /** * Period in seconds for which the location will be updated (should be between 60 and 86400) */ live_period?: number + /** + * For live locations, a direction in which the user is moving, in degrees. Must be between 1 and 360 if specified. + */ + heading?: number + + /** + * For live locations, a maximum distance for proximity alerts about approaching another chat member, in meters. Must be between 1 and 100000 if specified. + */ + proximity_alert_radius?: number + + /** + * Pass True, if the message should be sent even if the specified replied-to message is not found + */ + allow_sending_without_reply?: boolean + /** * Does not exist, see https://core.telegram.org/bots/api#sendlocation */ From beab76e64c105fa4169db3b050de98560451d344 Mon Sep 17 00:00:00 2001 From: Loskir Date: Thu, 14 Jan 2021 15:37:53 +0300 Subject: [PATCH 11/35] Use typegram instead of telegram-typings --- package.json | 2 +- typings/telegram-types.d.ts | 91 +++++++------------------------------ 2 files changed, 18 insertions(+), 75 deletions(-) diff --git a/package.json b/package.json index bee6b14da..5bd7f1271 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "module-alias": "^2.2.2", "node-fetch": "^2.2.0", "sandwich-stream": "^2.0.1", - "telegram-typings": "^3.6.0" + "typegram": "^3.1.5" }, "devDependencies": { "@types/node": "^13.1.0", diff --git a/typings/telegram-types.d.ts b/typings/telegram-types.d.ts index d8bbc4a49..b13ddae13 100644 --- a/typings/telegram-types.d.ts +++ b/typings/telegram-types.d.ts @@ -1,5 +1,4 @@ -import * as TT from "telegram-typings"; -export * from "telegram-typings"; +import * as TT from 'typegram' export type ParseMode = 'Markdown' | 'MarkdownV2' | 'HTML' @@ -350,7 +349,7 @@ export interface ExtraDocument extends ExtraReplyMessage { * Document caption (may also be used when resending documents by file_id), 0-1024 characters */ caption?: string - + /** * List of special entities that appear in the caption, which can be specified instead of parse_mode */ @@ -602,77 +601,21 @@ export interface ExtraUnban { only_if_banned?: Boolean } -export interface IncomingMessage extends TT.Message { - audio?: TT.Audio - entities?: TT.MessageEntity[] - caption?: string - document?: TT.Document - game?: TT.Game - photo?: TT.PhotoSize[] - animation?: TT.Animation - sticker?: TT.Sticker - video?: TT.Video - video_note?: TT.VideoNote - contact?: TT.Contact - location?: TT.Location - venue?: TT.Venue - pinned_message?: TT.Message - invoice?: TT.Invoice - successful_payment?: TT.SuccessfulPayment - dice?: Dice -} - -export interface MessageAudio extends TT.Message { - audio: TT.Audio -} - -export interface MessageDocument extends TT.Message { - document: TT.Document -} - -export interface MessageGame extends TT.Message { - game: TT.Game -} - -export interface MessageInvoice extends TT.Message { - invoice: TT.Invoice -} - -export interface MessageLocation extends TT.Message { - location: TT.Location -} - -export interface MessagePhoto extends TT.Message { - photo: TT.PhotoSize[] -} - -export interface MessageAnimation extends TT.Message { - animation: TT.Animation -} - -export interface MessageSticker extends TT.Message { - sticker: TT.Sticker -} - -export interface MessageVideo extends TT.Message { - video: TT.Video -} - -export interface MessageVideoNote extends TT.Message { - video_note: TT.VideoNote -} - -export interface MessageVoice extends TT.Message { - voice: TT.Voice -} - -export interface MessageDice extends TT.Message { - dice: Dice -} - -export interface MessagePoll extends TT.Message { - poll: Poll -} +export type IncomingMessage = TT.Message + +export type MessageAudio = TT.Message.AudioMessage +export type MessageDocument = TT.Message.DocumentMessage +export type MessageGame = TT.Message.GameMessage +export type MessageInvoice = TT.Message.InvoiceMessage +export type MessageLocation = TT.Message.LocationMessage +export type MessagePhoto = TT.Message.PhotoMessage +export type MessageAnimation = TT.Message.AnimationMessage +export type MessageSticker = TT.Message.StickerMessage +export type MessageVideo = TT.Message.VideoMessage +export type MessageVideoNote = TT.Message.VideoNoteMessage +export type MessageVoice = TT.Message.VoiceMessage +export type MessageDice = TT.Message.DiceMessage +export type MessagePoll = TT.Message.PollMessage export interface NewInvoiceParameters { /** From f46b2d90af7cae2e985370b7a9b653fba7ceca41 Mon Sep 17 00:00:00 2001 From: Loskir Date: Thu, 14 Jan 2021 15:43:22 +0300 Subject: [PATCH 12/35] Fix: add reexport --- typings/telegram-types.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/typings/telegram-types.d.ts b/typings/telegram-types.d.ts index b13ddae13..bfd172d0f 100644 --- a/typings/telegram-types.d.ts +++ b/typings/telegram-types.d.ts @@ -1,4 +1,5 @@ import * as TT from 'typegram' +export * from 'typegram' export type ParseMode = 'Markdown' | 'MarkdownV2' | 'HTML' From 611b91da2b74b446cb7afe85131411791ca8f28a Mon Sep 17 00:00:00 2001 From: Loskir Date: Thu, 14 Jan 2021 15:46:13 +0300 Subject: [PATCH 13/35] Fix JSDoc for promoteChatMember --- typings/telegram.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/typings/telegram.d.ts b/typings/telegram.d.ts index ec8ff3b8b..4e457642d 100644 --- a/typings/telegram.d.ts +++ b/typings/telegram.d.ts @@ -672,6 +672,7 @@ export declare class Telegram extends ApiClient { * 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. * @param chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) * @param userId Unique identifier of the target user + * @param extra Extra parameters for promoteChatMember * @returns True on success */ promoteChatMember( From 0810733a070778cd66b690142b0cd4cc22ab46cb Mon Sep 17 00:00:00 2001 From: Josh Dies Date: Thu, 14 Jan 2021 16:05:53 +0300 Subject: [PATCH 14/35] missing space --- typings/test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typings/test.ts b/typings/test.ts index 6eb0d387c..47917b5e6 100644 --- a/typings/test.ts +++ b/typings/test.ts @@ -108,7 +108,7 @@ bot.hears('something', async (ctx) => { reply_markup: Markup.inlineKeyboard([]) }) - ctx.editMessageLiveLocation(90,90, { + ctx.editMessageLiveLocation(90, 90, { reply_markup: Markup.inlineKeyboard([]) }) From 498308e177b8543745504d8216721ab7629f7e41 Mon Sep 17 00:00:00 2001 From: Josh Dies Date: Thu, 14 Jan 2021 16:52:31 +0300 Subject: [PATCH 15/35] correct params in editMessageLiveLocation --- context.js | 8 +++++--- docs/README.md | 1 + telegram.js | 5 +++-- typings/context.d.ts | 15 +++++++++------ typings/telegram-types.d.ts | 7 +++++++ typings/telegram.d.ts | 21 +++++++++++++++++++++ 6 files changed, 46 insertions(+), 11 deletions(-) diff --git a/context.js b/context.js index 6e4b151d9..f374ab9b1 100644 --- a/context.js +++ b/context.js @@ -272,7 +272,7 @@ class TelegrafContext { ) } - editMessageLiveLocation (latitude, longitude, markup) { + editMessageLiveLocation (latitude, longitude, markup, extra) { this.assert(this.callbackQuery || this.inlineMessageId, 'editMessageLiveLocation') return this.inlineMessageId ? this.telegram.editMessageLiveLocation( @@ -281,7 +281,8 @@ class TelegrafContext { undefined, undefined, this.inlineMessageId, - markup + markup, + extra ) : this.telegram.editMessageLiveLocation( latitude, @@ -289,7 +290,8 @@ class TelegrafContext { this.chat.id, this.callbackQuery.message.message_id, undefined, - markup + markup, + extra ) } diff --git a/docs/README.md b/docs/README.md index 18d817b95..ef2e0c539 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1442,6 +1442,7 @@ Use this method to edit live location messages sent by the bot or via the bot. | messageId | `string` | Message id | | inlineMessageId | `string` | Inline message id | | [markup] | `object` | Keyboard markup | +| [extra] | `object` | [Extra parameters](https://core.telegram.org/bots/api#editmessagelivelocation)| ##### editMessageReplyMarkup diff --git a/telegram.js b/telegram.js index 3d282ba13..dbf3cea37 100644 --- a/telegram.js +++ b/telegram.js @@ -315,14 +315,15 @@ class Telegram extends ApiClient { }) } - editMessageLiveLocation (latitude, longitude, chatId, messageId, inlineMessageId, markup) { + editMessageLiveLocation (latitude, longitude, chatId, messageId, inlineMessageId, markup, extra = {}) { return this.callApi('editMessageLiveLocation', { latitude, longitude, chat_id: chatId, message_id: messageId, inline_message_id: inlineMessageId, - reply_markup: markup + reply_markup: markup, + ...extra }) } diff --git a/typings/context.d.ts b/typings/context.d.ts index d53bf6d30..b9897946f 100644 --- a/typings/context.d.ts +++ b/typings/context.d.ts @@ -456,15 +456,18 @@ export declare class TelegrafContext { ): Promise /** - * Use this method to edit live location messages. + * Use this method to edit live location messages * @returns On success, if the edited message was sent by the bot, the edited message is returned, otherwise True is returned. - * @param lat New latitude - * @param lon New longitude + * @param latitude New latitude + * @param longitude New longitude + * @param markup Markup of inline keyboard + * @param extra Extra params */ editMessageLiveLocation( - lat: number, - lon: number, - extra?: tt.ExtraLocation + latitude: number, + longitude: number, + markup: tt.InlineKeyboardMarkup, + extra?: tt.ExtraEditLocation ): Promise /** diff --git a/typings/telegram-types.d.ts b/typings/telegram-types.d.ts index a8dbfa997..45761bd42 100644 --- a/typings/telegram-types.d.ts +++ b/typings/telegram-types.d.ts @@ -443,6 +443,13 @@ export interface ExtraLocation extends ExtraReplyMessage { parse_mode?: never } +export interface ExtraEditLocation extends ExtraLocation { + /** + * Does not exist, see https://core.telegram.org/bots/api#sendlocation + */ + live_period?: never +} + export interface ExtraPhoto extends ExtraReplyMessage { /** * Photo caption (may also be used when resending photos by file_id), 0-1024 characters diff --git a/typings/telegram.d.ts b/typings/telegram.d.ts index ec8ff3b8b..3ee7bf674 100644 --- a/typings/telegram.d.ts +++ b/typings/telegram.d.ts @@ -156,6 +156,27 @@ export declare class Telegram extends ApiClient { markup?: string ): Promise + /** + * Use this method to edit live location messages + * @param latitude Latitude of location + * @param longitude Longitude of location + * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) + * @param messageId Required if inlineMessageId is not specified. Identifier of the sent message + * @param inlineMessageId Required if chatId and messageId are not specified. Identifier of the inline message + * @param markup Markup of inline keyboard + * @param extra Extra params + * @returns On success, if the edited message is not an inline message, the edited Message is returned, otherwise True is returned. + */ + editMessageLiveLocation( + latitude: number, + longitude: number, + chatId: number | string | void, + messageId: number, + inlineMessageId: string | void, + markup: tt.InlineKeyboardMarkup, + extra?: tt.ExtraLocation + ): Promise + /** * Use this method to delete a message, including service messages, with the following limitations: * - A message can only be deleted if it was sent less than 48 hours ago. From c88c326833a7814f8b3acbbc1da50197e1e1a989 Mon Sep 17 00:00:00 2001 From: Loskir Date: Thu, 14 Jan 2021 17:08:17 +0300 Subject: [PATCH 16/35] Remove IncomingMessage --- typings/context.d.ts | 2 +- typings/telegram-types.d.ts | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/typings/context.d.ts b/typings/context.d.ts index d53bf6d30..9a4ce9464 100644 --- a/typings/context.d.ts +++ b/typings/context.d.ts @@ -21,7 +21,7 @@ export declare class TelegrafContext { inlineQuery?: tt.InlineQuery match?: RegExpExecArray | null me?: string - message?: tt.IncomingMessage + message?: tt.Message poll?: tt.Poll pollAnswer?: tt.PollAnswer preCheckoutQuery?: tt.PreCheckoutQuery diff --git a/typings/telegram-types.d.ts b/typings/telegram-types.d.ts index bfd172d0f..691cb9ab9 100644 --- a/typings/telegram-types.d.ts +++ b/typings/telegram-types.d.ts @@ -602,8 +602,6 @@ export interface ExtraUnban { only_if_banned?: Boolean } -export type IncomingMessage = TT.Message - export type MessageAudio = TT.Message.AudioMessage export type MessageDocument = TT.Message.DocumentMessage export type MessageGame = TT.Message.GameMessage From 3b320a95af843f53204112bcc983b2293b3a2e59 Mon Sep 17 00:00:00 2001 From: Loskir Date: Thu, 14 Jan 2021 17:14:51 +0300 Subject: [PATCH 17/35] Add emoji param to ExtraDice --- typings/telegram-types.d.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/typings/telegram-types.d.ts b/typings/telegram-types.d.ts index e1449738c..af914ec8f 100644 --- a/typings/telegram-types.d.ts +++ b/typings/telegram-types.d.ts @@ -421,12 +421,12 @@ export interface ExtraLocation extends ExtraReplyMessage { * For live locations, a direction in which the user is moving, in degrees. Must be between 1 and 360 if specified. */ heading?: number - + /** * For live locations, a maximum distance for proximity alerts about approaching another chat member, in meters. Must be between 1 and 100000 if specified. */ proximity_alert_radius?: number - + /** * Pass True, if the message should be sent even if the specified replied-to message is not found */ @@ -581,6 +581,14 @@ export interface ExtraVoice extends ExtraReplyMessage { } export interface ExtraDice extends ExtraReplyMessage { + /** + * Emoji on which the dice throw animation is based. + * Currently, must be one of β€œπŸŽ²β€, β€œπŸŽ―β€, β€œπŸ€β€, β€œβš½β€, or β€œπŸŽ°β€. + * Dice can have values 1-6 for β€œπŸŽ²β€ and β€œπŸŽ―β€, values 1-5 for β€œπŸ€β€ and β€œβš½β€, and values 1-64 for β€œπŸŽ°β€. + * Defaults to β€œπŸŽ²β€ + * */ + emoji?: string + /** * Does not exist, see https://core.telegram.org/bots/api#senddice */ From b32ea344e44adbd9e7de4c506bb689fd4b42d024 Mon Sep 17 00:00:00 2001 From: Josh Dies Date: Thu, 14 Jan 2021 17:51:00 +0300 Subject: [PATCH 18/35] its ok ...undefined --- telegram.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telegram.js b/telegram.js index dbf3cea37..8b817e7c4 100644 --- a/telegram.js +++ b/telegram.js @@ -315,7 +315,7 @@ class Telegram extends ApiClient { }) } - editMessageLiveLocation (latitude, longitude, chatId, messageId, inlineMessageId, markup, extra = {}) { + editMessageLiveLocation (latitude, longitude, chatId, messageId, inlineMessageId, markup, extra) { return this.callApi('editMessageLiveLocation', { latitude, longitude, From b7f2852aa4f440fe999862b41f582136ad189ed7 Mon Sep 17 00:00:00 2001 From: Josh Dies Date: Thu, 14 Jan 2021 18:02:16 +0300 Subject: [PATCH 19/35] correct params in promoteChatMember --- typings/context.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typings/context.d.ts b/typings/context.d.ts index 1986b33e2..2c254f525 100644 --- a/typings/context.d.ts +++ b/typings/context.d.ts @@ -488,8 +488,8 @@ export declare class TelegrafContext { /** * 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. - * @param chatId Unique identifier for the target chat or username of the target channel (in the format `@channelusername`) * @param userId Unique identifier of the target user + * @param extra Extra parameters for promoteChatMember * @returns True on success */ promoteChatMember( From 6fd65b7161a8790dd40ef61046aaed94d384d1cb Mon Sep 17 00:00:00 2001 From: Loskir Date: Thu, 14 Jan 2021 17:16:41 +0300 Subject: [PATCH 20/35] Change max poll question length to 300 --- typings/telegram.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typings/telegram.d.ts b/typings/telegram.d.ts index beae98499..62b796578 100644 --- a/typings/telegram.d.ts +++ b/typings/telegram.d.ts @@ -510,7 +510,7 @@ export declare class Telegram extends ApiClient { /** * Use this method to send a native poll. * @param chatId Unique identifier for the target chat or username of the target channel (in the format @channelusername) - * @param question Poll question, 1-255 characters + * @param question Poll question, 1-300 characters * @param options A JSON-serialized list of answer options, 2-10 strings 1-100 characters each * @param extra Additional params to send poll * @returns On success, the sent Message is returned. From fc86259cd139eeb386df2a91c75e03f2ee758a82 Mon Sep 17 00:00:00 2001 From: Loskir Date: Thu, 14 Jan 2021 18:44:05 +0300 Subject: [PATCH 21/35] Fix test for sendVideoNote --- typings/test.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/typings/test.ts b/typings/test.ts index 47917b5e6..66bd503af 100644 --- a/typings/test.ts +++ b/typings/test.ts @@ -166,9 +166,7 @@ bot.hears('something', async (ctx) => { duration: 0, length: 0, thumb: '', - parse_mode: "HTML", disable_notification: false, - disable_web_page_preview: false, reply_markup: Markup.inlineKeyboard([]), reply_to_message_id: 0, }) From 22d4e5d496502b64310374ef2211dfe3c23ec16c Mon Sep 17 00:00:00 2001 From: Loskir Date: Thu, 14 Jan 2021 18:44:23 +0300 Subject: [PATCH 22/35] Fix test for editMessageLiveLocation --- typings/test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/typings/test.ts b/typings/test.ts index 66bd503af..51e296344 100644 --- a/typings/test.ts +++ b/typings/test.ts @@ -108,8 +108,8 @@ bot.hears('something', async (ctx) => { reply_markup: Markup.inlineKeyboard([]) }) - ctx.editMessageLiveLocation(90, 90, { - reply_markup: Markup.inlineKeyboard([]) + ctx.editMessageLiveLocation(90, 90, Markup.inlineKeyboard([]), { + heading: 1 }) ctx.stopMessageLiveLocation({ From b1286d9f134820da431d26e7bfe524424e6f53ea Mon Sep 17 00:00:00 2001 From: Josh Dies Date: Thu, 14 Jan 2021 18:18:08 +0300 Subject: [PATCH 23/35] add copyMessage method --- docs/README.md | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index ef2e0c539..f76c9ae5f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1485,7 +1485,6 @@ Forwards message. | messageId | `number` | Message id | | [extra] | `object` | [Extra parameters](https://core.telegram.org/bots/api#forwardmessage)| - ##### sendCopy Sends message copy. @@ -1498,6 +1497,19 @@ Sends message copy. | message | `object` | Message | | [extra] | `object` | [Extra parameters](https://core.telegram.org/bots/api#sendmessage)| +##### copyMessage + +Use this method to copy messages of any kind. + +`telegram.copyMessage(chatId, message, [extra]) => Promise` + +| Param | Type | Description | +| --- | --- | --- | +| chatId | `number/string` | Target Chat id | +| fromChatId | `number/string` | Source Chat id | +| messageId | `number` | Message id | +| [extra] | `object` | [Extra parameters](https://core.telegram.org/bots/api#copymessage)| + ##### getWebhookInfo Use this method to get current webhook status. Requires no parameters. On success, returns a WebhookInfo object. If the bot is using getUpdates, will return an object with the url field empty. From ef7b1efba61dbdfbe3f3dcddf82d4fd5bf1a8574 Mon Sep 17 00:00:00 2001 From: Josh Dies Date: Thu, 14 Jan 2021 18:46:08 +0300 Subject: [PATCH 24/35] =?UTF-8?q?convert=20sendCopy=20to=20proxy=20method?= =?UTF-8?q?=20=F0=9F=98=A5=20bb=20replicators?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/replicators.js | 140 -------------------------------------------- telegram.js | 14 +---- 2 files changed, 2 insertions(+), 152 deletions(-) delete mode 100644 core/replicators.js diff --git a/core/replicators.js b/core/replicators.js deleted file mode 100644 index 1d93758e2..000000000 --- a/core/replicators.js +++ /dev/null @@ -1,140 +0,0 @@ -const { formatHTML } = require('../markup') - -module.exports = { - copyMethods: { - audio: 'sendAudio', - contact: 'sendContact', - document: 'sendDocument', - location: 'sendLocation', - photo: 'sendPhoto', - sticker: 'sendSticker', - text: 'sendMessage', - venue: 'sendVenue', - video: 'sendVideo', - video_note: 'sendVideoNote', - animation: 'sendAnimation', - voice: 'sendVoice', - poll: 'sendPoll' - }, - text: (message) => { - const entities = message.entities || [] - return { - reply_markup: message.reply_markup, - parse_mode: entities.length > 0 ? 'HTML' : '', - text: formatHTML(message.text, entities) - } - }, - contact: (message) => { - return { - reply_markup: message.reply_markup, - phone_number: message.contact.phone_number, - first_name: message.contact.first_name, - last_name: message.contact.last_name - } - }, - location: (message) => { - return { - reply_markup: message.reply_markup, - latitude: message.location.latitude, - longitude: message.location.longitude - } - }, - venue: (message) => { - return { - reply_markup: message.reply_markup, - latitude: message.venue.location.latitude, - longitude: message.venue.location.longitude, - title: message.venue.title, - address: message.venue.address, - foursquare_id: message.venue.foursquare_id - } - }, - voice: (message) => { - const entities = message.caption_entities || [] - return { - reply_markup: message.reply_markup, - voice: message.voice.file_id, - duration: message.voice.duration, - caption: formatHTML(message.caption, entities), - parse_mode: entities.length > 0 ? 'HTML' : '' - } - }, - audio: (message) => { - const entities = message.caption_entities || [] - return { - reply_markup: message.reply_markup, - audio: message.audio.file_id, - thumb: message.audio.thumb, - duration: message.audio.duration, - performer: message.audio.performer, - title: message.audio.title, - caption: formatHTML(message.caption, entities), - parse_mode: entities.length > 0 ? 'HTML' : '' - } - }, - video: (message) => { - const entities = message.caption_entities || [] - return { - reply_markup: message.reply_markup, - video: message.video.file_id, - thumb: message.video.thumb, - caption: formatHTML(message.caption, entities), - parse_mode: entities.length > 0 ? 'HTML' : '', - duration: message.video.duration, - width: message.video.width, - height: message.video.height, - supports_streaming: !!message.video.supports_streaming - } - }, - document: (message) => { - const entities = message.caption_entities || [] - return { - reply_markup: message.reply_markup, - document: message.document.file_id, - caption: formatHTML(message.caption, entities), - parse_mode: entities.length > 0 ? 'HTML' : '' - } - }, - sticker: (message) => { - return { - reply_markup: message.reply_markup, - sticker: message.sticker.file_id - } - }, - photo: (message) => { - const entities = message.caption_entities || [] - return { - reply_markup: message.reply_markup, - photo: message.photo[message.photo.length - 1].file_id, - parse_mode: entities.length > 0 ? 'HTML' : '', - caption: formatHTML(message.caption, entities) - } - }, - video_note: (message) => { - return { - reply_markup: message.reply_markup, - video_note: message.video_note.file_id, - thumb: message.video_note.thumb, - length: message.video_note.length, - duration: message.video_note.duration - } - }, - animation: (message) => { - return { - reply_markup: message.reply_markup, - animation: message.animation.file_id, - thumb: message.animation.thumb, - duration: message.animation.duration - } - }, - poll: (message) => { - return { - question: message.poll.question, - type: message.poll.type, - is_anonymous: message.poll.is_anonymous, - allows_multiple_answers: message.poll.allows_multiple_answers, - correct_option_id: message.poll.correct_option_id, - options: message.poll.options.map(({ text }) => text) - } - } -} diff --git a/telegram.js b/telegram.js index 8b817e7c4..a3e7cbda3 100644 --- a/telegram.js +++ b/telegram.js @@ -1,4 +1,3 @@ -const replicators = require('./core/replicators') const ApiClient = require('./core/network/client') class Telegram extends ApiClient { @@ -414,19 +413,10 @@ class Telegram extends ApiClient { } sendCopy (chatId, message, extra) { - if (!message) { + if (!message || !message.chat || !message.chat.id || message.message_id) { throw new Error('Message is required') } - const type = Object.keys(replicators.copyMethods).find((type) => message[type]) - if (!type) { - throw new Error('Unsupported message type') - } - const opts = { - chat_id: chatId, - ...replicators[type](message), - ...extra - } - return this.callApi(replicators.copyMethods[type], opts) + return this.copyMessage(chatId, message.chat.id, message.message_id, extra) } copyMessage (chatId, fromChatId, messageId, extra) { From d9e189ea55b500f5be1b2c4a59a24581b473e869 Mon Sep 17 00:00:00 2001 From: Josh Dies Date: Thu, 14 Jan 2021 19:02:21 +0300 Subject: [PATCH 25/35] =?UTF-8?q?Revert=20"convert=20sendCopy=20to=20proxy?= =?UTF-8?q?=20method=20=F0=9F=98=A5=20bb=20replicators"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit ef7b1efba61dbdfbe3f3dcddf82d4fd5bf1a8574. --- core/replicators.js | 140 ++++++++++++++++++++++++++++++++++++++++++++ telegram.js | 14 ++++- 2 files changed, 152 insertions(+), 2 deletions(-) create mode 100644 core/replicators.js diff --git a/core/replicators.js b/core/replicators.js new file mode 100644 index 000000000..1d93758e2 --- /dev/null +++ b/core/replicators.js @@ -0,0 +1,140 @@ +const { formatHTML } = require('../markup') + +module.exports = { + copyMethods: { + audio: 'sendAudio', + contact: 'sendContact', + document: 'sendDocument', + location: 'sendLocation', + photo: 'sendPhoto', + sticker: 'sendSticker', + text: 'sendMessage', + venue: 'sendVenue', + video: 'sendVideo', + video_note: 'sendVideoNote', + animation: 'sendAnimation', + voice: 'sendVoice', + poll: 'sendPoll' + }, + text: (message) => { + const entities = message.entities || [] + return { + reply_markup: message.reply_markup, + parse_mode: entities.length > 0 ? 'HTML' : '', + text: formatHTML(message.text, entities) + } + }, + contact: (message) => { + return { + reply_markup: message.reply_markup, + phone_number: message.contact.phone_number, + first_name: message.contact.first_name, + last_name: message.contact.last_name + } + }, + location: (message) => { + return { + reply_markup: message.reply_markup, + latitude: message.location.latitude, + longitude: message.location.longitude + } + }, + venue: (message) => { + return { + reply_markup: message.reply_markup, + latitude: message.venue.location.latitude, + longitude: message.venue.location.longitude, + title: message.venue.title, + address: message.venue.address, + foursquare_id: message.venue.foursquare_id + } + }, + voice: (message) => { + const entities = message.caption_entities || [] + return { + reply_markup: message.reply_markup, + voice: message.voice.file_id, + duration: message.voice.duration, + caption: formatHTML(message.caption, entities), + parse_mode: entities.length > 0 ? 'HTML' : '' + } + }, + audio: (message) => { + const entities = message.caption_entities || [] + return { + reply_markup: message.reply_markup, + audio: message.audio.file_id, + thumb: message.audio.thumb, + duration: message.audio.duration, + performer: message.audio.performer, + title: message.audio.title, + caption: formatHTML(message.caption, entities), + parse_mode: entities.length > 0 ? 'HTML' : '' + } + }, + video: (message) => { + const entities = message.caption_entities || [] + return { + reply_markup: message.reply_markup, + video: message.video.file_id, + thumb: message.video.thumb, + caption: formatHTML(message.caption, entities), + parse_mode: entities.length > 0 ? 'HTML' : '', + duration: message.video.duration, + width: message.video.width, + height: message.video.height, + supports_streaming: !!message.video.supports_streaming + } + }, + document: (message) => { + const entities = message.caption_entities || [] + return { + reply_markup: message.reply_markup, + document: message.document.file_id, + caption: formatHTML(message.caption, entities), + parse_mode: entities.length > 0 ? 'HTML' : '' + } + }, + sticker: (message) => { + return { + reply_markup: message.reply_markup, + sticker: message.sticker.file_id + } + }, + photo: (message) => { + const entities = message.caption_entities || [] + return { + reply_markup: message.reply_markup, + photo: message.photo[message.photo.length - 1].file_id, + parse_mode: entities.length > 0 ? 'HTML' : '', + caption: formatHTML(message.caption, entities) + } + }, + video_note: (message) => { + return { + reply_markup: message.reply_markup, + video_note: message.video_note.file_id, + thumb: message.video_note.thumb, + length: message.video_note.length, + duration: message.video_note.duration + } + }, + animation: (message) => { + return { + reply_markup: message.reply_markup, + animation: message.animation.file_id, + thumb: message.animation.thumb, + duration: message.animation.duration + } + }, + poll: (message) => { + return { + question: message.poll.question, + type: message.poll.type, + is_anonymous: message.poll.is_anonymous, + allows_multiple_answers: message.poll.allows_multiple_answers, + correct_option_id: message.poll.correct_option_id, + options: message.poll.options.map(({ text }) => text) + } + } +} diff --git a/telegram.js b/telegram.js index a3e7cbda3..8b817e7c4 100644 --- a/telegram.js +++ b/telegram.js @@ -1,3 +1,4 @@ +const replicators = require('./core/replicators') const ApiClient = require('./core/network/client') class Telegram extends ApiClient { @@ -413,10 +414,19 @@ class Telegram extends ApiClient { } sendCopy (chatId, message, extra) { - if (!message || !message.chat || !message.chat.id || message.message_id) { + if (!message) { throw new Error('Message is required') } - return this.copyMessage(chatId, message.chat.id, message.message_id, extra) + const type = Object.keys(replicators.copyMethods).find((type) => message[type]) + if (!type) { + throw new Error('Unsupported message type') + } + const opts = { + chat_id: chatId, + ...replicators[type](message), + ...extra + } + return this.callApi(replicators.copyMethods[type], opts) } copyMessage (chatId, fromChatId, messageId, extra) { From 86196a18f477c67c6f0286eb264ebd9b2262ba2b Mon Sep 17 00:00:00 2001 From: Josh Dies Date: Thu, 14 Jan 2021 19:12:55 +0300 Subject: [PATCH 26/35] sendCopy via proxy method --- telegram.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/telegram.js b/telegram.js index 8b817e7c4..13a6749f9 100644 --- a/telegram.js +++ b/telegram.js @@ -417,6 +417,9 @@ class Telegram extends ApiClient { if (!message) { throw new Error('Message is required') } + if (message.chat && message.chat.id && message.message_id) { + return this.copyMessage(chatId, message.chat.id, message.message_id, extra) + } const type = Object.keys(replicators.copyMethods).find((type) => message[type]) if (!type) { throw new Error('Unsupported message type') From c2c3174a2919c3c514891f59e77adccb37eb20b1 Mon Sep 17 00:00:00 2001 From: Loskir Date: Thu, 14 Jan 2021 18:48:13 +0300 Subject: [PATCH 27/35] Update typings for Extra --- typings/composer.d.ts | 2 +- typings/context.d.ts | 6 +- typings/extra.d.ts | 4 +- typings/markup.d.ts | 2 +- typings/telegram-types.d.ts | 313 +++++++++--------------------------- 5 files changed, 81 insertions(+), 246 deletions(-) diff --git a/typings/composer.d.ts b/typings/composer.d.ts index 9212add6e..a0438b15a 100644 --- a/typings/composer.d.ts +++ b/typings/composer.d.ts @@ -169,7 +169,7 @@ export declare class Composer static reply( text: string, - extra?: tt.ExtraReplyMessage + extra?: tt.ExtraSendMessage ): MiddlewareFn /** diff --git a/typings/context.d.ts b/typings/context.d.ts index 2c254f525..e2ec6470d 100644 --- a/typings/context.d.ts +++ b/typings/context.d.ts @@ -161,7 +161,7 @@ export declare class TelegrafContext { * @param extra SendMessage additional params * @returns sent Message if Success */ - reply(text: string, extra?: tt.ExtraReplyMessage): Promise + reply(text: string, extra?: tt.ExtraSendMessage): Promise /** * Use this method to send audio files to the same chat, if you want Telegram clients to display them in the music player. @@ -220,7 +220,7 @@ export declare class TelegrafContext { * @param extra Additional params to send message * @returns a Message on success */ - replyWithHTML(html: string, extra?: tt.ExtraReplyMessage): Promise + replyWithHTML(html: string, extra?: tt.ExtraSendMessage): Promise /** * Use this method to send invoices @@ -254,7 +254,7 @@ export declare class TelegrafContext { */ replyWithMarkdown( markdown: string, - extra?: tt.ExtraReplyMessage + extra?: tt.ExtraSendMessage ): Promise /** diff --git a/typings/extra.d.ts b/typings/extra.d.ts index f05a0161b..d6d627014 100644 --- a/typings/extra.d.ts +++ b/typings/extra.d.ts @@ -13,7 +13,7 @@ export declare class Extra { webPreview(value?: boolean): this - markup(markup: any): tt.ExtraEditMessage & this + markup(markup: any): tt.ExtraReplyMarkup & this HTML(value?: boolean): this @@ -29,7 +29,7 @@ export declare class Extra { static webPreview(value?: boolean): Extra - static markup(markup: any): tt.ExtraEditMessage + static markup(markup: any): tt.ExtraReplyMarkup static HTML(value?: boolean): Extra diff --git a/typings/markup.d.ts b/typings/markup.d.ts index b38508a4c..778f3cb5a 100644 --- a/typings/markup.d.ts +++ b/typings/markup.d.ts @@ -103,7 +103,7 @@ export declare class Markup { selective(value?: boolean): this - extra(options?: tt.ExtraReplyMessage): tt.ExtraReplyMessage + extra(options?: tt.Extra): tt.Extra keyboard( buttons: KeyboardButton[] | KeyboardButton[][], diff --git a/typings/telegram-types.d.ts b/typings/telegram-types.d.ts index af914ec8f..885f1fd88 100644 --- a/typings/telegram-types.d.ts +++ b/typings/telegram-types.d.ts @@ -263,37 +263,76 @@ export interface ExtraPromoteChatMember { can_promote_members?: boolean } -export interface ExtraReplyMessage { +export interface ExtraReplyMarkup { + /** + * Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. + */ + reply_markup?: TT.InlineKeyboardMarkup | TT.ReplyKeyboardMarkup | TT.ReplyKeyboardRemove | TT.ForceReply +} + +interface ExtraReplyMarkupInlineKeyboard { + /** A JSON-serialized object for a new message inline keyboard. */ + reply_markup?: TT.InlineKeyboardMarkup +} + +interface ExtraFormatting { + /** + * Mode for parsing entities in the message text. See formatting options for more details. + */ + parse_mode?: ParseMode + + /** + * List of special entities that appear in message text, which can be specified instead of parse_mode + */ + entities?: TT.MessageEntity[] +} + +interface ExtraCaption { + /** + * Audio caption, 0-1024 characters + */ + caption?: string /** - * Send Markdown or HTML, if you want Telegram apps to show bold, italic, fixed-width text or inline URLs in your bot's message. + * Mode for parsing entities in the photo caption. See formatting options for more details. */ parse_mode?: ParseMode + /** + * List of special entities that appear in message text, which can be specified instead of parse_mode + */ + caption_entities?: TT.MessageEntity[] +} + +interface ExtraDisableWebPagePreview { /** * Disables link previews for links in this message */ disable_web_page_preview?: boolean +} +interface ExtraDisableNotifications { /** * Sends the message silently. Users will receive a notification with no sound. */ disable_notification?: boolean +} +interface ExtraReplyMessage { /** * If the message is a reply, ID of the original message */ reply_to_message_id?: number /** - * Additional interface options. An object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. + * Pass True, if the message should be sent even if the specified replied-to message is not found */ - reply_markup?: TT.InlineKeyboardMarkup | TT.ReplyKeyboardMarkup | TT.ReplyKeyboardRemove | TT.ForceReply + allow_sending_without_reply?: boolean } -export interface ExtraEditMessage extends ExtraReplyMessage { - // no specified properties -} +export interface ExtraSendMessage extends ExtraFormatting, ExtraDisableWebPagePreview, ExtraDisableNotifications, ExtraReplyMessage, ExtraReplyMarkup {} + +export interface ExtraEditMessage extends ExtraFormatting, ExtraDisableWebPagePreview, ExtraReplyMarkupInlineKeyboard {} export interface ExtraUnpinMessage { /** @@ -302,11 +341,7 @@ export interface ExtraUnpinMessage { message_id?: number } -export interface ExtraAudio extends ExtraReplyMessage { - /** - * Audio caption, 0-1024 characters - */ - caption?: string +export interface ExtraAudio extends ExtraCaption, ExtraDisableNotifications, ExtraReplyMessage, ExtraReplyMarkup { /** * Duration of the audio in seconds @@ -330,14 +365,9 @@ export interface ExtraAudio extends ExtraReplyMessage { * so you can pass β€œattach://” if the thumbnail was uploaded using multipart/form-data under . */ thumb?: InputFile - - /** - * Does not exist, see https://core.telegram.org/bots/api#sendaudio - */ - disable_web_page_preview?: never } -export interface ExtraDocument extends ExtraReplyMessage { +export interface ExtraDocument extends ExtraCaption, ExtraDisableNotifications, ExtraReplyMessage, ExtraReplyMarkup { /** * Thumbnail of the file sent; can be ignored if thumbnail generation for the file is supported server-side. * The thumbnail should be in JPEG format and less than 200 kB in size. A thumbnailβ€˜s width and height should not exceed 320. @@ -346,67 +376,39 @@ export interface ExtraDocument extends ExtraReplyMessage { */ thumb?: InputFile - /** - * Document caption (may also be used when resending documents by file_id), 0-1024 characters - */ - caption?: string - - /** - * List of special entities that appear in the caption, which can be specified instead of parse_mode - */ - caption_entities?: TT.MessageEntity - /** * Disables automatic server-side content type detection for files uploaded using multipart/form-data */ disable_content_type_detection?: Boolean - - /** - * Pass True, if the message should be sent even if the specified replied-to message is not found - */ - allow_sending_without_reply?: Boolean - - /** - * Does not exist, see https://core.telegram.org/bots/api#senddocument - */ - disable_web_page_preview?: never } -export interface ExtraGame extends ExtraReplyMessage { - /** - * Inline keyboard. If empty, one β€˜Play game_title’ button will be shown. If not empty, the first button must launch the game. - */ - reply_markup?: TT.InlineKeyboardMarkup +export interface ExtraGame extends ExtraDisableNotifications, ExtraReplyMessage, ExtraReplyMarkupInlineKeyboard {} - /** - * Does not exist, see https://core.telegram.org/bots/api#sendgame - */ - disable_web_page_preview?: never +export interface ExtraInvoice extends ExtraDisableNotifications, ExtraReplyMessage, ExtraReplyMarkupInlineKeyboard {} +export interface ExtraLocation extends ExtraDisableNotifications, ExtraReplyMessage, ExtraReplyMarkup { /** - * Does not exist, see https://core.telegram.org/bots/api#sendgame + * The radius of uncertainty for the location, measured in meters; 0-1500 */ - parse_mode?: never -} + horizontal_accuracy?: number -export interface ExtraInvoice extends ExtraReplyMessage { /** - * Inline keyboard. If empty, one 'Pay total price' button will be shown. If not empty, the first button must be a Pay button. + * Period in seconds for which the location will be updated (should be between 60 and 86400) */ - reply_markup?: TT.InlineKeyboardMarkup + live_period?: number /** - * Does not exist, see https://core.telegram.org/bots/api#sendinvoice + * For live locations, a direction in which the user is moving, in degrees. Must be between 1 and 360 if specified. */ - disable_web_page_preview?: never + heading?: number /** - * Does not exist, see https://core.telegram.org/bots/api#sendinvoice + * For live locations, a maximum distance for proximity alerts about approaching another chat member, in meters. Must be between 1 and 100000 if specified. */ - parse_mode?: never + proximity_alert_radius?: number } -export interface ExtraLocation extends ExtraReplyMessage { +export interface ExtraEditLocation { /** * The radius of uncertainty for the location, measured in meters; 0-1500 */ @@ -426,84 +428,17 @@ export interface ExtraLocation extends ExtraReplyMessage { * For live locations, a maximum distance for proximity alerts about approaching another chat member, in meters. Must be between 1 and 100000 if specified. */ proximity_alert_radius?: number - - /** - * Pass True, if the message should be sent even if the specified replied-to message is not found - */ - allow_sending_without_reply?: boolean - - /** - * Does not exist, see https://core.telegram.org/bots/api#sendlocation - */ - disable_web_page_preview?: never - - /** - * Does not exist, see https://core.telegram.org/bots/api#sendlocation - */ - parse_mode?: never -} - -export interface ExtraEditLocation extends ExtraLocation { - /** - * Does not exist, see https://core.telegram.org/bots/api#sendlocation - */ - live_period?: never } -export interface ExtraPhoto extends ExtraReplyMessage { - /** - * Photo caption (may also be used when resending photos by file_id), 0-1024 characters - */ - caption?: string - - /** - * Does not exist, see https://core.telegram.org/bots/api#sendphoto - */ - disable_web_page_preview?: never -} - -export interface ExtraMediaGroup extends ExtraReplyMessage { - /** - * Does not exist, see https://core.telegram.org/bots/api#sendmediagroup - */ - disable_web_page_preview?: never - - /** - * Does not exist, see https://core.telegram.org/bots/api#sendmediagroup - */ - parse_mode?: never - - /** - * Does not exist, see https://core.telegram.org/bots/api#sendmediagroup - */ - reply_markup?: never - - /** - * Pass True, if the message should be sent even if the specified replied-to message is not found - */ - allow_sending_without_reply?: Boolean -} +export interface ExtraPhoto extends ExtraCaption, ExtraDisableNotifications, ExtraReplyMessage, ExtraReplyMarkup {} -export interface ExtraAnimation extends ExtraReplyMessage { - /** - * Animation caption (may also be used when resending animation by file_id), 0-200 characters - */ - caption?: string -} +export interface ExtraMediaGroup extends ExtraDisableNotifications, ExtraReplyMessage {} -export interface ExtraSticker extends ExtraReplyMessage { - /** - * Does not exist, see https://core.telegram.org/bots/api#sendsticker - */ - disable_web_page_preview?: never +export interface ExtraAnimation extends ExtraCaption, ExtraDisableNotifications, ExtraReplyMessage, ExtraReplyMarkup {} - /** - * Does not exist, see https://core.telegram.org/bots/api#sendsticker - */ - parse_mode?: never -} +export interface ExtraSticker extends ExtraDisableNotifications, ExtraReplyMessage, ExtraReplyMarkup {} -export interface ExtraVideo extends ExtraReplyMessage { +export interface ExtraVideo extends ExtraCaption, ExtraDisableNotifications, ExtraReplyMessage, ExtraReplyMarkup { /** * Duration of sent video in seconds */ @@ -527,23 +462,13 @@ export interface ExtraVideo extends ExtraReplyMessage { */ thumb?: InputFile - /** - * Video caption (may also be used when resending videos by file_id), 0-1024 characters - */ - caption?: string - /** * Pass True, if the uploaded video is suitable for streaming */ supports_streaming?: boolean - - /** - * Does not exist, see https://core.telegram.org/bots/api#sendvideo - */ - disable_web_page_preview?: never } -export interface ExtraVideoNote extends ExtraReplyMessage { +export interface ExtraVideoNote extends ExtraDisableNotifications, ExtraReplyMessage, ExtraReplyMarkup { /** * Duration of sent video in seconds */ @@ -563,24 +488,14 @@ export interface ExtraVideoNote extends ExtraReplyMessage { thumb?: InputFile } -export interface ExtraVoice extends ExtraReplyMessage { - /** - * Voice message caption, 0-1024 characters - */ - caption?: string - +export interface ExtraVoice extends ExtraCaption, ExtraDisableNotifications, ExtraReplyMessage, ExtraReplyMarkup { /** * Duration of the voice message in seconds */ duration?: number - - /** - * Does not exist, see https://core.telegram.org/bots/api#sendvoice - */ - disable_web_page_preview?: never } -export interface ExtraDice extends ExtraReplyMessage { +export interface ExtraDice extends ExtraDisableNotifications, ExtraReplyMessage, ExtraReplyMarkup { /** * Emoji on which the dice throw animation is based. * Currently, must be one of β€œπŸŽ²β€, β€œπŸŽ―β€, β€œπŸ€β€, β€œβš½β€, or β€œπŸŽ°β€. @@ -588,19 +503,9 @@ export interface ExtraDice extends ExtraReplyMessage { * Defaults to β€œπŸŽ²β€ * */ emoji?: string - - /** - * Does not exist, see https://core.telegram.org/bots/api#senddice - */ - parse_mode?: never - - /** - * Does not exist, see https://core.telegram.org/bots/api#senddice - */ - disable_web_page_preview?: never } -export interface ExtraPoll { +export interface ExtraPoll extends ExtraDisableNotifications, ExtraReplyMessage, ExtraReplyMarkup { /** True, if the poll needs to be anonymous, defaults to True */ is_anonymous?: boolean @@ -612,25 +517,13 @@ export interface ExtraPoll { /** Pass True, if the poll needs to be immediately closed. This can be useful for poll preview. */ is_closed?: boolean - - /** Sends the message silently. Users will receive a notification with no sound. */ - disable_notification?: boolean - - /** If the message is a reply, ID of the original message */ - reply_to_message_id?: number - - /** Additional interface options. A JSON-serialized object for an inline keyboard, custom reply keyboard, instructions to remove reply keyboard or to force a reply from the user. */ - reply_markup?: - | TT.InlineKeyboardMarkup - | TT.ReplyKeyboardMarkup - | TT.ReplyKeyboardRemove - | TT.ForceReply } -export interface ExtraStopPoll { - /** A JSON-serialized object for a new message inline keyboard. */ - reply_markup?: TT.InlineKeyboardMarkup -} +export interface ExtraStopPoll extends ExtraReplyMarkupInlineKeyboard {} + +export type Extra = ExtraSendMessage + | ExtraEditMessage + | ExtraUnpinMessage export interface ExtraUnban { /** Do nothing if the user is not banned */ @@ -774,61 +667,3 @@ export interface BotCommand { */ description: string } - -/** - * This object represents a dice with random value from 1 to 6. (Yes, we're aware of the β€œproper” singular of die. But it's awkward, and we decided to help it change. One dice at a time!) - */ -export interface Dice { - /** - * Value of the dice, 1-6 - */ - value: number -} - -export interface PollOption { - /** Option text, 1-100 characters */ - text: string - - /** Number of users that voted for this option */ - voter_count: number -} - -export interface PollAnswer { - /** Unique poll identifier */ - poll_id: string - - /** The user, who changed the answer to the poll */ - user: TT.User - - /** 0-based identifiers of answer options, chosen by the user. May be empty if the user retracted their vote. */ - option_ids: number[] -} - -export interface Poll { - /** Unique poll identifier */ - id: string - - /** Poll question, 1-255 characters */ - question: string - - /** List of poll options */ - options: PollOption[] - - /** Total number of users that voted in the poll */ - total_voter_count: number - - /** True, if the poll is closed */ - is_closed: boolean - - /** True, if the poll is anonymous */ - is_anonymous: boolean - - /** Poll type, currently can be β€œregular” or β€œquiz” */ - type: 'regular' | 'quiz' - - /** True, if the poll allows multiple answers */ - allows_multiple_answers: boolean - - /** 0-based identifier of the correct answer option. Available only for polls in the quiz mode, which are closed, or was sent (not forwarded) by the bot or to the private chat with the bot. */ - correct_option_id?: number -} From 318d88f6302612a9f23fa920a92d067f57dcb41d Mon Sep 17 00:00:00 2001 From: Loskir Date: Thu, 14 Jan 2021 19:16:43 +0300 Subject: [PATCH 28/35] Update typings for quiz --- typings/context.d.ts | 2 +- typings/telegram-types.d.ts | 23 ++++++++++++++++++++--- typings/telegram.d.ts | 2 +- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/typings/context.d.ts b/typings/context.d.ts index e2ec6470d..3608504f9 100644 --- a/typings/context.d.ts +++ b/typings/context.d.ts @@ -302,7 +302,7 @@ export declare class TelegrafContext { replyWithQuiz( question: string, options: string[], - extra: tt.ExtraPoll + extra: tt.ExtraQuiz ): Promise /** diff --git a/typings/telegram-types.d.ts b/typings/telegram-types.d.ts index 885f1fd88..56a052b35 100644 --- a/typings/telegram-types.d.ts +++ b/typings/telegram-types.d.ts @@ -512,13 +512,30 @@ export interface ExtraPoll extends ExtraDisableNotifications, ExtraReplyMessage, /** True, if the poll allows multiple answers, ignored for polls in quiz mode, defaults to False */ allows_multiple_answers?: boolean - /** 0-based identifier of the correct answer option, required for polls in quiz mode */ - correct_option_id?: number - /** Pass True, if the poll needs to be immediately closed. This can be useful for poll preview. */ is_closed?: boolean } +export interface ExtraQuiz extends ExtraPoll { + /** 0-based identifier of the correct answer option, required for polls in quiz mode */ + correct_option_id: number + + /** Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-200 characters with at most 2 line feeds after entities parsing */ + explanation?: string + + /** List of special entities that appear in the poll explanation, which can be specified instead of parse_mode */ + explanation_entities?: TT.MessageEntity[] + + /** Mode for parsing entities in the explanation. See formatting options for more details. */ + explanation_parse_mode?: ParseMode + + /** Amount of time in seconds the poll will be active after creation, 5-600. Can't be used together with close_date. */ + open_period?: number + + /** Point in time (Unix timestamp) when the poll will be automatically closed. Must be at least 5 and no more than 600 seconds in the future. Can't be used together with open_period. */ + close_date?: number +} + export interface ExtraStopPoll extends ExtraReplyMarkupInlineKeyboard {} export type Extra = ExtraSendMessage diff --git a/typings/telegram.d.ts b/typings/telegram.d.ts index 62b796578..a214eccbc 100644 --- a/typings/telegram.d.ts +++ b/typings/telegram.d.ts @@ -534,7 +534,7 @@ export declare class Telegram extends ApiClient { chatId: number | string, question: string, options: string[], - extra: tt.ExtraPoll + extra: tt.ExtraQuiz ): Promise /** From 4136de46501d5ab1a10cfa5229a141433bcc974f Mon Sep 17 00:00:00 2001 From: Loskir Date: Thu, 14 Jan 2021 19:40:57 +0300 Subject: [PATCH 29/35] Fix typings for poll --- typings/telegram-types.d.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/typings/telegram-types.d.ts b/typings/telegram-types.d.ts index 56a052b35..b05c00d64 100644 --- a/typings/telegram-types.d.ts +++ b/typings/telegram-types.d.ts @@ -514,6 +514,12 @@ export interface ExtraPoll extends ExtraDisableNotifications, ExtraReplyMessage, /** Pass True, if the poll needs to be immediately closed. This can be useful for poll preview. */ is_closed?: boolean + + /** Amount of time in seconds the poll will be active after creation, 5-600. Can't be used together with close_date. */ + open_period?: number + + /** Point in time (Unix timestamp) when the poll will be automatically closed. Must be at least 5 and no more than 600 seconds in the future. Can't be used together with open_period. */ + close_date?: number } export interface ExtraQuiz extends ExtraPoll { @@ -528,12 +534,6 @@ export interface ExtraQuiz extends ExtraPoll { /** Mode for parsing entities in the explanation. See formatting options for more details. */ explanation_parse_mode?: ParseMode - - /** Amount of time in seconds the poll will be active after creation, 5-600. Can't be used together with close_date. */ - open_period?: number - - /** Point in time (Unix timestamp) when the poll will be automatically closed. Must be at least 5 and no more than 600 seconds in the future. Can't be used together with open_period. */ - close_date?: number } export interface ExtraStopPoll extends ExtraReplyMarkupInlineKeyboard {} From 35e37d236c138feee163f20845d6f285126cd995 Mon Sep 17 00:00:00 2001 From: Josh Dies Date: Thu, 14 Jan 2021 20:44:53 +0300 Subject: [PATCH 30/35] native copy message & online require --- docs/examples/echo-bot-module.js | 6 ++---- docs/examples/echo-bot.js | 6 ++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/docs/examples/echo-bot-module.js b/docs/examples/echo-bot-module.js index 56c5971c3..65b395070 100644 --- a/docs/examples/echo-bot-module.js +++ b/docs/examples/echo-bot-module.js @@ -1,8 +1,6 @@ // Modules documentation: https://telegraf.js.org/#/?id=telegraf-modules // $> telegraf -t `BOT TOKEN` echo-bot-module.js -const Composer = require('telegraf/composer') -const Extra = require('telegraf/extra') -const Markup = require('telegraf/markup') +const { Composer, Extra, Markup } = require('telegraf') const keyboard = Markup.inlineKeyboard([ Markup.urlButton('❀️', 'http://telegraf.js.org'), @@ -35,6 +33,6 @@ bot.help(async (ctx) => { }) bot.action('delete', ({ deleteMessage }) => deleteMessage()) bot.on('dice', (ctx) => ctx.reply(`Value: ${ctx.message.dice.value}`)) -bot.on('message', (ctx) => ctx.telegram.sendCopy(ctx.chat.id, ctx.message, Extra.markup(keyboard))) +bot.on('message', (ctx) => ctx.copyMessage(ctx.chat.id, Extra.markup(keyboard))) module.exports = bot diff --git a/docs/examples/echo-bot.js b/docs/examples/echo-bot.js index e2475a652..3660ee3e1 100644 --- a/docs/examples/echo-bot.js +++ b/docs/examples/echo-bot.js @@ -1,6 +1,4 @@ -const Telegraf = require('telegraf') -const Extra = require('telegraf/extra') -const Markup = require('telegraf/markup') +const { Telegraf, Extra, Markup } = require('../../telegraf') const keyboard = Markup.inlineKeyboard([ Markup.urlButton('❀️', 'http://telegraf.js.org'), @@ -10,6 +8,6 @@ const keyboard = Markup.inlineKeyboard([ const bot = new Telegraf(process.env.BOT_TOKEN) bot.start((ctx) => ctx.reply('Hello')) bot.help((ctx) => ctx.reply('Help message')) -bot.on('message', (ctx) => ctx.telegram.sendCopy(ctx.chat.id, ctx.message, Extra.markup(keyboard))) +bot.on('message', (ctx) => ctx.copyMessage(ctx.chat.id, Extra.markup(keyboard))) bot.action('delete', ({ deleteMessage }) => deleteMessage()) bot.launch() From eb96e8f059739792ebc4e133e63e7d737fd7288b Mon Sep 17 00:00:00 2001 From: Ilya Volk Date: Fri, 15 Jan 2021 00:54:13 +0300 Subject: [PATCH 31/35] rewrite editMessageMedia --- context.js | 25 +++++++++++-------------- docs/examples/media-bot.js | 9 ++++++--- telegram.js | 10 ++-------- typings/context.d.ts | 6 ++---- typings/telegram-types.d.ts | 8 ++++++++ typings/telegram.d.ts | 9 +++++++++ 6 files changed, 38 insertions(+), 29 deletions(-) diff --git a/context.js b/context.js index f374ab9b1..399a95910 100644 --- a/context.js +++ b/context.js @@ -239,20 +239,17 @@ class TelegrafContext { editMessageMedia (media, extra) { this.assert(this.callbackQuery || this.inlineMessageId, 'editMessageMedia') return this.inlineMessageId - ? this.telegram.editMessageMedia( - undefined, - undefined, - this.inlineMessageId, - media, - extra - ) - : this.telegram.editMessageMedia( - this.chat.id, - this.callbackQuery.message.message_id, - undefined, - media, - extra - ) + ? this.telegram.editMessageMedia({ + inline_message_id: this.inlineMessageId, + media, + reply_markup: extra.reply_markup ? extra.reply_markup : extra + }) + : this.telegram.editMessageMedia({ + chat_id: this.chat.id, + message_id: this.callbackQuery.message.message_id, + media, + reply_markup: extra.reply_markup ? extra.reply_markup : extra + }) } editMessageReplyMarkup (markup) { diff --git a/docs/examples/media-bot.js b/docs/examples/media-bot.js index f9735a22c..caac3bbea 100644 --- a/docs/examples/media-bot.js +++ b/docs/examples/media-bot.js @@ -62,8 +62,11 @@ bot.command('edit_media', (ctx) => ctx.replyWithAnimation(AnimationUrl1, Extra.m ))) bot.action('swap_media', (ctx) => ctx.editMessageMedia({ - type: 'animation', - media: AnimationUrl2 -})) + media: { + type: 'animation', + media: AnimationUrl2, + }, + }), +) bot.launch() diff --git a/telegram.js b/telegram.js index 13a6749f9..095f0c72a 100644 --- a/telegram.js +++ b/telegram.js @@ -296,14 +296,8 @@ class Telegram extends ApiClient { }) } - editMessageMedia (chatId, messageId, inlineMessageId, media, extra = {}) { - return this.callApi('editMessageMedia', { - chat_id: chatId, - message_id: messageId, - inline_message_id: inlineMessageId, - media: { ...media, parse_mode: extra.parse_mode }, - reply_markup: extra.reply_markup ? extra.reply_markup : extra - }) + editMessageMedia (request = {}) { + return this.callApi('editMessageMedia', request) } editMessageReplyMarkup (chatId, messageId, inlineMessageId, markup) { diff --git a/typings/context.d.ts b/typings/context.d.ts index 3608504f9..a2ece1ebf 100644 --- a/typings/context.d.ts +++ b/typings/context.d.ts @@ -447,12 +447,10 @@ export declare class TelegrafContext { /** * Use this method to edit animation, audio, document, photo, or video messages. * @returns On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned. - * @param media New media of message - * @param markup Markup of inline keyboard + * @param request Request object (reqd more: https://core.telegram.org/bots/api#editmessagemedia) */ editMessageMedia( - media: tt.MessageMedia, - extra?: tt.ExtraEditMessage + request: tt.EditMessageMediaRequest ): Promise /** diff --git a/typings/telegram-types.d.ts b/typings/telegram-types.d.ts index b05c00d64..6f8d8708b 100644 --- a/typings/telegram-types.d.ts +++ b/typings/telegram-types.d.ts @@ -144,6 +144,14 @@ export interface InputMediaDocument { parse_mode?: string } +export interface EditMessageMediaRequest { + chat_id?: number | string + message_id?: number + inline_message_id?: string + media: MessageMedia + reply_markup?: ExtraReplyMarkup + } + export interface StickerData { png_sticker: string | Buffer emojis: string diff --git a/typings/telegram.d.ts b/typings/telegram.d.ts index a214eccbc..360bc3fb1 100644 --- a/typings/telegram.d.ts +++ b/typings/telegram.d.ts @@ -156,6 +156,15 @@ export declare class Telegram extends ApiClient { markup?: string ): Promise + /** + * Use this method to edit animation, audio, document, photo, or video messages. + * @returns On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned. + * @param request Request object (reqd more: https://core.telegram.org/bots/api#editmessagemedia) + */ + editMessageMedia( + request: tt.EditMessageMediaRequest + ): Promise + /** * Use this method to edit live location messages * @param latitude Latitude of location From a4c5f122718841bb9883ae8a41c888dceccdd4a8 Mon Sep 17 00:00:00 2001 From: Ilya Volk Date: Fri, 15 Jan 2021 01:07:43 +0300 Subject: [PATCH 32/35] fixes --- docs/examples/media-bot.js | 10 ++++------ telegram.js | 4 ++-- typings/context.d.ts | 3 ++- typings/telegram-types.d.ts | 6 ++++-- typings/telegram.d.ts | 2 +- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/docs/examples/media-bot.js b/docs/examples/media-bot.js index caac3bbea..dc5e3524d 100644 --- a/docs/examples/media-bot.js +++ b/docs/examples/media-bot.js @@ -62,11 +62,9 @@ bot.command('edit_media', (ctx) => ctx.replyWithAnimation(AnimationUrl1, Extra.m ))) bot.action('swap_media', (ctx) => ctx.editMessageMedia({ - media: { - type: 'animation', - media: AnimationUrl2, - }, - }), -) + type: 'animation', + media: AnimationUrl2, + } +)) bot.launch() diff --git a/telegram.js b/telegram.js index 095f0c72a..f7ce01bb4 100644 --- a/telegram.js +++ b/telegram.js @@ -296,8 +296,8 @@ class Telegram extends ApiClient { }) } - editMessageMedia (request = {}) { - return this.callApi('editMessageMedia', request) + editMessageMedia (payload = {}) { + return this.callApi('editMessageMedia', payload) } editMessageReplyMarkup (chatId, messageId, inlineMessageId, markup) { diff --git a/typings/context.d.ts b/typings/context.d.ts index a2ece1ebf..640f76593 100644 --- a/typings/context.d.ts +++ b/typings/context.d.ts @@ -450,7 +450,8 @@ export declare class TelegrafContext { * @param request Request object (reqd more: https://core.telegram.org/bots/api#editmessagemedia) */ editMessageMedia( - request: tt.EditMessageMediaRequest + media: tt.MessageMedia, + extra?: tt.ExtraEditMedia ): Promise /** diff --git a/typings/telegram-types.d.ts b/typings/telegram-types.d.ts index 6f8d8708b..fc5f28f24 100644 --- a/typings/telegram-types.d.ts +++ b/typings/telegram-types.d.ts @@ -144,12 +144,12 @@ export interface InputMediaDocument { parse_mode?: string } -export interface EditMessageMediaRequest { +export interface EditMessageMediaPayload { chat_id?: number | string message_id?: number inline_message_id?: string media: MessageMedia - reply_markup?: ExtraReplyMarkup + reply_markup?: ExtraEditMedia } export interface StickerData { @@ -342,6 +342,8 @@ export interface ExtraSendMessage extends ExtraFormatting, ExtraDisableWebPagePr export interface ExtraEditMessage extends ExtraFormatting, ExtraDisableWebPagePreview, ExtraReplyMarkupInlineKeyboard {} +export interface ExtraEditMedia extends ExtraReplyMarkupInlineKeyboard {} + export interface ExtraUnpinMessage { /** * Identifier of a message to unpin. If not specified, the most recent pinned message (by sending date) will be unpinned. diff --git a/typings/telegram.d.ts b/typings/telegram.d.ts index 360bc3fb1..e6e096fdc 100644 --- a/typings/telegram.d.ts +++ b/typings/telegram.d.ts @@ -162,7 +162,7 @@ export declare class Telegram extends ApiClient { * @param request Request object (reqd more: https://core.telegram.org/bots/api#editmessagemedia) */ editMessageMedia( - request: tt.EditMessageMediaRequest + payload: tt.EditMessageMediaPayload ): Promise /** From 267bafbdf08dbb618f2960050dc96dde1522ea7e Mon Sep 17 00:00:00 2001 From: Loskir Date: Fri, 15 Jan 2021 10:49:36 +0300 Subject: [PATCH 33/35] Fix typing for EditMessageMediaPayload --- typings/telegram-types.d.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/typings/telegram-types.d.ts b/typings/telegram-types.d.ts index fc5f28f24..46dfee18e 100644 --- a/typings/telegram-types.d.ts +++ b/typings/telegram-types.d.ts @@ -144,12 +144,11 @@ export interface InputMediaDocument { parse_mode?: string } -export interface EditMessageMediaPayload { +export interface EditMessageMediaPayload extends ExtraEditMedia { chat_id?: number | string message_id?: number inline_message_id?: string media: MessageMedia - reply_markup?: ExtraEditMedia } export interface StickerData { From af7f7f203c04658a2391e941721ba670cf12b93a Mon Sep 17 00:00:00 2001 From: Loskir Date: Fri, 15 Jan 2021 10:49:55 +0300 Subject: [PATCH 34/35] Fix JSDoc --- typings/context.d.ts | 3 ++- typings/telegram.d.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/typings/context.d.ts b/typings/context.d.ts index 640f76593..f17275372 100644 --- a/typings/context.d.ts +++ b/typings/context.d.ts @@ -447,7 +447,8 @@ export declare class TelegrafContext { /** * Use this method to edit animation, audio, document, photo, or video messages. * @returns On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned. - * @param request Request object (reqd more: https://core.telegram.org/bots/api#editmessagemedia) + * @param media A JSON-serialized object for a new media content of the message + * @param extra Extra parameters for editMessageMedia */ editMessageMedia( media: tt.MessageMedia, diff --git a/typings/telegram.d.ts b/typings/telegram.d.ts index e6e096fdc..bed386cdf 100644 --- a/typings/telegram.d.ts +++ b/typings/telegram.d.ts @@ -159,7 +159,7 @@ export declare class Telegram extends ApiClient { /** * Use this method to edit animation, audio, document, photo, or video messages. * @returns On success, if the edited message was sent by the bot, the edited Message is returned, otherwise True is returned. - * @param request Request object (reqd more: https://core.telegram.org/bots/api#editmessagemedia) + * @param payload Request object (reqd more: https://core.telegram.org/bots/api#editmessagemedia) */ editMessageMedia( payload: tt.EditMessageMediaPayload From eea947b7180674981eb0aae772118a767ecb22ed Mon Sep 17 00:00:00 2001 From: Loskir Date: Fri, 15 Jan 2021 10:51:06 +0300 Subject: [PATCH 35/35] Lint --- context.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/context.js b/context.js index 399a95910..fd2049c94 100644 --- a/context.js +++ b/context.js @@ -240,16 +240,16 @@ class TelegrafContext { this.assert(this.callbackQuery || this.inlineMessageId, 'editMessageMedia') return this.inlineMessageId ? this.telegram.editMessageMedia({ - inline_message_id: this.inlineMessageId, - media, - reply_markup: extra.reply_markup ? extra.reply_markup : extra - }) + inline_message_id: this.inlineMessageId, + media, + reply_markup: extra.reply_markup ? extra.reply_markup : extra + }) : this.telegram.editMessageMedia({ - chat_id: this.chat.id, - message_id: this.callbackQuery.message.message_id, - media, - reply_markup: extra.reply_markup ? extra.reply_markup : extra - }) + chat_id: this.chat.id, + message_id: this.callbackQuery.message.message_id, + media, + reply_markup: extra.reply_markup ? extra.reply_markup : extra + }) } editMessageReplyMarkup (markup) {