feat(client): pinMessage and unpinMessage methods, pin and unpin bound methods for Message
This commit is contained in:
parent
e3ff2b9041
commit
4371e9b63a
4 changed files with 107 additions and 0 deletions
|
@ -46,6 +46,7 @@ import { getHistory } from './methods/messages/get-history'
|
|||
import { getMessages } from './methods/messages/get-messages'
|
||||
import { iterHistory } from './methods/messages/iter-history'
|
||||
import { _parseEntities } from './methods/messages/parse-entities'
|
||||
import { pinMessage } from './methods/messages/pin-message'
|
||||
import { searchGlobal } from './methods/messages/search-global'
|
||||
import { searchMessages } from './methods/messages/search-messages'
|
||||
import { sendDice } from './methods/messages/send-dice'
|
||||
|
@ -53,6 +54,7 @@ import { sendLocation } from './methods/messages/send-location'
|
|||
import { sendMedia } from './methods/messages/send-media'
|
||||
import { sendPhoto } from './methods/messages/send-photo'
|
||||
import { sendText } from './methods/messages/send-text'
|
||||
import { unpinMessage } from './methods/messages/unpin-message'
|
||||
import {
|
||||
getParseMode,
|
||||
registerParseMode,
|
||||
|
@ -947,6 +949,25 @@ export class TelegramClient extends BaseTelegramClient {
|
|||
): Promise<[string, tl.TypeMessageEntity[] | undefined]> {
|
||||
return _parseEntities.apply(this, arguments)
|
||||
}
|
||||
/**
|
||||
* Pin a message in a group, supergroup, channel or PM.
|
||||
*
|
||||
* For supergroups/channels, you must have appropriate permissions,
|
||||
* either as an admin, or as default permissions
|
||||
*
|
||||
* @param chatId Chat ID, username, phone number, `"self"` or `"me"`
|
||||
* @param messageId Message ID
|
||||
* @param notify (default: `false`) Whether to send a notification (only for legacy groups and supergroups)
|
||||
* @param bothSides (default: `false`) Whether to pin for both sides (only for private chats)
|
||||
*/
|
||||
pinMessage(
|
||||
chatId: InputPeerLike,
|
||||
messageId: number,
|
||||
notify?: boolean,
|
||||
bothSides?: boolean
|
||||
): Promise<void> {
|
||||
return pinMessage.apply(this, arguments)
|
||||
}
|
||||
/**
|
||||
* Search for messages globally from all of your chats
|
||||
*
|
||||
|
@ -1309,6 +1330,18 @@ export class TelegramClient extends BaseTelegramClient {
|
|||
): Promise<Message> {
|
||||
return sendText.apply(this, arguments)
|
||||
}
|
||||
/**
|
||||
* Unpin a message in a group, supergroup, channel or PM.
|
||||
*
|
||||
* For supergroups/channels, you must have appropriate permissions,
|
||||
* either as an admin, or as default permissions
|
||||
*
|
||||
* @param chatId Chat ID, username, phone number, `"self"` or `"me"`
|
||||
* @param messageId Message ID
|
||||
*/
|
||||
unpinMessage(chatId: InputPeerLike, messageId: number): Promise<void> {
|
||||
return unpinMessage.apply(this, arguments)
|
||||
}
|
||||
/**
|
||||
* Register a given {@link IMessageEntityParser} as a parse mode
|
||||
* for messages. When this method is first called, given parse
|
||||
|
|
31
packages/client/src/methods/messages/pin-message.ts
Normal file
31
packages/client/src/methods/messages/pin-message.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
import { TelegramClient } from '../../client'
|
||||
import { InputPeerLike } from '../../types'
|
||||
import { normalizeToInputPeer } from '../../utils/peer-utils'
|
||||
|
||||
/**
|
||||
* Pin a message in a group, supergroup, channel or PM.
|
||||
*
|
||||
* For supergroups/channels, you must have appropriate permissions,
|
||||
* either as an admin, or as default permissions
|
||||
*
|
||||
* @param chatId Chat ID, username, phone number, `"self"` or `"me"`
|
||||
* @param messageId Message ID
|
||||
* @param notify Whether to send a notification (only for legacy groups and supergroups)
|
||||
* @param bothSides Whether to pin for both sides (only for private chats)
|
||||
* @internal
|
||||
*/
|
||||
export async function pinMessage(
|
||||
this: TelegramClient,
|
||||
chatId: InputPeerLike,
|
||||
messageId: number,
|
||||
notify = false,
|
||||
bothSides = false
|
||||
): Promise<void> {
|
||||
await this.call({
|
||||
_: 'messages.updatePinnedMessage',
|
||||
peer: normalizeToInputPeer(await this.resolvePeer(chatId)),
|
||||
id: messageId,
|
||||
silent: !notify,
|
||||
pmOneside: !bothSides
|
||||
})
|
||||
}
|
26
packages/client/src/methods/messages/unpin-message.ts
Normal file
26
packages/client/src/methods/messages/unpin-message.ts
Normal file
|
@ -0,0 +1,26 @@
|
|||
import { TelegramClient } from '../../client'
|
||||
import { InputPeerLike } from '../../types'
|
||||
import { normalizeToInputPeer } from '../../utils/peer-utils'
|
||||
|
||||
/**
|
||||
* Unpin a message in a group, supergroup, channel or PM.
|
||||
*
|
||||
* For supergroups/channels, you must have appropriate permissions,
|
||||
* either as an admin, or as default permissions
|
||||
*
|
||||
* @param chatId Chat ID, username, phone number, `"self"` or `"me"`
|
||||
* @param messageId Message ID
|
||||
* @internal
|
||||
*/
|
||||
export async function unpinMessage(
|
||||
this: TelegramClient,
|
||||
chatId: InputPeerLike,
|
||||
messageId: number,
|
||||
): Promise<void> {
|
||||
await this.call({
|
||||
_: 'messages.updatePinnedMessage',
|
||||
peer: normalizeToInputPeer(await this.resolvePeer(chatId)),
|
||||
id: messageId,
|
||||
unpin: true
|
||||
})
|
||||
}
|
|
@ -913,6 +913,23 @@ export class Message {
|
|||
return this.client.deleteMessages(this.chat.inputPeer, this.id, revoke)
|
||||
}
|
||||
|
||||
/**
|
||||
* Pin this message.
|
||||
*
|
||||
* @param notify Whether to send a notification (only for legacy groups and supergroups)
|
||||
* @param bothSides Whether to pin for both sides (only for private chats)
|
||||
*/
|
||||
pin(notify = false, bothSides = false): Promise<void> {
|
||||
return this.client.pinMessage(this.chat.inputPeer, this.id, notify, bothSides)
|
||||
}
|
||||
|
||||
/**
|
||||
* Unpin this message.
|
||||
*/
|
||||
unpin(): Promise<void> {
|
||||
return this.client.pinMessage(this.chat.inputPeer, this.id)
|
||||
}
|
||||
|
||||
/**
|
||||
* Edit this message's text and/or reply markup
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue