feat(client): edit media and schedule date in the message
This commit is contained in:
parent
8bd81adacc
commit
03bf248658
2 changed files with 78 additions and 12 deletions
|
@ -1137,7 +1137,7 @@ export interface TelegramClient extends BaseTelegramClient {
|
||||||
revoke?: boolean
|
revoke?: boolean
|
||||||
): Promise<boolean>
|
): Promise<boolean>
|
||||||
/**
|
/**
|
||||||
* 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 chatId ID of the chat, its username, phone or `"me"` or `"self"`
|
||||||
* @param message Message or its ID
|
* @param message Message or its ID
|
||||||
|
@ -1149,6 +1149,8 @@ export interface TelegramClient extends BaseTelegramClient {
|
||||||
params: {
|
params: {
|
||||||
/**
|
/**
|
||||||
* New message text
|
* New message text
|
||||||
|
*
|
||||||
|
* When `media` is passed, `media.caption` is used instead
|
||||||
*/
|
*/
|
||||||
text?: string
|
text?: string
|
||||||
|
|
||||||
|
@ -1165,19 +1167,40 @@ export interface TelegramClient extends BaseTelegramClient {
|
||||||
* parse mode.
|
* parse mode.
|
||||||
*
|
*
|
||||||
* **Note:** Passing this makes the method ignore {@link parseMode}
|
* **Note:** Passing this makes the method ignore {@link parseMode}
|
||||||
|
*
|
||||||
|
* When `media` is passed, `media.entities` is used instead
|
||||||
*/
|
*/
|
||||||
entities?: tl.TypeMessageEntity[]
|
entities?: tl.TypeMessageEntity[]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New message media
|
||||||
|
*/
|
||||||
|
media?: InputMediaLike
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether to disable links preview in this message
|
* Whether to disable links preview in this message
|
||||||
*/
|
*/
|
||||||
disableWebPreview?: boolean
|
disableWebPreview?: boolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For bots: inline or reply markup or an instruction
|
* For bots: new reply markup.
|
||||||
* to hide a reply keyboard or to force a reply.
|
* If omitted, existing markup will be removed.
|
||||||
*/
|
*/
|
||||||
replyMarkup?: ReplyMarkup
|
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<Message>
|
): Promise<Message>
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,10 +1,16 @@
|
||||||
import { TelegramClient } from '../../client'
|
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 { tl } from '@mtcute/tl'
|
||||||
import { normalizeToInputPeer } from '../../utils/peer-utils'
|
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 chatId ID of the chat, its username, phone or `"me"` or `"self"`
|
||||||
* @param message Message or its ID
|
* @param message Message or its ID
|
||||||
|
@ -18,6 +24,8 @@ export async function editMessage(
|
||||||
params: {
|
params: {
|
||||||
/**
|
/**
|
||||||
* New message text
|
* New message text
|
||||||
|
*
|
||||||
|
* When `media` is passed, `media.caption` is used instead
|
||||||
*/
|
*/
|
||||||
text?: string
|
text?: string
|
||||||
|
|
||||||
|
@ -34,26 +42,60 @@ export async function editMessage(
|
||||||
* parse mode.
|
* parse mode.
|
||||||
*
|
*
|
||||||
* **Note:** Passing this makes the method ignore {@link parseMode}
|
* **Note:** Passing this makes the method ignore {@link parseMode}
|
||||||
|
*
|
||||||
|
* When `media` is passed, `media.entities` is used instead
|
||||||
*/
|
*/
|
||||||
entities?: tl.TypeMessageEntity[]
|
entities?: tl.TypeMessageEntity[]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* New message media
|
||||||
|
*/
|
||||||
|
media?: InputMediaLike
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether to disable links preview in this message
|
* Whether to disable links preview in this message
|
||||||
*/
|
*/
|
||||||
disableWebPreview?: boolean
|
disableWebPreview?: boolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* For bots: inline or reply markup or an instruction
|
* For bots: new reply markup.
|
||||||
* to hide a reply keyboard or to force a reply.
|
* If omitted, existing markup will be removed.
|
||||||
*/
|
*/
|
||||||
replyMarkup?: ReplyMarkup
|
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<Message> {
|
): Promise<Message> {
|
||||||
const [content, entities] = await this._parseEntities(
|
let content: string | undefined
|
||||||
params.text,
|
let entities: tl.TypeMessageEntity[] | undefined
|
||||||
params.parseMode,
|
let media: tl.TypeInputMedia | undefined = undefined
|
||||||
params.entities
|
|
||||||
)
|
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({
|
const res = await this.call({
|
||||||
_: 'messages.editMessage',
|
_: 'messages.editMessage',
|
||||||
|
@ -63,6 +105,7 @@ export async function editMessage(
|
||||||
replyMarkup: BotKeyboard._convertToTl(params.replyMarkup),
|
replyMarkup: BotKeyboard._convertToTl(params.replyMarkup),
|
||||||
message: content,
|
message: content,
|
||||||
entities,
|
entities,
|
||||||
|
media
|
||||||
})
|
})
|
||||||
|
|
||||||
return this._findMessageInUpdate(res, true) as any
|
return this._findMessageInUpdate(res, true) as any
|
||||||
|
|
Loading…
Reference in a new issue