diff --git a/context.js b/context.js index 02f421079..fd2049c94 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, + ? this.telegram.editMessageMedia({ + inline_message_id: this.inlineMessageId, media, - extra - ) - : this.telegram.editMessageMedia( - this.chat.id, - this.callbackQuery.message.message_id, - undefined, + 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, - extra - ) + reply_markup: extra.reply_markup ? extra.reply_markup : extra + }) } editMessageReplyMarkup (markup) { @@ -272,7 +269,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 +278,8 @@ class TelegrafContext { undefined, undefined, this.inlineMessageId, - markup + markup, + extra ) : this.telegram.editMessageLiveLocation( latitude, @@ -289,7 +287,8 @@ class TelegrafContext { this.chat.id, this.callbackQuery.message.message_id, undefined, - markup + markup, + extra ) } @@ -380,6 +379,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) @@ -590,6 +594,16 @@ class TelegrafContext { this.assert(message, 'forwardMessage') return this.telegram.forwardMessage(chatId, this.chat.id, message.message_id, extra) } + + copyMessage (chatId, extra) { + 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/docs/README.md b/docs/README.md index 6d0af7c7a..f76c9ae5f 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) | @@ -1440,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 @@ -1482,7 +1485,6 @@ Forwards message. | messageId | `number` | Message id | | [extra] | `object` | [Extra parameters](https://core.telegram.org/bots/api#forwardmessage)| - ##### sendCopy Sends message copy. @@ -1495,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. @@ -1786,6 +1801,18 @@ Use this method to unpin a message in a supergroup chat. `telegram.unpinChatMessage(chatId) => Promise` [Official documentation](https://core.telegram.org/bots/api#unpinchatmessage) +| Param | Type | Description | +| --- | --- | --- | +| 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 | @@ -1808,6 +1835,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 +2137,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 @@ -2127,7 +2156,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/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() diff --git a/docs/examples/media-bot.js b/docs/examples/media-bot.js index f9735a22c..dc5e3524d 100644 --- a/docs/examples/media-bot.js +++ b/docs/examples/media-bot.js @@ -62,8 +62,9 @@ bot.command('edit_media', (ctx) => ctx.replyWithAnimation(AnimationUrl1, Extra.m ))) bot.action('swap_media', (ctx) => ctx.editMessageMedia({ - type: 'animation', - media: AnimationUrl2 -})) + type: 'animation', + media: AnimationUrl2, + } +)) bot.launch() 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/telegram.js b/telegram.js index 1224b766e..f7ce01bb4 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) { @@ -231,16 +226,20 @@ 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 }) + } + + unpinAllChatMessages (chatId) { + return this.callApi('unpinAllChatMessages', { chat_id: chatId }) } leaveChat (chatId) { 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) { @@ -297,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 (payload = {}) { + return this.callApi('editMessageMedia', payload) } editMessageReplyMarkup (chatId, messageId, inlineMessageId, markup) { @@ -316,14 +309,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 }) } @@ -417,6 +411,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') @@ -428,6 +425,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..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) @@ -102,6 +103,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 }) @@ -141,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) @@ -156,6 +159,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/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 7021badde..f17275372 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 @@ -145,8 +145,15 @@ 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(extra?: tt.ExtraUnpinMessage): Promise + + /** + * Use this method to clear the list of pinned messages in a chat + * @returns True on success */ - unpinChatMessage(): Promise + unpinAllChatMessages(): Promise /** * Use this method to reply on messages in the same chat. @@ -154,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. @@ -213,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 @@ -247,7 +254,7 @@ export declare class TelegrafContext { */ replyWithMarkdown( markdown: string, - extra?: tt.ExtraReplyMessage + extra?: tt.ExtraSendMessage ): Promise /** @@ -295,7 +302,7 @@ export declare class TelegrafContext { replyWithQuiz( question: string, options: string[], - extra: tt.ExtraPoll + extra: tt.ExtraQuiz ): Promise /** @@ -348,6 +355,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 + // ------------------------------------------------------------------------------------------ // // ------------------------------------------------------------------------------------------ // // ------------------------------------------------------------------------------------------ // @@ -429,24 +447,27 @@ 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 media A JSON-serialized object for a new media content of the message + * @param extra Extra parameters for editMessageMedia */ editMessageMedia( media: tt.MessageMedia, - extra?: tt.ExtraEditMessage + extra?: tt.ExtraEditMedia ): 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 /** @@ -460,14 +481,15 @@ 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. - * @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( 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 decfa226b..46dfee18e 100644 --- a/typings/telegram-types.d.ts +++ b/typings/telegram-types.d.ts @@ -1,5 +1,5 @@ -import * as TT from "telegram-typings"; -export * from "telegram-typings"; +import * as TT from 'typegram' +export * from 'typegram' export type ParseMode = 'Markdown' | 'MarkdownV2' | 'HTML' @@ -144,6 +144,13 @@ export interface InputMediaDocument { parse_mode?: string } +export interface EditMessageMediaPayload extends ExtraEditMedia { + chat_id?: number | string + message_id?: number + inline_message_id?: string + media: MessageMedia + } + export interface StickerData { png_sticker: string | Buffer emojis: string @@ -207,6 +214,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 @@ -241,43 +270,87 @@ 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 ExtraEditMedia extends ExtraReplyMarkupInlineKeyboard {} -export interface ExtraAudio extends ExtraReplyMessage { +export interface ExtraUnpinMessage { /** - * Audio caption, 0-1024 characters + * Identifier of a message to unpin. If not specified, the most recent pinned message (by sending date) will be unpinned. */ - caption?: string + message_id?: number +} + +export interface ExtraAudio extends ExtraCaption, ExtraDisableNotifications, ExtraReplyMessage, ExtraReplyMarkup { /** * Duration of the audio in seconds @@ -301,14 +374,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. @@ -318,116 +386,68 @@ export interface ExtraDocument extends ExtraReplyMessage { thumb?: InputFile /** - * Document caption (may also be used when resending documents by file_id), 0-1024 characters - */ - caption?: string - - /** - * 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 - - /** - * Does not exist, see https://core.telegram.org/bots/api#sendgame - */ - disable_web_page_preview?: never - - /** - * Does not exist, see https://core.telegram.org/bots/api#sendgame + * Disables automatic server-side content type detection for files uploaded using multipart/form-data */ - parse_mode?: never + disable_content_type_detection?: Boolean } -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. - */ - reply_markup?: TT.InlineKeyboardMarkup +export interface ExtraGame extends ExtraDisableNotifications, ExtraReplyMessage, ExtraReplyMarkupInlineKeyboard {} - /** - * Does not exist, see https://core.telegram.org/bots/api#sendinvoice - */ - 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#sendinvoice + * The radius of uncertainty for the location, measured in meters; 0-1500 */ - parse_mode?: never -} + horizontal_accuracy?: number -export interface ExtraLocation extends ExtraReplyMessage { /** * Period in seconds for which the location will be updated (should be between 60 and 86400) */ live_period?: number /** - * Does not exist, see https://core.telegram.org/bots/api#sendlocation + * 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#sendlocation + * 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 ExtraPhoto extends ExtraReplyMessage { - /** - * Photo caption (may also be used when resending photos by file_id), 0-1024 characters - */ - caption?: string - +export interface ExtraEditLocation { /** - * Does not exist, see https://core.telegram.org/bots/api#sendphoto + * The radius of uncertainty for the location, measured in meters; 0-1500 */ - disable_web_page_preview?: never -} + horizontal_accuracy?: number -export interface ExtraMediaGroup extends ExtraReplyMessage { /** - * Does not exist, see https://core.telegram.org/bots/api#sendmediagroup + * Period in seconds for which the location will be updated (should be between 60 and 86400) */ - disable_web_page_preview?: never + live_period?: number /** - * Does not exist, see https://core.telegram.org/bots/api#sendmediagroup + * For live locations, a direction in which the user is moving, in degrees. Must be between 1 and 360 if specified. */ - parse_mode?: never + heading?: number /** - * Does not exist, see https://core.telegram.org/bots/api#sendmediagroup + * For live locations, a maximum distance for proximity alerts about approaching another chat member, in meters. Must be between 1 and 100000 if specified. */ - reply_markup?: never + proximity_alert_radius?: number } -export interface ExtraAnimation extends ExtraReplyMessage { - /** - * Animation caption (may also be used when resending animation by file_id), 0-200 characters - */ - caption?: string -} +export interface ExtraPhoto extends ExtraCaption, ExtraDisableNotifications, ExtraReplyMessage, ExtraReplyMarkup {} -export interface ExtraSticker extends ExtraReplyMessage { - /** - * Does not exist, see https://core.telegram.org/bots/api#sendsticker - */ - disable_web_page_preview?: never +export interface ExtraMediaGroup extends ExtraDisableNotifications, ExtraReplyMessage {} - /** - * Does not exist, see https://core.telegram.org/bots/api#sendsticker - */ - parse_mode?: never -} +export interface ExtraAnimation extends ExtraCaption, ExtraDisableNotifications, ExtraReplyMessage, ExtraReplyMarkup {} + +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 */ @@ -451,23 +471,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 */ @@ -487,138 +497,78 @@ 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 { - /** - * Does not exist, see https://core.telegram.org/bots/api#senddice - */ - parse_mode?: never - +export interface ExtraDice extends ExtraDisableNotifications, ExtraReplyMessage, ExtraReplyMarkup { /** - * Does not exist, see https://core.telegram.org/bots/api#senddice - */ - disable_web_page_preview?: never + * 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 } -export interface ExtraPoll { +export interface ExtraPoll extends ExtraDisableNotifications, ExtraReplyMessage, ExtraReplyMarkup { /** True, if the poll needs to be anonymous, defaults to True */ is_anonymous?: boolean /** 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 - /** 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 -} + /** 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 -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 + /** 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 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 ExtraQuiz extends ExtraPoll { + /** 0-based identifier of the correct answer option, required for polls in quiz mode */ + correct_option_id: number -export interface MessageAnimation extends TT.Message { - animation: TT.Animation -} + /** 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 -export interface MessageSticker extends TT.Message { - sticker: TT.Sticker -} + /** List of special entities that appear in the poll explanation, which can be specified instead of parse_mode */ + explanation_entities?: TT.MessageEntity[] -export interface MessageVideo extends TT.Message { - video: TT.Video + /** Mode for parsing entities in the explanation. See formatting options for more details. */ + explanation_parse_mode?: ParseMode } -export interface MessageVideoNote extends TT.Message { - video_note: TT.VideoNote -} +export interface ExtraStopPoll extends ExtraReplyMarkupInlineKeyboard {} -export interface MessageVoice extends TT.Message { - voice: TT.Voice -} +export type Extra = ExtraSendMessage + | ExtraEditMessage + | ExtraUnpinMessage -export interface MessageDice extends TT.Message { - dice: Dice +export interface ExtraUnban { + /** Do nothing if the user is not banned */ + only_if_banned?: Boolean } -export interface MessagePoll extends TT.Message { - poll: Poll -} +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 { /** @@ -743,61 +693,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 -} diff --git a/typings/telegram.d.ts b/typings/telegram.d.ts index 4d7a20699..bed386cdf 100644 --- a/typings/telegram.d.ts +++ b/typings/telegram.d.ts @@ -156,6 +156,36 @@ 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 payload Request object (reqd more: https://core.telegram.org/bots/api#editmessagemedia) + */ + editMessageMedia( + payload: tt.EditMessageMediaPayload + ): 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. @@ -246,6 +276,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) @@ -331,9 +376,17 @@ 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, 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 */ - unpinChatMessage(chatId: number | string): Promise + unpinAllChatMessages(chatId: number | string): Promise /** * Use this method to send text messages @@ -459,14 +512,14 @@ 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> /** * 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. @@ -490,7 +543,7 @@ export declare class Telegram extends ApiClient { chatId: number | string, question: string, options: string[], - extra: tt.ExtraPoll + extra: tt.ExtraQuiz ): Promise /** @@ -586,23 +639,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 @@ -641,14 +693,16 @@ 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. * @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( diff --git a/typings/test.ts b/typings/test.ts index 6eb0d387c..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({ @@ -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, })