feat(core): basic support for quick replies
This commit is contained in:
parent
de8033e6d2
commit
a414ea9425
7 changed files with 71 additions and 5 deletions
|
@ -63,9 +63,12 @@ export function _findMessageInUpdate(
|
||||||
!(
|
!(
|
||||||
u._ === 'updateNewMessage' ||
|
u._ === 'updateNewMessage' ||
|
||||||
u._ === 'updateNewChannelMessage' ||
|
u._ === 'updateNewChannelMessage' ||
|
||||||
u._ === 'updateNewScheduledMessage'
|
u._ === 'updateNewScheduledMessage' ||
|
||||||
|
u._ === 'updateQuickReplyMessage'
|
||||||
)
|
)
|
||||||
) { continue }
|
) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// this *may* break if updateMessageID comes after the message update
|
// this *may* break if updateMessageID comes after the message update
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { InputPeerLike, Message, PeersIndex } from '../../types/index.js'
|
||||||
import { assertIsUpdatesGroup } from '../../updates/utils.js'
|
import { assertIsUpdatesGroup } from '../../updates/utils.js'
|
||||||
import { normalizeDate } from '../../utils/misc-utils.js'
|
import { normalizeDate } from '../../utils/misc-utils.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
import { resolvePeer } from '../users/resolve-peer.js'
|
||||||
|
import { _normalizeQuickReplyShortcut } from './send-common.js'
|
||||||
|
|
||||||
// @exported
|
// @exported
|
||||||
export interface ForwardMessageOptions {
|
export interface ForwardMessageOptions {
|
||||||
|
@ -56,6 +57,12 @@ export interface ForwardMessageOptions {
|
||||||
*/
|
*/
|
||||||
sendAs?: InputPeerLike
|
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
|
* Whether to dispatch the forwarded messages
|
||||||
* to the client's update handler.
|
* to the client's update handler.
|
||||||
|
@ -105,6 +112,7 @@ export async function forwardMessagesById(
|
||||||
dropMediaCaptions: noCaption,
|
dropMediaCaptions: noCaption,
|
||||||
noforwards: forbidForwards,
|
noforwards: forbidForwards,
|
||||||
sendAs: sendAs ? await resolvePeer(client, sendAs) : undefined,
|
sendAs: sendAs ? await resolvePeer(client, sendAs) : undefined,
|
||||||
|
quickReplyShortcut: _normalizeQuickReplyShortcut(params.quickReply),
|
||||||
})
|
})
|
||||||
|
|
||||||
assertIsUpdatesGroup('messages.forwardMessages', res)
|
assertIsUpdatesGroup('messages.forwardMessages', res)
|
||||||
|
|
|
@ -100,6 +100,12 @@ export interface CommonSendParams {
|
||||||
*/
|
*/
|
||||||
sendAs?: InputPeerLike
|
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
|
* Whether to dispatch the returned message
|
||||||
* to the client's update handler.
|
* to the client's update handler.
|
||||||
|
@ -107,6 +113,28 @@ export interface CommonSendParams {
|
||||||
shouldDispatch?: true
|
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
|
* @internal
|
||||||
* @noemit
|
* @noemit
|
||||||
|
@ -172,6 +200,7 @@ export async function _processCommonSendParameters(
|
||||||
peer,
|
peer,
|
||||||
replyTo: tlReplyTo,
|
replyTo: tlReplyTo,
|
||||||
scheduleDate,
|
scheduleDate,
|
||||||
|
quickReplyShortcut: _normalizeQuickReplyShortcut(params.quickReply),
|
||||||
chainId: _getPeerChainId(client, peer, 'send'),
|
chainId: _getPeerChainId(client, peer, 'send'),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,11 @@ export async function sendMediaGroup(
|
||||||
): Promise<Message[]> {
|
): Promise<Message[]> {
|
||||||
if (!params) params = {}
|
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[] = []
|
const multiMedia: tl.RawInputSingleMedia[] = []
|
||||||
|
|
||||||
|
@ -105,6 +109,7 @@ export async function sendMediaGroup(
|
||||||
noforwards: params.forbidForwards,
|
noforwards: params.forbidForwards,
|
||||||
sendAs: params.sendAs ? await resolvePeer(client, params.sendAs) : undefined,
|
sendAs: params.sendAs ? await resolvePeer(client, params.sendAs) : undefined,
|
||||||
invertMedia: params.invertMedia,
|
invertMedia: params.invertMedia,
|
||||||
|
quickReplyShortcut,
|
||||||
},
|
},
|
||||||
{ chainId },
|
{ chainId },
|
||||||
)
|
)
|
||||||
|
|
|
@ -80,7 +80,11 @@ export async function sendMedia(
|
||||||
)
|
)
|
||||||
|
|
||||||
const replyMarkup = BotKeyboard._convertToTl(params.replyMarkup)
|
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 randomId = randomLong()
|
||||||
const res = await client.call(
|
const res = await client.call(
|
||||||
|
@ -99,6 +103,7 @@ export async function sendMedia(
|
||||||
noforwards: params.forbidForwards,
|
noforwards: params.forbidForwards,
|
||||||
sendAs: params.sendAs ? await resolvePeer(client, params.sendAs) : undefined,
|
sendAs: params.sendAs ? await resolvePeer(client, params.sendAs) : undefined,
|
||||||
invertMedia: params.invert,
|
invertMedia: params.invert,
|
||||||
|
quickReplyShortcut,
|
||||||
},
|
},
|
||||||
{ chainId },
|
{ chainId },
|
||||||
)
|
)
|
||||||
|
|
|
@ -54,7 +54,11 @@ export async function sendText(
|
||||||
const [message, entities] = await _normalizeInputText(client, text)
|
const [message, entities] = await _normalizeInputText(client, text)
|
||||||
|
|
||||||
const replyMarkup = BotKeyboard._convertToTl(params.replyMarkup)
|
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 randomId = randomLong()
|
||||||
const res = await client.call(
|
const res = await client.call(
|
||||||
|
@ -73,6 +77,7 @@ export async function sendText(
|
||||||
noforwards: params.forbidForwards,
|
noforwards: params.forbidForwards,
|
||||||
sendAs: params.sendAs ? await resolvePeer(client, params.sendAs) : undefined,
|
sendAs: params.sendAs ? await resolvePeer(client, params.sendAs) : undefined,
|
||||||
invertMedia: params.invertMedia,
|
invertMedia: params.invertMedia,
|
||||||
|
quickReplyShortcut,
|
||||||
},
|
},
|
||||||
{ chainId },
|
{ chainId },
|
||||||
)
|
)
|
||||||
|
|
|
@ -213,6 +213,17 @@ export class Message {
|
||||||
return this.raw.mentioned!
|
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,
|
* If this message is generated from an inline query,
|
||||||
* information about the bot which generated it
|
* information about the bot which generated it
|
||||||
|
|
Loading…
Reference in a new issue