feat(client): support more service messages
This commit is contained in:
parent
977527b78a
commit
e28ec79110
2 changed files with 434 additions and 144 deletions
42
packages/client/src/types/calls/discard-reason.ts
Normal file
42
packages/client/src/types/calls/discard-reason.ts
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
/**
|
||||||
|
* Phone call discard reason. Can be:
|
||||||
|
* - `missed`: The call was missed
|
||||||
|
* - `disconnect`: The connection has interrupted
|
||||||
|
* - `hangup`: The call was ended normally
|
||||||
|
* - `busy`: The call was discarded because the user is in another call
|
||||||
|
*/
|
||||||
|
import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
|
export type CallDiscardReason = 'missed' | 'disconnect' | 'hangup' | 'busy'
|
||||||
|
|
||||||
|
/** @internal */
|
||||||
|
export function _callDiscardReasonFromTl(
|
||||||
|
raw: tl.TypePhoneCallDiscardReason
|
||||||
|
): CallDiscardReason {
|
||||||
|
switch (raw._) {
|
||||||
|
case 'phoneCallDiscardReasonMissed':
|
||||||
|
return 'missed'
|
||||||
|
case 'phoneCallDiscardReasonDisconnect':
|
||||||
|
return 'disconnect'
|
||||||
|
case 'phoneCallDiscardReasonHangup':
|
||||||
|
return 'hangup'
|
||||||
|
case 'phoneCallDiscardReasonBusy':
|
||||||
|
return 'busy'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @internal */
|
||||||
|
export function _callDiscardReasonToTl(
|
||||||
|
r: CallDiscardReason
|
||||||
|
): tl.TypePhoneCallDiscardReason {
|
||||||
|
switch (r) {
|
||||||
|
case 'missed':
|
||||||
|
return { _: 'phoneCallDiscardReasonMissed' }
|
||||||
|
case 'disconnect':
|
||||||
|
return { _: 'phoneCallDiscardReasonDisconnect' }
|
||||||
|
case 'hangup':
|
||||||
|
return { _: 'phoneCallDiscardReasonHangup' }
|
||||||
|
case 'busy':
|
||||||
|
return { _: 'phoneCallDiscardReasonBusy' }
|
||||||
|
}
|
||||||
|
}
|
|
@ -29,6 +29,10 @@ import {
|
||||||
WebPage,
|
WebPage,
|
||||||
} from '../media'
|
} from '../media'
|
||||||
import { parseDocument } from '../media/document-utils'
|
import { parseDocument } from '../media/document-utils'
|
||||||
|
import {
|
||||||
|
_callDiscardReasonFromTl,
|
||||||
|
CallDiscardReason,
|
||||||
|
} from '../calls/discard-reason'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A message or a service message
|
* A message or a service message
|
||||||
|
@ -152,6 +156,134 @@ export namespace Message {
|
||||||
readonly inviter: number
|
readonly inviter: number
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** A payment was received from a user (bot) */
|
||||||
|
export interface ActionPaymentReceived {
|
||||||
|
readonly type: 'payment_received'
|
||||||
|
|
||||||
|
/** Three-letter ISO 4217 currency code */
|
||||||
|
readonly currency: string
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Price of the product in the smallest units of the currency
|
||||||
|
* (integer, not float/double). For example, for a price of
|
||||||
|
* `US$ 1.45`, `amount = 145`
|
||||||
|
*/
|
||||||
|
readonly amount: tl.Long
|
||||||
|
|
||||||
|
/** Bot specified invoice payload */
|
||||||
|
readonly payload: Buffer
|
||||||
|
|
||||||
|
/** Order information provided by the user */
|
||||||
|
readonly info?: tl.TypePaymentRequestedInfo
|
||||||
|
|
||||||
|
/** ID of the shipping option chosen by the user */
|
||||||
|
readonly shippingOptionId?: string
|
||||||
|
|
||||||
|
/** Payment provider ID */
|
||||||
|
readonly charge?: tl.TypePaymentCharge
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A payment was sent to a user */
|
||||||
|
export interface ActionPaymentSent {
|
||||||
|
readonly type: 'payment_sent'
|
||||||
|
|
||||||
|
/** Three-letter ISO 4217 currency code */
|
||||||
|
readonly currency: string
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Price of the product in the smallest units of the currency
|
||||||
|
* (integer, not float/double). For example, for a price of
|
||||||
|
* `US$ 1.45`, `amount = 145`
|
||||||
|
*/
|
||||||
|
readonly amount: tl.Long
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A phone call */
|
||||||
|
export interface ActionCall {
|
||||||
|
readonly type: 'call'
|
||||||
|
|
||||||
|
/** Call ID */
|
||||||
|
readonly id: tl.Long
|
||||||
|
|
||||||
|
/** Whether this is a video call */
|
||||||
|
readonly isVideo: boolean
|
||||||
|
|
||||||
|
/** Duration if the call in seconds (0 if not available) */
|
||||||
|
readonly duration: number
|
||||||
|
|
||||||
|
/** Call discard reason, if available */
|
||||||
|
readonly reason?: CallDiscardReason
|
||||||
|
}
|
||||||
|
|
||||||
|
/** A screenshot was taken */
|
||||||
|
export interface ActionScreenshotTaken {
|
||||||
|
readonly type: 'screenshot_taken'
|
||||||
|
}
|
||||||
|
|
||||||
|
/** User has authorized via the bot */
|
||||||
|
export interface ActionBotAllowed {
|
||||||
|
readonly type: 'bot_allowed'
|
||||||
|
|
||||||
|
/** Domain where the user has logged in */
|
||||||
|
readonly domain: string
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A user is in proximity of another user
|
||||||
|
* (see [Proximity alerts]{https://core.telegram.org/api/live-location#proximity-alert})
|
||||||
|
*/
|
||||||
|
export interface ActionGeoProximity {
|
||||||
|
readonly type: 'geo_proximity'
|
||||||
|
|
||||||
|
/** ID of the user who sent the geolocation with proximity alerts */
|
||||||
|
readonly targetId: number
|
||||||
|
|
||||||
|
/** ID of the user who has approached `targetId` */
|
||||||
|
readonly userId: number
|
||||||
|
|
||||||
|
/** Distance between them in meters */
|
||||||
|
readonly distance: number
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Group call has started */
|
||||||
|
export interface ActionGroupCallStarted {
|
||||||
|
readonly type: 'group_call_started'
|
||||||
|
|
||||||
|
/** TL object representing the call */
|
||||||
|
readonly call: tl.TypeInputGroupCall
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Group call has ended */
|
||||||
|
export interface ActionGroupCallEnded {
|
||||||
|
readonly type: 'group_call_ended'
|
||||||
|
|
||||||
|
/** TL object representing the call */
|
||||||
|
readonly call: tl.TypeInputGroupCall
|
||||||
|
|
||||||
|
/** Duration of the call */
|
||||||
|
readonly duration: number
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Group call has ended */
|
||||||
|
export interface ActionGroupInvite {
|
||||||
|
readonly type: 'group_call_invite'
|
||||||
|
|
||||||
|
/** TL object representing the call */
|
||||||
|
readonly call: tl.TypeInputGroupCall
|
||||||
|
|
||||||
|
/** IDs of the users invited to the call */
|
||||||
|
readonly userIds: number[]
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Messages TTL changed */
|
||||||
|
export interface ActionSetTtl {
|
||||||
|
readonly type: 'set_ttl'
|
||||||
|
|
||||||
|
/** New TTL period */
|
||||||
|
readonly period: number
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Information about a forward */
|
||||||
export interface MessageForwardInfo {
|
export interface MessageForwardInfo {
|
||||||
/**
|
/**
|
||||||
* Date the original message was sent
|
* Date the original message was sent
|
||||||
|
@ -193,6 +325,16 @@ export namespace Message {
|
||||||
| ActionUserLeft
|
| ActionUserLeft
|
||||||
| ActionUserRemoved
|
| ActionUserRemoved
|
||||||
| ActionUserJoinedLink
|
| ActionUserJoinedLink
|
||||||
|
| ActionPaymentReceived
|
||||||
|
| ActionPaymentSent
|
||||||
|
| ActionCall
|
||||||
|
| ActionScreenshotTaken
|
||||||
|
| ActionBotAllowed
|
||||||
|
| ActionGeoProximity
|
||||||
|
| ActionGroupCallStarted
|
||||||
|
| ActionGroupCallEnded
|
||||||
|
| ActionGroupInvite
|
||||||
|
| ActionSetTtl
|
||||||
| null
|
| null
|
||||||
|
|
||||||
// todo: venue, poll, invoice, successful_payment,
|
// todo: venue, poll, invoice, successful_payment,
|
||||||
|
@ -250,7 +392,7 @@ export class Message {
|
||||||
raw: tl.TypeMessage,
|
raw: tl.TypeMessage,
|
||||||
users: Record<number, tl.TypeUser>,
|
users: Record<number, tl.TypeUser>,
|
||||||
chats: Record<number, tl.TypeChat>,
|
chats: Record<number, tl.TypeChat>,
|
||||||
isScheduled = false,
|
isScheduled = false
|
||||||
) {
|
) {
|
||||||
this.client = client
|
this.client = client
|
||||||
this._users = users
|
this._users = users
|
||||||
|
@ -352,18 +494,15 @@ export class Message {
|
||||||
// forwarded channel post
|
// forwarded channel post
|
||||||
this._sender = new Chat(
|
this._sender = new Chat(
|
||||||
this.client,
|
this.client,
|
||||||
this._chats[from.channelId],
|
this._chats[from.channelId]
|
||||||
)
|
)
|
||||||
} else if (from._ === 'peerUser') {
|
} else if (from._ === 'peerUser') {
|
||||||
this._sender = new User(
|
this._sender = new User(this.client, this._users[from.userId])
|
||||||
this.client,
|
|
||||||
this._users[from.userId],
|
|
||||||
)
|
|
||||||
} else
|
} else
|
||||||
throw new MtCuteTypeAssertionError(
|
throw new MtCuteTypeAssertionError(
|
||||||
'Message#sender (@ raw.fromId)',
|
'Message#sender (@ raw.fromId)',
|
||||||
'peerUser | peerChannel',
|
'peerUser | peerChannel',
|
||||||
from._,
|
from._
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383,7 +522,7 @@ export class Message {
|
||||||
this.client,
|
this.client,
|
||||||
this.raw,
|
this.raw,
|
||||||
this._users,
|
this._users,
|
||||||
this._chats,
|
this._chats
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -420,18 +559,18 @@ export class Message {
|
||||||
if (fwd.fromId._ === 'peerChannel') {
|
if (fwd.fromId._ === 'peerChannel') {
|
||||||
sender = new Chat(
|
sender = new Chat(
|
||||||
this.client,
|
this.client,
|
||||||
this._chats[fwd.fromId.channelId],
|
this._chats[fwd.fromId.channelId]
|
||||||
)
|
)
|
||||||
} else if (fwd.fromId._ === 'peerUser') {
|
} else if (fwd.fromId._ === 'peerUser') {
|
||||||
sender = new User(
|
sender = new User(
|
||||||
this.client,
|
this.client,
|
||||||
this._users[fwd.fromId.userId],
|
this._users[fwd.fromId.userId]
|
||||||
)
|
)
|
||||||
} else
|
} else
|
||||||
throw new MtCuteTypeAssertionError(
|
throw new MtCuteTypeAssertionError(
|
||||||
'Message#forward (@ raw.fwdFrom.fromId)',
|
'Message#forward (@ raw.fwdFrom.fromId)',
|
||||||
'peerUser | peerChannel',
|
'peerUser | peerChannel',
|
||||||
fwd.fromId._,
|
fwd.fromId._
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
this._forward = null
|
this._forward = null
|
||||||
|
@ -483,7 +622,7 @@ export class Message {
|
||||||
} else {
|
} else {
|
||||||
this._viaBot = new User(
|
this._viaBot = new User(
|
||||||
this.client,
|
this.client,
|
||||||
this._users[this.raw.viaBotId],
|
this._users[this.raw.viaBotId]
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -538,66 +677,82 @@ export class Message {
|
||||||
const act = this.raw.action
|
const act = this.raw.action
|
||||||
let action: Message.MessageAction
|
let action: Message.MessageAction
|
||||||
|
|
||||||
if (act._ === 'messageActionChatCreate') {
|
switch (act._) {
|
||||||
|
case 'messageActionChatCreate':
|
||||||
action = {
|
action = {
|
||||||
type: 'chat_created',
|
type: 'chat_created',
|
||||||
title: act.title,
|
title: act.title,
|
||||||
users: act.users,
|
users: act.users,
|
||||||
}
|
}
|
||||||
} else if (act._ === 'messageActionChannelCreate') {
|
break
|
||||||
|
case 'messageActionChannelCreate':
|
||||||
action = {
|
action = {
|
||||||
type: 'channel_created',
|
type: 'channel_created',
|
||||||
title: act.title,
|
title: act.title,
|
||||||
}
|
}
|
||||||
} else if (act._ === 'messageActionChatMigrateTo') {
|
break
|
||||||
|
case 'messageActionChatMigrateTo':
|
||||||
action = {
|
action = {
|
||||||
type: 'chat_migrate_to',
|
type: 'chat_migrate_to',
|
||||||
id: act.channelId,
|
id: act.channelId,
|
||||||
}
|
}
|
||||||
} else if (act._ === 'messageActionChannelMigrateFrom') {
|
break
|
||||||
|
case 'messageActionChannelMigrateFrom':
|
||||||
action = {
|
action = {
|
||||||
type: 'channel_migrate_from',
|
type: 'channel_migrate_from',
|
||||||
id: act.chatId,
|
id: act.chatId,
|
||||||
title: act.title,
|
title: act.title,
|
||||||
}
|
}
|
||||||
} else if (act._ === 'messageActionPinMessage') {
|
break
|
||||||
|
case 'messageActionPinMessage':
|
||||||
action = {
|
action = {
|
||||||
type: 'message_pinned',
|
type: 'message_pinned',
|
||||||
}
|
}
|
||||||
} else if (act._ === 'messageActionHistoryClear') {
|
break
|
||||||
|
case 'messageActionHistoryClear':
|
||||||
action = {
|
action = {
|
||||||
type: 'history_cleared',
|
type: 'history_cleared',
|
||||||
}
|
}
|
||||||
} else if (act._ === 'messageActionGameScore') {
|
break
|
||||||
|
case 'messageActionGameScore':
|
||||||
action = {
|
action = {
|
||||||
type: 'game_score',
|
type: 'game_score',
|
||||||
gameId: act.gameId,
|
gameId: act.gameId,
|
||||||
score: act.score,
|
score: act.score,
|
||||||
}
|
}
|
||||||
} else if (act._ === 'messageActionContactSignUp') {
|
break
|
||||||
|
case 'messageActionContactSignUp':
|
||||||
action = {
|
action = {
|
||||||
type: 'contact_joined',
|
type: 'contact_joined',
|
||||||
}
|
}
|
||||||
} else if (act._ === 'messageActionChatEditTitle') {
|
break
|
||||||
|
case 'messageActionChatEditTitle':
|
||||||
action = {
|
action = {
|
||||||
type: 'title_changed',
|
type: 'title_changed',
|
||||||
title: act.title,
|
title: act.title,
|
||||||
}
|
}
|
||||||
} else if (act._ === 'messageActionChatEditPhoto') {
|
break
|
||||||
|
case 'messageActionChatEditPhoto':
|
||||||
action = {
|
action = {
|
||||||
type: 'photo_changed',
|
type: 'photo_changed',
|
||||||
photo: new Photo(this.client, act.photo as tl.RawPhoto),
|
photo: new Photo(
|
||||||
|
this.client,
|
||||||
|
act.photo as tl.RawPhoto
|
||||||
|
),
|
||||||
}
|
}
|
||||||
} else if (act._ === 'messageActionChatDeletePhoto') {
|
break
|
||||||
|
case 'messageActionChatDeletePhoto':
|
||||||
action = {
|
action = {
|
||||||
type: 'photo_deleted',
|
type: 'photo_deleted',
|
||||||
}
|
}
|
||||||
} else if (act._ === 'messageActionChatAddUser') {
|
break
|
||||||
|
case 'messageActionChatAddUser':
|
||||||
action = {
|
action = {
|
||||||
type: 'users_added',
|
type: 'users_added',
|
||||||
users: act.users,
|
users: act.users,
|
||||||
}
|
}
|
||||||
} else if (act._ === 'messageActionChatDeleteUser') {
|
break
|
||||||
|
case 'messageActionChatDeleteUser':
|
||||||
if (
|
if (
|
||||||
this.raw.fromId?._ === 'peerUser' &&
|
this.raw.fromId?._ === 'peerUser' &&
|
||||||
act.userId === this.raw.fromId.userId
|
act.userId === this.raw.fromId.userId
|
||||||
|
@ -611,13 +766,95 @@ export class Message {
|
||||||
user: act.userId,
|
user: act.userId,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (act._ === 'messageActionChatJoinedByLink') {
|
break
|
||||||
|
case 'messageActionChatJoinedByLink':
|
||||||
action = {
|
action = {
|
||||||
type: 'user_joined_link',
|
type: 'user_joined_link',
|
||||||
inviter: act.inviterId,
|
inviter: act.inviterId,
|
||||||
}
|
}
|
||||||
} else {
|
break
|
||||||
|
case 'messageActionPaymentSentMe':
|
||||||
|
action = {
|
||||||
|
type: 'payment_received',
|
||||||
|
currency: act.currency,
|
||||||
|
amount: act.totalAmount,
|
||||||
|
payload: act.payload,
|
||||||
|
info: act.info,
|
||||||
|
shippingOptionId: act.shippingOptionId,
|
||||||
|
charge: act.charge,
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case 'messageActionPaymentSent':
|
||||||
|
action = {
|
||||||
|
type: 'payment_sent',
|
||||||
|
currency: act.currency,
|
||||||
|
amount: act.totalAmount,
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case 'messageActionPhoneCall':
|
||||||
|
action = {
|
||||||
|
type: 'call',
|
||||||
|
id: act.callId,
|
||||||
|
isVideo: !!act.video,
|
||||||
|
reason: act.reason
|
||||||
|
? _callDiscardReasonFromTl(act.reason)
|
||||||
|
: undefined,
|
||||||
|
duration: act.duration ?? 0,
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case 'messageActionScreenshotTaken':
|
||||||
|
action = {
|
||||||
|
type: 'screenshot_taken'
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case 'messageActionBotAllowed':
|
||||||
|
action = {
|
||||||
|
type: 'bot_allowed',
|
||||||
|
domain: act.domain
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case 'messageActionGeoProximityReached':
|
||||||
|
if (act.fromId._ !== 'peerUser' || act.toId._ !== 'peerUser') {
|
||||||
action = null
|
action = null
|
||||||
|
} else {
|
||||||
|
action = {
|
||||||
|
type: 'geo_proximity',
|
||||||
|
targetId: act.toId.userId,
|
||||||
|
userId: act.fromId.userId,
|
||||||
|
distance: act.distance
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case 'messageActionGroupCall':
|
||||||
|
if (act.duration) {
|
||||||
|
action = {
|
||||||
|
type: 'group_call_ended',
|
||||||
|
call: act.call,
|
||||||
|
duration: act.duration
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
action = {
|
||||||
|
type: 'group_call_started',
|
||||||
|
call: act.call
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case 'messageActionInviteToGroupCall':
|
||||||
|
action = {
|
||||||
|
type: 'group_call_invite',
|
||||||
|
call: act.call,
|
||||||
|
userIds: act.users
|
||||||
|
}
|
||||||
|
break
|
||||||
|
case 'messageActionSetMessagesTTL':
|
||||||
|
action = {
|
||||||
|
type: 'set_ttl',
|
||||||
|
period: act.period
|
||||||
|
}
|
||||||
|
break
|
||||||
|
default:
|
||||||
|
action = null
|
||||||
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
this._action = action
|
this._action = action
|
||||||
|
@ -676,7 +913,12 @@ export class Message {
|
||||||
} else if (m._ === 'messageMediaVenue') {
|
} else if (m._ === 'messageMediaVenue') {
|
||||||
media = new Venue(this.client, m)
|
media = new Venue(this.client, m)
|
||||||
} else if (m._ === 'messageMediaPoll') {
|
} else if (m._ === 'messageMediaPoll') {
|
||||||
media = new Poll(this.client, m.poll, this._users, m.results)
|
media = new Poll(
|
||||||
|
this.client,
|
||||||
|
m.poll,
|
||||||
|
this._users,
|
||||||
|
m.results
|
||||||
|
)
|
||||||
} else if (m._ === 'messageMediaInvoice') {
|
} else if (m._ === 'messageMediaInvoice') {
|
||||||
media = new Invoice(this.client, m)
|
media = new Invoice(this.client, m)
|
||||||
} else {
|
} else {
|
||||||
|
@ -751,7 +993,7 @@ export class Message {
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new MtCuteArgumentError(
|
throw new MtCuteArgumentError(
|
||||||
`Cannot generate message link for ${this.chat.type}`,
|
`Cannot generate message link for ${this.chat.type}`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -793,13 +1035,11 @@ export class Message {
|
||||||
replyText(
|
replyText(
|
||||||
text: string,
|
text: string,
|
||||||
visible = false,
|
visible = false,
|
||||||
params?: Parameters<TelegramClient['sendText']>[2],
|
params?: Parameters<TelegramClient['sendText']>[2]
|
||||||
): ReturnType<TelegramClient['sendText']> {
|
): ReturnType<TelegramClient['sendText']> {
|
||||||
if (visible) {
|
if (visible) {
|
||||||
return this.client.sendText(this.chat.inputPeer, text, {
|
return this.client.sendText(this.chat.inputPeer, text, {
|
||||||
...(
|
...(params || {}),
|
||||||
params || {}
|
|
||||||
),
|
|
||||||
replyTo: this.id,
|
replyTo: this.id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -819,13 +1059,11 @@ export class Message {
|
||||||
replyMedia(
|
replyMedia(
|
||||||
media: InputMediaLike,
|
media: InputMediaLike,
|
||||||
visible = false,
|
visible = false,
|
||||||
params?: Parameters<TelegramClient['sendMedia']>[2],
|
params?: Parameters<TelegramClient['sendMedia']>[2]
|
||||||
): ReturnType<TelegramClient['sendMedia']> {
|
): ReturnType<TelegramClient['sendMedia']> {
|
||||||
if (visible) {
|
if (visible) {
|
||||||
return this.client.sendMedia(this.chat.inputPeer, media, {
|
return this.client.sendMedia(this.chat.inputPeer, media, {
|
||||||
...(
|
...(params || {}),
|
||||||
params || {}
|
|
||||||
),
|
|
||||||
replyTo: this.id,
|
replyTo: this.id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -848,7 +1086,12 @@ export class Message {
|
||||||
* @param bothSides Whether to pin for both sides (only for private chats)
|
* @param bothSides Whether to pin for both sides (only for private chats)
|
||||||
*/
|
*/
|
||||||
pin(notify = false, bothSides = false): Promise<void> {
|
pin(notify = false, bothSides = false): Promise<void> {
|
||||||
return this.client.pinMessage(this.chat.inputPeer, this.id, notify, bothSides)
|
return this.client.pinMessage(
|
||||||
|
this.chat.inputPeer,
|
||||||
|
this.id,
|
||||||
|
notify,
|
||||||
|
bothSides
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -864,7 +1107,7 @@ export class Message {
|
||||||
* @link TelegramClient.editMessage
|
* @link TelegramClient.editMessage
|
||||||
*/
|
*/
|
||||||
edit(
|
edit(
|
||||||
params: Parameters<TelegramClient['editMessage']>[2],
|
params: Parameters<TelegramClient['editMessage']>[2]
|
||||||
): Promise<Message> {
|
): Promise<Message> {
|
||||||
return this.client.editMessage(this.chat.inputPeer, this.id, params)
|
return this.client.editMessage(this.chat.inputPeer, this.id, params)
|
||||||
}
|
}
|
||||||
|
@ -881,13 +1124,11 @@ export class Message {
|
||||||
*/
|
*/
|
||||||
editText(
|
editText(
|
||||||
text: string,
|
text: string,
|
||||||
params?: Omit<Parameters<TelegramClient['editMessage']>[2], 'text'>,
|
params?: Omit<Parameters<TelegramClient['editMessage']>[2], 'text'>
|
||||||
): Promise<Message> {
|
): Promise<Message> {
|
||||||
return this.edit({
|
return this.edit({
|
||||||
text,
|
text,
|
||||||
...(
|
...(params || {}),
|
||||||
params || {}
|
|
||||||
),
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -903,23 +1144,31 @@ export class Message {
|
||||||
* @param toChatId Target chat ID
|
* @param toChatId Target chat ID
|
||||||
* @param params Copy parameters
|
* @param params Copy parameters
|
||||||
*/
|
*/
|
||||||
sendCopy (toChatId: InputPeerLike, params: Parameters<TelegramClient['sendCopy']>[3]): Promise<Message> {
|
sendCopy(
|
||||||
|
toChatId: InputPeerLike,
|
||||||
|
params: Parameters<TelegramClient['sendCopy']>[3]
|
||||||
|
): Promise<Message> {
|
||||||
if (!params) params = {}
|
if (!params) params = {}
|
||||||
|
|
||||||
if (this.raw._ === 'messageService') {
|
if (this.raw._ === 'messageService') {
|
||||||
throw new MtCuteArgumentError('Service messages can\'t be copied')
|
throw new MtCuteArgumentError("Service messages can't be copied")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.media && !(
|
if (this.media && !(this.media instanceof WebPage)) {
|
||||||
this.media instanceof WebPage
|
return this.client.sendMedia(
|
||||||
)) {
|
toChatId,
|
||||||
return this.client.sendMedia(toChatId, {
|
{
|
||||||
type: 'auto',
|
type: 'auto',
|
||||||
file: this.media.inputMedia,
|
file: this.media.inputMedia,
|
||||||
caption: params.caption ?? this.raw.message,
|
caption: params.caption ?? this.raw.message,
|
||||||
// we shouldn't use original entities if the user wants custom text
|
// we shouldn't use original entities if the user wants custom text
|
||||||
entities: params.entities ?? params.caption ? undefined : this.raw.entities,
|
entities:
|
||||||
}, params)
|
params.entities ?? params.caption
|
||||||
|
? undefined
|
||||||
|
: this.raw.entities,
|
||||||
|
},
|
||||||
|
params
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.client.sendText(toChatId, this.raw.message, params)
|
return this.client.sendText(toChatId, this.raw.message, params)
|
||||||
|
@ -940,5 +1189,4 @@ export class Message {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
makeInspectable(Message, ['empty', 'isScheduled'], ['link'])
|
makeInspectable(Message, ['empty', 'isScheduled'], ['link'])
|
||||||
|
|
Loading…
Reference in a new issue