From 03bf248658be20b9749699daa35899594a9e99c7 Mon Sep 17 00:00:00 2001 From: teidesu Date: Mon, 3 May 2021 14:30:12 +0300 Subject: [PATCH] feat(client): edit media and schedule date in the message --- packages/client/src/client.ts | 29 ++++++++- .../src/methods/messages/edit-message.ts | 61 ++++++++++++++++--- 2 files changed, 78 insertions(+), 12 deletions(-) diff --git a/packages/client/src/client.ts b/packages/client/src/client.ts index a5c1ac72..96a86e2d 100644 --- a/packages/client/src/client.ts +++ b/packages/client/src/client.ts @@ -1137,7 +1137,7 @@ export interface TelegramClient extends BaseTelegramClient { revoke?: boolean ): Promise /** - * Edit message text and/or reply markup. + * Edit message text, media, reply markup and schedule date. * * @param chatId ID of the chat, its username, phone or `"me"` or `"self"` * @param message Message or its ID @@ -1149,6 +1149,8 @@ export interface TelegramClient extends BaseTelegramClient { params: { /** * New message text + * + * When `media` is passed, `media.caption` is used instead */ text?: string @@ -1165,19 +1167,40 @@ export interface TelegramClient extends BaseTelegramClient { * parse mode. * * **Note:** Passing this makes the method ignore {@link parseMode} + * + * When `media` is passed, `media.entities` is used instead */ entities?: tl.TypeMessageEntity[] + /** + * New message media + */ + media?: InputMediaLike + /** * Whether to disable links preview in this message */ disableWebPreview?: boolean /** - * For bots: inline or reply markup or an instruction - * to hide a reply keyboard or to force a reply. + * For bots: new reply markup. + * If omitted, existing markup will be removed. */ replyMarkup?: ReplyMarkup + + /** + * To re-schedule a message: new schedule date. + * When passing a number, a UNIX time in ms is expected. + */ + scheduleDate?: Date | number + + /** + * For media, upload progress callback. + * + * @param uploaded Number of bytes uploaded + * @param total Total file size in bytes + */ + progressCallback?: (uploaded: number, total: number) => void } ): Promise /** diff --git a/packages/client/src/methods/messages/edit-message.ts b/packages/client/src/methods/messages/edit-message.ts index 8068fdf7..61e8c64e 100644 --- a/packages/client/src/methods/messages/edit-message.ts +++ b/packages/client/src/methods/messages/edit-message.ts @@ -1,10 +1,16 @@ import { TelegramClient } from '../../client' -import { BotKeyboard, InputPeerLike, Message, ReplyMarkup } from '../../types' +import { + BotKeyboard, + InputMediaLike, + InputPeerLike, + Message, + ReplyMarkup, +} from '../../types' import { tl } from '@mtcute/tl' import { normalizeToInputPeer } from '../../utils/peer-utils' /** - * Edit message text and/or reply markup. + * Edit message text, media, reply markup and schedule date. * * @param chatId ID of the chat, its username, phone or `"me"` or `"self"` * @param message Message or its ID @@ -18,6 +24,8 @@ export async function editMessage( params: { /** * New message text + * + * When `media` is passed, `media.caption` is used instead */ text?: string @@ -34,26 +42,60 @@ export async function editMessage( * parse mode. * * **Note:** Passing this makes the method ignore {@link parseMode} + * + * When `media` is passed, `media.entities` is used instead */ entities?: tl.TypeMessageEntity[] + /** + * New message media + */ + media?: InputMediaLike + /** * Whether to disable links preview in this message */ disableWebPreview?: boolean /** - * For bots: inline or reply markup or an instruction - * to hide a reply keyboard or to force a reply. + * For bots: new reply markup. + * If omitted, existing markup will be removed. */ replyMarkup?: ReplyMarkup + + /** + * To re-schedule a message: new schedule date. + * When passing a number, a UNIX time in ms is expected. + */ + scheduleDate?: Date | number + + /** + * For media, upload progress callback. + * + * @param uploaded Number of bytes uploaded + * @param total Total file size in bytes + */ + progressCallback?: (uploaded: number, total: number) => void } ): Promise { - const [content, entities] = await this._parseEntities( - params.text, - params.parseMode, - params.entities - ) + let content: string | undefined + let entities: tl.TypeMessageEntity[] | undefined + let media: tl.TypeInputMedia | undefined = undefined + + if (params.media) { + media = await this._normalizeInputMedia(params.media, params) + ;[content, entities] = await this._parseEntities( + params.media.caption, + params.parseMode, + params.media.entities + ) + } else { + ;[content, entities] = await this._parseEntities( + params.text, + params.parseMode, + params.entities + ) + } const res = await this.call({ _: 'messages.editMessage', @@ -63,6 +105,7 @@ export async function editMessage( replyMarkup: BotKeyboard._convertToTl(params.replyMarkup), message: content, entities, + media }) return this._findMessageInUpdate(res, true) as any