diff --git a/packages/core/src/highlevel/methods/messages/find-in-update.ts b/packages/core/src/highlevel/methods/messages/find-in-update.ts index 8c7f1f3c..b93a1ed5 100644 --- a/packages/core/src/highlevel/methods/messages/find-in-update.ts +++ b/packages/core/src/highlevel/methods/messages/find-in-update.ts @@ -63,9 +63,12 @@ export function _findMessageInUpdate( !( u._ === 'updateNewMessage' || u._ === 'updateNewChannelMessage' || - u._ === 'updateNewScheduledMessage' + u._ === 'updateNewScheduledMessage' || + u._ === 'updateQuickReplyMessage' ) - ) { continue } + ) { + continue + } } // this *may* break if updateMessageID comes after the message update diff --git a/packages/core/src/highlevel/methods/messages/forward-messages.ts b/packages/core/src/highlevel/methods/messages/forward-messages.ts index a108f586..88a80924 100644 --- a/packages/core/src/highlevel/methods/messages/forward-messages.ts +++ b/packages/core/src/highlevel/methods/messages/forward-messages.ts @@ -5,6 +5,7 @@ import { InputPeerLike, Message, PeersIndex } from '../../types/index.js' import { assertIsUpdatesGroup } from '../../updates/utils.js' import { normalizeDate } from '../../utils/misc-utils.js' import { resolvePeer } from '../users/resolve-peer.js' +import { _normalizeQuickReplyShortcut } from './send-common.js' // @exported export interface ForwardMessageOptions { @@ -56,6 +57,12 @@ export interface ForwardMessageOptions { */ sendAs?: InputPeerLike + /** + * If passed, instead of sending the message, it will be saved into the + * given quick reply shortcut (either its ID or its shortcut string). + */ + quickReply?: number | string + /** * Whether to dispatch the forwarded messages * to the client's update handler. @@ -105,6 +112,7 @@ export async function forwardMessagesById( dropMediaCaptions: noCaption, noforwards: forbidForwards, sendAs: sendAs ? await resolvePeer(client, sendAs) : undefined, + quickReplyShortcut: _normalizeQuickReplyShortcut(params.quickReply), }) assertIsUpdatesGroup('messages.forwardMessages', res) diff --git a/packages/core/src/highlevel/methods/messages/send-common.ts b/packages/core/src/highlevel/methods/messages/send-common.ts index e5ef2d62..40a64c9d 100644 --- a/packages/core/src/highlevel/methods/messages/send-common.ts +++ b/packages/core/src/highlevel/methods/messages/send-common.ts @@ -100,6 +100,12 @@ export interface CommonSendParams { */ sendAs?: InputPeerLike + /** + * If passed, instead of sending the message, it will be saved into the + * given quick reply shortcut (either its ID or its shortcut string). + */ + quickReply?: number | string + /** * Whether to dispatch the returned message * to the client's update handler. @@ -107,6 +113,28 @@ export interface CommonSendParams { shouldDispatch?: true } +/** + * @internal + * @noemit + */ +export function _normalizeQuickReplyShortcut( + shortcut: number | string | undefined, +): tl.TypeInputQuickReplyShortcut | undefined { + if (!shortcut) return undefined + + if (typeof shortcut === 'number') { + return { + _: 'inputQuickReplyShortcutId', + shortcutId: shortcut, + } + } + + return { + _: 'inputQuickReplyShortcut', + shortcut, + } +} + /** * @internal * @noemit @@ -172,6 +200,7 @@ export async function _processCommonSendParameters( peer, replyTo: tlReplyTo, scheduleDate, + quickReplyShortcut: _normalizeQuickReplyShortcut(params.quickReply), chainId: _getPeerChainId(client, peer, 'send'), } } diff --git a/packages/core/src/highlevel/methods/messages/send-media-group.ts b/packages/core/src/highlevel/methods/messages/send-media-group.ts index b36a7529..caad0bb8 100644 --- a/packages/core/src/highlevel/methods/messages/send-media-group.ts +++ b/packages/core/src/highlevel/methods/messages/send-media-group.ts @@ -50,7 +50,11 @@ export async function sendMediaGroup( ): Promise { if (!params) params = {} - const { peer, replyTo, scheduleDate, chainId } = await _processCommonSendParameters(client, chatId, params) + const { peer, replyTo, scheduleDate, chainId, quickReplyShortcut } = await _processCommonSendParameters( + client, + chatId, + params, + ) const multiMedia: tl.RawInputSingleMedia[] = [] @@ -105,6 +109,7 @@ export async function sendMediaGroup( noforwards: params.forbidForwards, sendAs: params.sendAs ? await resolvePeer(client, params.sendAs) : undefined, invertMedia: params.invertMedia, + quickReplyShortcut, }, { chainId }, ) diff --git a/packages/core/src/highlevel/methods/messages/send-media.ts b/packages/core/src/highlevel/methods/messages/send-media.ts index edf13dde..04960af0 100644 --- a/packages/core/src/highlevel/methods/messages/send-media.ts +++ b/packages/core/src/highlevel/methods/messages/send-media.ts @@ -80,7 +80,11 @@ export async function sendMedia( ) const replyMarkup = BotKeyboard._convertToTl(params.replyMarkup) - const { peer, replyTo, scheduleDate, chainId } = await _processCommonSendParameters(client, chatId, params) + const { peer, replyTo, scheduleDate, chainId, quickReplyShortcut } = await _processCommonSendParameters( + client, + chatId, + params, + ) const randomId = randomLong() const res = await client.call( @@ -99,6 +103,7 @@ export async function sendMedia( noforwards: params.forbidForwards, sendAs: params.sendAs ? await resolvePeer(client, params.sendAs) : undefined, invertMedia: params.invert, + quickReplyShortcut, }, { chainId }, ) diff --git a/packages/core/src/highlevel/methods/messages/send-text.ts b/packages/core/src/highlevel/methods/messages/send-text.ts index aa571d42..8ba178f3 100644 --- a/packages/core/src/highlevel/methods/messages/send-text.ts +++ b/packages/core/src/highlevel/methods/messages/send-text.ts @@ -54,7 +54,11 @@ export async function sendText( const [message, entities] = await _normalizeInputText(client, text) const replyMarkup = BotKeyboard._convertToTl(params.replyMarkup) - const { peer, replyTo, scheduleDate, chainId } = await _processCommonSendParameters(client, chatId, params) + const { peer, replyTo, scheduleDate, chainId, quickReplyShortcut } = await _processCommonSendParameters( + client, + chatId, + params, + ) const randomId = randomLong() const res = await client.call( @@ -73,6 +77,7 @@ export async function sendText( noforwards: params.forbidForwards, sendAs: params.sendAs ? await resolvePeer(client, params.sendAs) : undefined, invertMedia: params.invertMedia, + quickReplyShortcut, }, { chainId }, ) diff --git a/packages/core/src/highlevel/types/messages/message.ts b/packages/core/src/highlevel/types/messages/message.ts index 149755e8..77829d51 100644 --- a/packages/core/src/highlevel/types/messages/message.ts +++ b/packages/core/src/highlevel/types/messages/message.ts @@ -213,6 +213,17 @@ export class Message { return this.raw.mentioned! } + /** + * If non-null, this message is not actually sent, and is + * instead inside a group of "quick reply" messages + * under the given shortcut ID + */ + get quickReplyShortcutId(): number | null { + if (this.raw._ === 'messageService') return null + + return this.raw.quickReplyShortcutId ?? null + } + /** * If this message is generated from an inline query, * information about the bot which generated it