feat(client): mustReply parameter
This commit is contained in:
parent
d5e595d7cf
commit
afd6f54e54
4 changed files with 106 additions and 2 deletions
|
@ -2399,6 +2399,19 @@ export interface TelegramClient extends BaseTelegramClient {
|
||||||
*/
|
*/
|
||||||
replyTo?: number | Message
|
replyTo?: number | Message
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to throw an error if {@link replyTo}
|
||||||
|
* message does not exist.
|
||||||
|
*
|
||||||
|
* If that message was not found, `NotFoundError` is thrown,
|
||||||
|
* with `text` set to `MESSAGE_NOT_FOUND`.
|
||||||
|
*
|
||||||
|
* Incurs an additional request, so only use when really needed.
|
||||||
|
*
|
||||||
|
* Defaults to `false`
|
||||||
|
*/
|
||||||
|
mustReply?: boolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of formatting entities to use instead of parsing via a
|
* List of formatting entities to use instead of parsing via a
|
||||||
* parse mode.
|
* parse mode.
|
||||||
|
@ -2441,6 +2454,19 @@ export interface TelegramClient extends BaseTelegramClient {
|
||||||
*/
|
*/
|
||||||
replyTo?: number | Message
|
replyTo?: number | Message
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to throw an error if {@link replyTo}
|
||||||
|
* message does not exist.
|
||||||
|
*
|
||||||
|
* If that message was not found, `NotFoundError` is thrown,
|
||||||
|
* with `text` set to `MESSAGE_NOT_FOUND`.
|
||||||
|
*
|
||||||
|
* Incurs an additional request, so only use when really needed.
|
||||||
|
*
|
||||||
|
* Defaults to `false`
|
||||||
|
*/
|
||||||
|
mustReply?: boolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Message to comment to. Either a message object or message ID.
|
* Message to comment to. Either a message object or message ID.
|
||||||
*
|
*
|
||||||
|
@ -2535,6 +2561,19 @@ export interface TelegramClient extends BaseTelegramClient {
|
||||||
*/
|
*/
|
||||||
replyTo?: number | Message
|
replyTo?: number | Message
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to throw an error if {@link replyTo}
|
||||||
|
* message does not exist.
|
||||||
|
*
|
||||||
|
* If that message was not found, `NotFoundError` is thrown,
|
||||||
|
* with `text` set to `MESSAGE_NOT_FOUND`.
|
||||||
|
*
|
||||||
|
* Incurs an additional request, so only use when really needed.
|
||||||
|
*
|
||||||
|
* Defaults to `false`
|
||||||
|
*/
|
||||||
|
mustReply?: boolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Message to comment to. Either a message object or message ID.
|
* Message to comment to. Either a message object or message ID.
|
||||||
*
|
*
|
||||||
|
|
|
@ -60,6 +60,19 @@ export async function sendCopy(
|
||||||
*/
|
*/
|
||||||
replyTo?: number | Message
|
replyTo?: number | Message
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to throw an error if {@link replyTo}
|
||||||
|
* message does not exist.
|
||||||
|
*
|
||||||
|
* If that message was not found, `NotFoundError` is thrown,
|
||||||
|
* with `text` set to `MESSAGE_NOT_FOUND`.
|
||||||
|
*
|
||||||
|
* Incurs an additional request, so only use when really needed.
|
||||||
|
*
|
||||||
|
* Defaults to `false`
|
||||||
|
*/
|
||||||
|
mustReply?: boolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of formatting entities to use instead of parsing via a
|
* List of formatting entities to use instead of parsing via a
|
||||||
* parse mode.
|
* parse mode.
|
||||||
|
|
|
@ -3,7 +3,7 @@ import {
|
||||||
BotKeyboard, InputFileLike,
|
BotKeyboard, InputFileLike,
|
||||||
InputMediaLike,
|
InputMediaLike,
|
||||||
InputPeerLike,
|
InputPeerLike,
|
||||||
Message,
|
Message, MtCuteArgumentError,
|
||||||
ReplyMarkup,
|
ReplyMarkup,
|
||||||
} from '../../types'
|
} from '../../types'
|
||||||
import {
|
import {
|
||||||
|
@ -14,6 +14,7 @@ import {
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
|
import { assertIsUpdatesGroup } from '../../utils/updates-utils'
|
||||||
import { createUsersChatsIndex } from '../../utils/peer-utils'
|
import { createUsersChatsIndex } from '../../utils/peer-utils'
|
||||||
|
import { MessageNotFoundError } from '@mtcute/tl/errors'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a group of media.
|
* Send a group of media.
|
||||||
|
@ -37,6 +38,19 @@ export async function sendMediaGroup(
|
||||||
*/
|
*/
|
||||||
replyTo?: number | Message
|
replyTo?: number | Message
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to throw an error if {@link replyTo}
|
||||||
|
* message does not exist.
|
||||||
|
*
|
||||||
|
* If that message was not found, `NotFoundError` is thrown,
|
||||||
|
* with `text` set to `MESSAGE_NOT_FOUND`.
|
||||||
|
*
|
||||||
|
* Incurs an additional request, so only use when really needed.
|
||||||
|
*
|
||||||
|
* Defaults to `false`
|
||||||
|
*/
|
||||||
|
mustReply?: boolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Message to comment to. Either a message object or message ID.
|
* Message to comment to. Either a message object or message ID.
|
||||||
*
|
*
|
||||||
|
@ -108,6 +122,18 @@ export async function sendMediaGroup(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (params.mustReply) {
|
||||||
|
if (!replyTo)
|
||||||
|
throw new MtCuteArgumentError(
|
||||||
|
'mustReply used, but replyTo was not passed'
|
||||||
|
)
|
||||||
|
|
||||||
|
const msg = await this.getMessages(peer, replyTo)
|
||||||
|
|
||||||
|
if (!msg)
|
||||||
|
throw new MessageNotFoundError()
|
||||||
|
}
|
||||||
|
|
||||||
const multiMedia: tl.RawInputSingleMedia[] = []
|
const multiMedia: tl.RawInputSingleMedia[] = []
|
||||||
|
|
||||||
for (let i = 0; i < medias.length; i++) {
|
for (let i = 0; i < medias.length; i++) {
|
||||||
|
|
|
@ -3,7 +3,7 @@ import {
|
||||||
BotKeyboard,
|
BotKeyboard,
|
||||||
InputMediaLike,
|
InputMediaLike,
|
||||||
InputPeerLike,
|
InputPeerLike,
|
||||||
Message,
|
Message, MtCuteArgumentError,
|
||||||
ReplyMarkup,
|
ReplyMarkup,
|
||||||
} from '../../types'
|
} from '../../types'
|
||||||
import {
|
import {
|
||||||
|
@ -12,6 +12,7 @@ import {
|
||||||
randomUlong,
|
randomUlong,
|
||||||
} from '../../utils/misc-utils'
|
} from '../../utils/misc-utils'
|
||||||
import { tl } from '@mtcute/tl'
|
import { tl } from '@mtcute/tl'
|
||||||
|
import { MessageNotFoundError } from '@mtcute/tl/errors'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Send a single media (a photo or a document-based media)
|
* Send a single media (a photo or a document-based media)
|
||||||
|
@ -51,6 +52,19 @@ export async function sendMedia(
|
||||||
*/
|
*/
|
||||||
replyTo?: number | Message
|
replyTo?: number | Message
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether to throw an error if {@link replyTo}
|
||||||
|
* message does not exist.
|
||||||
|
*
|
||||||
|
* If that message was not found, `NotFoundError` is thrown,
|
||||||
|
* with `text` set to `MESSAGE_NOT_FOUND`.
|
||||||
|
*
|
||||||
|
* Incurs an additional request, so only use when really needed.
|
||||||
|
*
|
||||||
|
* Defaults to `false`
|
||||||
|
*/
|
||||||
|
mustReply?: boolean
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Message to comment to. Either a message object or message ID.
|
* Message to comment to. Either a message object or message ID.
|
||||||
*
|
*
|
||||||
|
@ -135,6 +149,18 @@ export async function sendMedia(
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (params.mustReply) {
|
||||||
|
if (!replyTo)
|
||||||
|
throw new MtCuteArgumentError(
|
||||||
|
'mustReply used, but replyTo was not passed'
|
||||||
|
)
|
||||||
|
|
||||||
|
const msg = await this.getMessages(peer, replyTo)
|
||||||
|
|
||||||
|
if (!msg)
|
||||||
|
throw new MessageNotFoundError()
|
||||||
|
}
|
||||||
|
|
||||||
const res = await this.call({
|
const res = await this.call({
|
||||||
_: 'messages.sendMedia',
|
_: 'messages.sendMedia',
|
||||||
peer,
|
peer,
|
||||||
|
|
Loading…
Reference in a new issue