feat: resolveUser and resolveChannel methods + refactor to use them
This commit is contained in:
parent
27e14472ff
commit
99bd1bc313
44 changed files with 134 additions and 131 deletions
|
@ -223,7 +223,7 @@ import { getProfilePhoto } from './methods/users/get-profile-photo.js'
|
||||||
import { getProfilePhotos } from './methods/users/get-profile-photos.js'
|
import { getProfilePhotos } from './methods/users/get-profile-photos.js'
|
||||||
import { getUsers } from './methods/users/get-users.js'
|
import { getUsers } from './methods/users/get-users.js'
|
||||||
import { iterProfilePhotos } from './methods/users/iter-profile-photos.js'
|
import { iterProfilePhotos } from './methods/users/iter-profile-photos.js'
|
||||||
import { resolvePeer } from './methods/users/resolve-peer.js'
|
import { resolveChannel, resolvePeer, resolveUser } from './methods/users/resolve-peer.js'
|
||||||
import { resolvePeerMany } from './methods/users/resolve-peer-many.js'
|
import { resolvePeerMany } from './methods/users/resolve-peer-many.js'
|
||||||
import { setGlobalTtl } from './methods/users/set-global-ttl.js'
|
import { setGlobalTtl } from './methods/users/set-global-ttl.js'
|
||||||
import { setMyEmojiStatus } from './methods/users/set-my-emoji-status.js'
|
import { setMyEmojiStatus } from './methods/users/set-my-emoji-status.js'
|
||||||
|
@ -5024,6 +5024,18 @@ export interface TelegramClient extends ITelegramClient {
|
||||||
* @param [force=false] Whether to force re-fetch the peer from the server (only for usernames and phone numbers)
|
* @param [force=false] Whether to force re-fetch the peer from the server (only for usernames and phone numbers)
|
||||||
*/
|
*/
|
||||||
resolvePeer(peerId: InputPeerLike, force?: boolean): Promise<tl.TypeInputPeer>
|
resolvePeer(peerId: InputPeerLike, force?: boolean): Promise<tl.TypeInputPeer>
|
||||||
|
/**
|
||||||
|
* Shorthand for `resolvePeer` that converts the input peer to `InputUser`.
|
||||||
|
* **Available**: ✅ both users and bots
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
resolveUser(peerId: InputPeerLike, force?: boolean): Promise<tl.TypeInputUser>
|
||||||
|
/**
|
||||||
|
* Shorthand for `resolvePeer` that converts the input peer to `InputChannel`.
|
||||||
|
* **Available**: ✅ both users and bots
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
resolveChannel(peerId: InputPeerLike, force?: boolean): Promise<tl.TypeInputChannel>
|
||||||
/**
|
/**
|
||||||
* Changes the current default value of the Time-To-Live setting,
|
* Changes the current default value of the Time-To-Live setting,
|
||||||
* applied to all new chats.
|
* applied to all new chats.
|
||||||
|
@ -5867,6 +5879,12 @@ TelegramClient.prototype.resolvePeerMany = function (...args) {
|
||||||
TelegramClient.prototype.resolvePeer = function (...args) {
|
TelegramClient.prototype.resolvePeer = function (...args) {
|
||||||
return resolvePeer(this._client, ...args)
|
return resolvePeer(this._client, ...args)
|
||||||
}
|
}
|
||||||
|
TelegramClient.prototype.resolveUser = function (...args) {
|
||||||
|
return resolveUser(this._client, ...args)
|
||||||
|
}
|
||||||
|
TelegramClient.prototype.resolveChannel = function (...args) {
|
||||||
|
return resolveChannel(this._client, ...args)
|
||||||
|
}
|
||||||
TelegramClient.prototype.setGlobalTtl = function (...args) {
|
TelegramClient.prototype.setGlobalTtl = function (...args) {
|
||||||
return setGlobalTtl(this._client, ...args)
|
return setGlobalTtl(this._client, ...args)
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,7 @@ import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import { InputPeerLike } from '../../types/index.js'
|
import { InputPeerLike } from '../../types/index.js'
|
||||||
import { toInputUser } from '../../utils/peer-utils.js'
|
import { resolveUser } from '../users/resolve-peer.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets information about a bot the current uzer owns (or the current bot)
|
* Gets information about a bot the current uzer owns (or the current bot)
|
||||||
|
@ -28,7 +27,7 @@ export async function getBotInfo(
|
||||||
|
|
||||||
return client.call({
|
return client.call({
|
||||||
_: 'bots.getBotInfo',
|
_: 'bots.getBotInfo',
|
||||||
bot: bot ? toInputUser(await resolvePeer(client, bot), bot) : undefined,
|
bot: bot ? await resolveUser(client, bot) : undefined,
|
||||||
langCode: langCode,
|
langCode: langCode,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,8 +2,7 @@ import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import { InputPeerLike } from '../../types/index.js'
|
import { InputPeerLike } from '../../types/index.js'
|
||||||
import { toInputUser } from '../../utils/peer-utils.js'
|
import { resolveUser } from '../users/resolve-peer.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetches the menu button set for the given user.
|
* Fetches the menu button set for the given user.
|
||||||
|
@ -11,6 +10,6 @@ import { resolvePeer } from '../users/resolve-peer.js'
|
||||||
export async function getBotMenuButton(client: ITelegramClient, user: InputPeerLike): Promise<tl.TypeBotMenuButton> {
|
export async function getBotMenuButton(client: ITelegramClient, user: InputPeerLike): Promise<tl.TypeBotMenuButton> {
|
||||||
return await client.call({
|
return await client.call({
|
||||||
_: 'bots.getBotMenuButton',
|
_: 'bots.getBotMenuButton',
|
||||||
userId: toInputUser(await resolvePeer(client, user), user),
|
userId: await resolveUser(client, user),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,7 @@ import { tl } from '@mtcute/tl'
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import { GameHighScore, InputMessageId, InputPeerLike, normalizeInputMessageId, PeersIndex } from '../../types/index.js'
|
import { GameHighScore, InputMessageId, InputPeerLike, normalizeInputMessageId, PeersIndex } from '../../types/index.js'
|
||||||
import { normalizeInlineId } from '../../utils/inline-utils.js'
|
import { normalizeInlineId } from '../../utils/inline-utils.js'
|
||||||
import { toInputUser } from '../../utils/peer-utils.js'
|
import { resolvePeer, resolveUser } from '../users/resolve-peer.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get high scores of a game
|
* Get high scores of a game
|
||||||
|
@ -24,7 +23,7 @@ export async function getGameHighScores(
|
||||||
let user: tl.TypeInputUser
|
let user: tl.TypeInputUser
|
||||||
|
|
||||||
if (userId) {
|
if (userId) {
|
||||||
user = toInputUser(await resolvePeer(client, userId), userId)
|
user = await resolveUser(client, userId)
|
||||||
} else {
|
} else {
|
||||||
user = { _: 'inputUserEmpty' }
|
user = { _: 'inputUserEmpty' }
|
||||||
}
|
}
|
||||||
|
@ -57,7 +56,7 @@ export async function getInlineGameHighScores(
|
||||||
let user: tl.TypeInputUser
|
let user: tl.TypeInputUser
|
||||||
|
|
||||||
if (userId) {
|
if (userId) {
|
||||||
user = toInputUser(await resolvePeer(client, userId), userId)
|
user = await resolveUser(client, userId)
|
||||||
} else {
|
} else {
|
||||||
user = { _: 'inputUserEmpty' }
|
user = { _: 'inputUserEmpty' }
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,7 @@ import { tl } from '@mtcute/tl'
|
||||||
import { assertNever } from '../../../types/utils.js'
|
import { assertNever } from '../../../types/utils.js'
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import { BotCommands } from '../../types/index.js'
|
import { BotCommands } from '../../types/index.js'
|
||||||
import { toInputUser } from '../../utils/peer-utils.js'
|
import { resolvePeer, resolveUser } from '../users/resolve-peer.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
|
||||||
|
|
||||||
/** @internal */
|
/** @internal */
|
||||||
export async function _normalizeCommandScope(
|
export async function _normalizeCommandScope(
|
||||||
|
@ -24,7 +23,7 @@ export async function _normalizeCommandScope(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 'member': {
|
case 'member': {
|
||||||
const user = toInputUser(await resolvePeer(client, scope.user), scope.user)
|
const user = await resolveUser(client, scope.user)
|
||||||
const chat = await resolvePeer(client, scope.chat)
|
const chat = await resolvePeer(client, scope.chat)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import { assertTrue } from '../../../utils/type-assertions.js'
|
import { assertTrue } from '../../../utils/type-assertions.js'
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import { InputPeerLike } from '../../types/index.js'
|
import { InputPeerLike } from '../../types/index.js'
|
||||||
import { toInputUser } from '../../utils/peer-utils.js'
|
import { resolveUser } from '../users/resolve-peer.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets information about a bot the current uzer owns (or the current bot)
|
* Sets information about a bot the current uzer owns (or the current bot)
|
||||||
|
@ -36,7 +35,7 @@ export async function setBotInfo(
|
||||||
|
|
||||||
const r = await client.call({
|
const r = await client.call({
|
||||||
_: 'bots.setBotInfo',
|
_: 'bots.setBotInfo',
|
||||||
bot: bot ? toInputUser(await resolvePeer(client, bot), bot) : undefined,
|
bot: bot ? await resolveUser(client, bot) : undefined,
|
||||||
langCode: langCode,
|
langCode: langCode,
|
||||||
name,
|
name,
|
||||||
about: bio,
|
about: bio,
|
||||||
|
|
|
@ -3,8 +3,7 @@ import { tl } from '@mtcute/tl'
|
||||||
import { assertTrue } from '../../../utils/type-assertions.js'
|
import { assertTrue } from '../../../utils/type-assertions.js'
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import { InputPeerLike } from '../../types/index.js'
|
import { InputPeerLike } from '../../types/index.js'
|
||||||
import { toInputUser } from '../../utils/peer-utils.js'
|
import { resolveUser } from '../users/resolve-peer.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a menu button for the given user.
|
* Sets a menu button for the given user.
|
||||||
|
@ -16,7 +15,7 @@ export async function setBotMenuButton(
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const r = await client.call({
|
const r = await client.call({
|
||||||
_: 'bots.setBotMenuButton',
|
_: 'bots.setBotMenuButton',
|
||||||
userId: toInputUser(await resolvePeer(client, user), user),
|
userId: await resolveUser(client, user),
|
||||||
button,
|
button,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -4,9 +4,8 @@ import { assertTrue } from '../../../utils/type-assertions.js'
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import { InputMessageId, InputPeerLike, Message, normalizeInputMessageId } from '../../types/index.js'
|
import { InputMessageId, InputPeerLike, Message, normalizeInputMessageId } from '../../types/index.js'
|
||||||
import { normalizeInlineId } from '../../utils/inline-utils.js'
|
import { normalizeInlineId } from '../../utils/inline-utils.js'
|
||||||
import { toInputUser } from '../../utils/peer-utils.js'
|
|
||||||
import { _findMessageInUpdate } from '../messages/find-in-update.js'
|
import { _findMessageInUpdate } from '../messages/find-in-update.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
import { resolvePeer, resolveUser } from '../users/resolve-peer.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set a score of a user in a game
|
* Set a score of a user in a game
|
||||||
|
@ -45,7 +44,7 @@ export async function setGameScore(
|
||||||
const { userId, score, noEdit, force, shouldDispatch } = params
|
const { userId, score, noEdit, force, shouldDispatch } = params
|
||||||
const { chatId, message } = normalizeInputMessageId(params)
|
const { chatId, message } = normalizeInputMessageId(params)
|
||||||
|
|
||||||
const user = toInputUser(await resolvePeer(client, userId), userId)
|
const user = await resolveUser(client, userId)
|
||||||
const chat = await resolvePeer(client, chatId)
|
const chat = await resolvePeer(client, chatId)
|
||||||
|
|
||||||
const res = await client.call({
|
const res = await client.call({
|
||||||
|
@ -91,7 +90,7 @@ export async function setInlineGameScore(
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const { messageId, userId, score, noEdit, force } = params
|
const { messageId, userId, score, noEdit, force } = params
|
||||||
|
|
||||||
const user = toInputUser(await resolvePeer(client, userId), userId)
|
const user = await resolveUser(client, userId)
|
||||||
|
|
||||||
const id = normalizeInlineId(messageId)
|
const id = normalizeInlineId(messageId)
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { MaybeArray } from '../../../types/utils.js'
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types/index.js'
|
import { InputPeerLike, MtInvalidPeerTypeError } from '../../types/index.js'
|
||||||
import { isInputPeerChannel, isInputPeerChat, toInputChannel, toInputUser } from '../../utils/peer-utils.js'
|
import { isInputPeerChannel, isInputPeerChat, toInputChannel, toInputUser } from '../../utils/peer-utils.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
import { resolvePeer, resolveUser } from '../users/resolve-peer.js'
|
||||||
import { resolvePeerMany } from '../users/resolve-peer-many.js'
|
import { resolvePeerMany } from '../users/resolve-peer-many.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -33,7 +33,7 @@ export async function addChatMembers(
|
||||||
|
|
||||||
if (isInputPeerChat(chat)) {
|
if (isInputPeerChat(chat)) {
|
||||||
for (const user of users) {
|
for (const user of users) {
|
||||||
const p = toInputUser(await resolvePeer(client, user))
|
const p = await resolveUser(client, user)
|
||||||
|
|
||||||
const updates = await client.call({
|
const updates = await client.call({
|
||||||
_: 'messages.addChatUser',
|
_: 'messages.addChatUser',
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import { InputPeerLike } from '../../types/index.js'
|
import { InputPeerLike } from '../../types/index.js'
|
||||||
import { toInputChannel } from '../../utils/peer-utils.js'
|
import { resolveChannel } from '../users/resolve-peer.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
|
||||||
|
|
||||||
// @alias=deleteSupergroup
|
// @alias=deleteSupergroup
|
||||||
/**
|
/**
|
||||||
|
@ -12,7 +11,7 @@ import { resolvePeer } from '../users/resolve-peer.js'
|
||||||
export async function deleteChannel(client: ITelegramClient, chatId: InputPeerLike): Promise<void> {
|
export async function deleteChannel(client: ITelegramClient, chatId: InputPeerLike): Promise<void> {
|
||||||
const res = await client.call({
|
const res = await client.call({
|
||||||
_: 'channels.deleteChannel',
|
_: 'channels.deleteChannel',
|
||||||
channel: toInputChannel(await resolvePeer(client, chatId), chatId),
|
channel: await resolveChannel(client, chatId),
|
||||||
})
|
})
|
||||||
client.handleClientUpdate(res)
|
client.handleClientUpdate(res)
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,7 @@ import { tl } from '@mtcute/tl'
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import { InputPeerLike } from '../../types/index.js'
|
import { InputPeerLike } from '../../types/index.js'
|
||||||
import { createDummyUpdate } from '../../updates/utils.js'
|
import { createDummyUpdate } from '../../updates/utils.js'
|
||||||
import { toInputChannel } from '../../utils/peer-utils.js'
|
import { resolveChannel, resolvePeer } from '../users/resolve-peer.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete all messages of a user (or channel) in a supergroup
|
* Delete all messages of a user (or channel) in a supergroup
|
||||||
|
@ -20,7 +19,7 @@ export async function deleteUserHistory(
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const { chatId, participantId } = params
|
const { chatId, participantId } = params
|
||||||
|
|
||||||
const channel = toInputChannel(await resolvePeer(client, chatId), chatId)
|
const channel = await resolveChannel(client, chatId)
|
||||||
|
|
||||||
const peer = await resolvePeer(client, participantId)
|
const peer = await resolvePeer(client, participantId)
|
||||||
|
|
||||||
|
|
|
@ -2,8 +2,7 @@ import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import { InputPeerLike } from '../../types/index.js'
|
import { InputPeerLike } from '../../types/index.js'
|
||||||
import { toInputChannel, toInputUser } from '../../utils/peer-utils.js'
|
import { resolveChannel, resolveUser } from '../users/resolve-peer.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Edit supergroup/channel admin rights of a user.
|
* Edit supergroup/channel admin rights of a user.
|
||||||
|
@ -23,8 +22,8 @@ export async function editAdminRights(
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const { chatId, userId, rights, rank = '' } = params
|
const { chatId, userId, rights, rank = '' } = params
|
||||||
|
|
||||||
const chat = toInputChannel(await resolvePeer(client, chatId), chatId)
|
const chat = await resolveChannel(client, chatId)
|
||||||
const user = toInputUser(await resolvePeer(client, userId), userId)
|
const user = await resolveUser(client, userId)
|
||||||
|
|
||||||
const res = await client.call({
|
const res = await client.call({
|
||||||
_: 'channels.editAdmin',
|
_: 'channels.editAdmin',
|
||||||
|
|
|
@ -5,8 +5,8 @@ import { tl } from '@mtcute/tl'
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import { ChatEvent, InputPeerLike, PeersIndex } from '../../types/index.js'
|
import { ChatEvent, InputPeerLike, PeersIndex } from '../../types/index.js'
|
||||||
import { InputChatEventFilters, normalizeChatEventFilters } from '../../types/peers/chat-event/filters.js'
|
import { InputChatEventFilters, normalizeChatEventFilters } from '../../types/peers/chat-event/filters.js'
|
||||||
import { toInputChannel, toInputUser } from '../../utils/peer-utils.js'
|
import { toInputUser } from '../../utils/peer-utils.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
import { resolveChannel } from '../users/resolve-peer.js'
|
||||||
import { resolvePeerMany } from '../users/resolve-peer-many.js'
|
import { resolvePeerMany } from '../users/resolve-peer-many.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,7 +77,7 @@ export async function getChatEventLog(
|
||||||
): Promise<ChatEvent[]> {
|
): Promise<ChatEvent[]> {
|
||||||
const { maxId = Long.ZERO, minId = Long.ZERO, query = '', limit = 100, users, filters } = params ?? {}
|
const { maxId = Long.ZERO, minId = Long.ZERO, query = '', limit = 100, users, filters } = params ?? {}
|
||||||
|
|
||||||
const channel = toInputChannel(await resolvePeer(client, chatId), chatId)
|
const channel = await resolveChannel(client, chatId)
|
||||||
|
|
||||||
const admins: tl.TypeInputUser[] | undefined = users ? await resolvePeerMany(client, users, toInputUser) : undefined
|
const admins: tl.TypeInputUser[] | undefined = users ? await resolvePeerMany(client, users, toInputUser) : undefined
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import { ArrayWithTotal, Chat, InputPeerLike } from '../../types/index.js'
|
import { ArrayWithTotal, Chat, InputPeerLike } from '../../types/index.js'
|
||||||
import { makeArrayWithTotal } from '../../utils/misc-utils.js'
|
import { makeArrayWithTotal } from '../../utils/misc-utils.js'
|
||||||
import { toInputChannel } from '../../utils/peer-utils.js'
|
import { resolveChannel } from '../users/resolve-peer.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
|
||||||
|
|
||||||
// @available=user
|
// @available=user
|
||||||
/**
|
/**
|
||||||
|
@ -20,7 +19,7 @@ export async function getSimilarChannels(
|
||||||
): Promise<ArrayWithTotal<Chat>> {
|
): Promise<ArrayWithTotal<Chat>> {
|
||||||
const res = await client.call({
|
const res = await client.call({
|
||||||
_: 'channels.getChannelRecommendations',
|
_: 'channels.getChannelRecommendations',
|
||||||
channel: toInputChannel(await resolvePeer(client, channel), channel),
|
channel: await resolveChannel(client, channel),
|
||||||
})
|
})
|
||||||
|
|
||||||
const parsed = res.chats.map((chat) => new Chat(chat))
|
const parsed = res.chats.map((chat) => new Chat(chat))
|
||||||
|
|
|
@ -5,8 +5,8 @@ import { tl } from '@mtcute/tl'
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import { ChatEvent, InputPeerLike } from '../../types/index.js'
|
import { ChatEvent, InputPeerLike } from '../../types/index.js'
|
||||||
import { normalizeChatEventFilters } from '../../types/peers/chat-event/filters.js'
|
import { normalizeChatEventFilters } from '../../types/peers/chat-event/filters.js'
|
||||||
import { toInputChannel, toInputUser } from '../../utils/peer-utils.js'
|
import { toInputUser } from '../../utils/peer-utils.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
import { resolveChannel } from '../users/resolve-peer.js'
|
||||||
import { resolvePeerMany } from '../users/resolve-peer-many.js'
|
import { resolvePeerMany } from '../users/resolve-peer-many.js'
|
||||||
import { getChatEventLog } from './get-chat-event-log.js'
|
import { getChatEventLog } from './get-chat-event-log.js'
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ export async function* iterChatEventLog(
|
||||||
): AsyncIterableIterator<ChatEvent> {
|
): AsyncIterableIterator<ChatEvent> {
|
||||||
if (!params) params = {}
|
if (!params) params = {}
|
||||||
|
|
||||||
const channel = toInputChannel(await resolvePeer(client, chatId), chatId)
|
const channel = await resolveChannel(client, chatId)
|
||||||
|
|
||||||
const { minId = Long.ZERO, query = '', limit = Infinity, chunkSize = 100, users, filters } = params
|
const { minId = Long.ZERO, query = '', limit = Infinity, chunkSize = 100, users, filters } = params
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import { Chat, InputPeerLike } from '../../types/index.js'
|
import { Chat, InputPeerLike } from '../../types/index.js'
|
||||||
import { assertIsUpdatesGroup } from '../../updates/utils.js'
|
import { assertIsUpdatesGroup } from '../../updates/utils.js'
|
||||||
import { INVITE_LINK_REGEX, toInputChannel } from '../../utils/peer-utils.js'
|
import { INVITE_LINK_REGEX } from '../../utils/peer-utils.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
import { resolveChannel } from '../users/resolve-peer.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Join a channel or supergroup
|
* Join a channel or supergroup
|
||||||
|
@ -34,7 +34,7 @@ export async function joinChat(client: ITelegramClient, chatId: InputPeerLike):
|
||||||
|
|
||||||
const res = await client.call({
|
const res = await client.call({
|
||||||
_: 'channels.joinChannel',
|
_: 'channels.joinChannel',
|
||||||
channel: toInputChannel(await resolvePeer(client, chatId), chatId),
|
channel: await resolveChannel(client, chatId),
|
||||||
})
|
})
|
||||||
|
|
||||||
assertIsUpdatesGroup('channels.joinChannel', res)
|
assertIsUpdatesGroup('channels.joinChannel', res)
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import { assertTrue } from '../../../utils/type-assertions.js'
|
import { assertTrue } from '../../../utils/type-assertions.js'
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import { InputPeerLike } from '../../types/index.js'
|
import { InputPeerLike } from '../../types/index.js'
|
||||||
import { toInputChannel } from '../../utils/peer-utils.js'
|
import { resolveChannel } from '../users/resolve-peer.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Change supergroup/channel username
|
* Change supergroup/channel username
|
||||||
|
@ -19,7 +18,7 @@ export async function setChatUsername(
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const r = await client.call({
|
const r = await client.call({
|
||||||
_: 'channels.updateUsername',
|
_: 'channels.updateUsername',
|
||||||
channel: toInputChannel(await resolvePeer(client, chatId), chatId),
|
channel: await resolveChannel(client, chatId),
|
||||||
username: username || '',
|
username: username || '',
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import { InputPeerLike } from '../../types/index.js'
|
import { InputPeerLike } from '../../types/index.js'
|
||||||
import { toInputChannel } from '../../utils/peer-utils.js'
|
import { resolveChannel } from '../users/resolve-peer.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set supergroup's slow mode interval.
|
* Set supergroup's slow mode interval.
|
||||||
|
@ -15,7 +14,7 @@ import { resolvePeer } from '../users/resolve-peer.js'
|
||||||
export async function setSlowMode(client: ITelegramClient, chatId: InputPeerLike, seconds = 0): Promise<void> {
|
export async function setSlowMode(client: ITelegramClient, chatId: InputPeerLike, seconds = 0): Promise<void> {
|
||||||
const res = await client.call({
|
const res = await client.call({
|
||||||
_: 'channels.toggleSlowMode',
|
_: 'channels.toggleSlowMode',
|
||||||
channel: toInputChannel(await resolvePeer(client, chatId), chatId),
|
channel: await resolveChannel(client, chatId),
|
||||||
seconds,
|
seconds,
|
||||||
})
|
})
|
||||||
client.handleClientUpdate(res)
|
client.handleClientUpdate(res)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import { InputPeerLike } from '../../types/index.js'
|
import { InputPeerLike } from '../../types/index.js'
|
||||||
import { toInputChannel } from '../../utils/peer-utils.js'
|
import { resolveChannel } from '../users/resolve-peer.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set whether a channel/supergroup has join requests enabled.
|
* Set whether a channel/supergroup has join requests enabled.
|
||||||
|
@ -19,7 +18,7 @@ export async function toggleJoinRequests(
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const res = await client.call({
|
const res = await client.call({
|
||||||
_: 'channels.toggleJoinRequest',
|
_: 'channels.toggleJoinRequest',
|
||||||
channel: toInputChannel(await resolvePeer(client, chatId), chatId),
|
channel: await resolveChannel(client, chatId),
|
||||||
enabled,
|
enabled,
|
||||||
})
|
})
|
||||||
client.handleClientUpdate(res)
|
client.handleClientUpdate(res)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import { InputPeerLike } from '../../types/index.js'
|
import { InputPeerLike } from '../../types/index.js'
|
||||||
import { toInputChannel } from '../../utils/peer-utils.js'
|
import { resolveChannel } from '../users/resolve-peer.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set whether a channel/supergroup has join-to-send setting enabled.
|
* Set whether a channel/supergroup has join-to-send setting enabled.
|
||||||
|
@ -12,14 +11,10 @@ import { resolvePeer } from '../users/resolve-peer.js'
|
||||||
* @param chatId Chat ID or username
|
* @param chatId Chat ID or username
|
||||||
* @param enabled Whether join-to-send setting should be enabled
|
* @param enabled Whether join-to-send setting should be enabled
|
||||||
*/
|
*/
|
||||||
export async function toggleJoinToSend(
|
export async function toggleJoinToSend(client: ITelegramClient, chatId: InputPeerLike, enabled = false): Promise<void> {
|
||||||
client: ITelegramClient,
|
|
||||||
chatId: InputPeerLike,
|
|
||||||
enabled = false,
|
|
||||||
): Promise<void> {
|
|
||||||
const res = await client.call({
|
const res = await client.call({
|
||||||
_: 'channels.toggleJoinToSend',
|
_: 'channels.toggleJoinToSend',
|
||||||
channel: toInputChannel(await resolvePeer(client, chatId), chatId),
|
channel: await resolveChannel(client, chatId),
|
||||||
enabled,
|
enabled,
|
||||||
})
|
})
|
||||||
client.handleClientUpdate(res)
|
client.handleClientUpdate(res)
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import { InputPeerLike, User } from '../../types/index.js'
|
import { InputPeerLike, User } from '../../types/index.js'
|
||||||
import { assertIsUpdatesGroup } from '../../updates/utils.js'
|
import { assertIsUpdatesGroup } from '../../updates/utils.js'
|
||||||
import { toInputUser } from '../../utils/peer-utils.js'
|
import { resolveUser } from '../users/resolve-peer.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add an existing Telegram user as a contact
|
* Add an existing Telegram user as a contact
|
||||||
|
@ -38,7 +37,7 @@ export async function addContact(
|
||||||
},
|
},
|
||||||
): Promise<User> {
|
): Promise<User> {
|
||||||
const { userId, firstName, lastName = '', phone = '', sharePhone = false } = params
|
const { userId, firstName, lastName = '', phone = '', sharePhone = false } = params
|
||||||
const peer = toInputUser(await resolvePeer(client, userId), userId)
|
const peer = await resolveUser(client, userId)
|
||||||
|
|
||||||
const res = await client.call({
|
const res = await client.call({
|
||||||
_: 'contacts.addContact',
|
_: 'contacts.addContact',
|
||||||
|
|
|
@ -3,9 +3,8 @@ import { tl } from '@mtcute/tl'
|
||||||
import { randomLong } from '../../../utils/long-utils.js'
|
import { randomLong } from '../../../utils/long-utils.js'
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import { InputPeerLike, Message } from '../../types/index.js'
|
import { InputPeerLike, Message } from '../../types/index.js'
|
||||||
import { toInputChannel } from '../../utils/peer-utils.js'
|
|
||||||
import { _findMessageInUpdate } from '../messages/find-in-update.js'
|
import { _findMessageInUpdate } from '../messages/find-in-update.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
import { resolveChannel, resolvePeer } from '../users/resolve-peer.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a topic in a forum
|
* Create a topic in a forum
|
||||||
|
@ -51,7 +50,7 @@ export async function createForumTopic(
|
||||||
|
|
||||||
const res = await client.call({
|
const res = await client.call({
|
||||||
_: 'channels.createForumTopic',
|
_: 'channels.createForumTopic',
|
||||||
channel: toInputChannel(await resolvePeer(client, chatId), chatId),
|
channel: await resolveChannel(client, chatId),
|
||||||
title,
|
title,
|
||||||
iconColor: typeof icon === 'number' ? icon : undefined,
|
iconColor: typeof icon === 'number' ? icon : undefined,
|
||||||
iconEmojiId: typeof icon !== 'number' ? icon : undefined,
|
iconEmojiId: typeof icon !== 'number' ? icon : undefined,
|
||||||
|
|
|
@ -2,8 +2,7 @@ import { assertTypeIsNot } from '../../../utils/type-assertions.js'
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import type { ForumTopic, InputPeerLike } from '../../types/index.js'
|
import type { ForumTopic, InputPeerLike } from '../../types/index.js'
|
||||||
import { createDummyUpdate } from '../../updates/utils.js'
|
import { createDummyUpdate } from '../../updates/utils.js'
|
||||||
import { toInputChannel } from '../../utils/peer-utils.js'
|
import { resolveChannel } from '../users/resolve-peer.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a forum topic and all its history
|
* Delete a forum topic and all its history
|
||||||
|
@ -16,7 +15,7 @@ export async function deleteForumTopicHistory(
|
||||||
chat: InputPeerLike,
|
chat: InputPeerLike,
|
||||||
topicId: number | ForumTopic,
|
topicId: number | ForumTopic,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const channel = toInputChannel(await resolvePeer(client, chat), chat)
|
const channel = await resolveChannel(client, chat)
|
||||||
assertTypeIsNot('deleteForumTopicHistory', channel, 'inputChannelEmpty')
|
assertTypeIsNot('deleteForumTopicHistory', channel, 'inputChannelEmpty')
|
||||||
|
|
||||||
const res = await client.call({
|
const res = await client.call({
|
||||||
|
|
|
@ -4,9 +4,8 @@ import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import type { ForumTopic, InputPeerLike, Message } from '../../types/index.js'
|
import type { ForumTopic, InputPeerLike, Message } from '../../types/index.js'
|
||||||
import { toInputChannel } from '../../utils/peer-utils.js'
|
|
||||||
import { _findMessageInUpdate } from '../messages/find-in-update.js'
|
import { _findMessageInUpdate } from '../messages/find-in-update.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
import { resolveChannel } from '../users/resolve-peer.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Modify a topic in a forum
|
* Modify a topic in a forum
|
||||||
|
@ -50,7 +49,7 @@ export async function editForumTopic(
|
||||||
|
|
||||||
const res = await client.call({
|
const res = await client.call({
|
||||||
_: 'channels.editForumTopic',
|
_: 'channels.editForumTopic',
|
||||||
channel: toInputChannel(await resolvePeer(client, chatId), chatId),
|
channel: await resolveChannel(client, chatId),
|
||||||
topicId: typeof topicId === 'number' ? topicId : topicId.id,
|
topicId: typeof topicId === 'number' ? topicId : topicId.id,
|
||||||
title,
|
title,
|
||||||
iconEmojiId: icon ? icon ?? Long.ZERO : undefined,
|
iconEmojiId: icon ? icon ?? Long.ZERO : undefined,
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import { MaybeArray } from '../../../types/utils.js'
|
import { MaybeArray } from '../../../types/utils.js'
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import { ForumTopic, InputPeerLike } from '../../types/index.js'
|
import { ForumTopic, InputPeerLike } from '../../types/index.js'
|
||||||
import { toInputChannel } from '../../utils/index.js'
|
import { resolveChannel } from '../users/resolve-peer.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get forum topics by their IDs
|
* Get forum topics by their IDs
|
||||||
|
@ -18,7 +17,7 @@ export async function getForumTopicsById(
|
||||||
|
|
||||||
const res = await client.call({
|
const res = await client.call({
|
||||||
_: 'channels.getForumTopicsByID',
|
_: 'channels.getForumTopicsByID',
|
||||||
channel: toInputChannel(await resolvePeer(client, chatId)),
|
channel: await resolveChannel(client, chatId),
|
||||||
topics: ids,
|
topics: ids,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import { ArrayPaginated, ForumTopic, InputPeerLike } from '../../types/index.js'
|
import { ArrayPaginated, ForumTopic, InputPeerLike } from '../../types/index.js'
|
||||||
import { makeArrayPaginated } from '../../utils/index.js'
|
import { makeArrayPaginated } from '../../utils/index.js'
|
||||||
import { toInputChannel } from '../../utils/peer-utils.js'
|
import { resolveChannel } from '../users/resolve-peer.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
|
||||||
|
|
||||||
// @exported
|
// @exported
|
||||||
export interface GetForumTopicsOffset {
|
export interface GetForumTopicsOffset {
|
||||||
|
@ -54,7 +53,7 @@ export async function getForumTopics(
|
||||||
|
|
||||||
const res = await client.call({
|
const res = await client.call({
|
||||||
_: 'channels.getForumTopics',
|
_: 'channels.getForumTopics',
|
||||||
channel: toInputChannel(await resolvePeer(client, chatId), chatId),
|
channel: await resolveChannel(client, chatId),
|
||||||
q: query,
|
q: query,
|
||||||
offsetDate,
|
offsetDate,
|
||||||
offsetId,
|
offsetId,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import { ForumTopic, InputPeerLike } from '../../types/index.js'
|
import { ForumTopic, InputPeerLike } from '../../types/index.js'
|
||||||
import { toInputChannel } from '../../utils/peer-utils.js'
|
import { resolveChannel } from '../users/resolve-peer.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
|
||||||
import { getForumTopics } from './get-forum-topics.js'
|
import { getForumTopics } from './get-forum-topics.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,7 +29,7 @@ export async function* iterForumTopics(
|
||||||
|
|
||||||
const { query, limit = Infinity, chunkSize = 100 } = params
|
const { query, limit = Infinity, chunkSize = 100 } = params
|
||||||
|
|
||||||
const peer = toInputChannel(await resolvePeer(client, chatId))
|
const peer = await resolveChannel(client, chatId)
|
||||||
|
|
||||||
let { offset } = params
|
let { offset } = params
|
||||||
let current = 0
|
let current = 0
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import type { ForumTopic, InputPeerLike } from '../../types/index.js'
|
import type { ForumTopic, InputPeerLike } from '../../types/index.js'
|
||||||
import { toInputChannel } from '../../utils/peer-utils.js'
|
import { resolveChannel } from '../users/resolve-peer.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reorder pinned forum topics
|
* Reorder pinned forum topics
|
||||||
|
@ -28,7 +27,7 @@ export async function reorderPinnedForumTopics(
|
||||||
const { chatId, order, force } = params
|
const { chatId, order, force } = params
|
||||||
await client.call({
|
await client.call({
|
||||||
_: 'channels.reorderPinnedForumTopics',
|
_: 'channels.reorderPinnedForumTopics',
|
||||||
channel: toInputChannel(await resolvePeer(client, chatId), chatId),
|
channel: await resolveChannel(client, chatId),
|
||||||
order: order.map((it) => (typeof it === 'number' ? it : it.id)),
|
order: order.map((it) => (typeof it === 'number' ? it : it.id)),
|
||||||
force,
|
force,
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import type { ForumTopic, InputPeerLike, Message } from '../../types/index.js'
|
import type { ForumTopic, InputPeerLike, Message } from '../../types/index.js'
|
||||||
import { toInputChannel } from '../../utils/peer-utils.js'
|
|
||||||
import { _findMessageInUpdate } from '../messages/find-in-update.js'
|
import { _findMessageInUpdate } from '../messages/find-in-update.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
import { resolveChannel } from '../users/resolve-peer.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Toggle open/close status of a topic in a forum
|
* Toggle open/close status of a topic in a forum
|
||||||
|
@ -34,7 +33,7 @@ export async function toggleForumTopicClosed(
|
||||||
|
|
||||||
const res = await client.call({
|
const res = await client.call({
|
||||||
_: 'channels.editForumTopic',
|
_: 'channels.editForumTopic',
|
||||||
channel: toInputChannel(await resolvePeer(client, chatId), chatId),
|
channel: await resolveChannel(client, chatId),
|
||||||
topicId: typeof topicId === 'number' ? topicId : topicId.id,
|
topicId: typeof topicId === 'number' ? topicId : topicId.id,
|
||||||
closed,
|
closed,
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import { ForumTopic, InputPeerLike } from '../../types/index.js'
|
import { ForumTopic, InputPeerLike } from '../../types/index.js'
|
||||||
import { toInputChannel } from '../../utils/peer-utils.js'
|
import { resolveChannel } from '../users/resolve-peer.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Toggle whether a topic in a forum is pinned
|
* Toggle whether a topic in a forum is pinned
|
||||||
|
@ -23,7 +22,7 @@ export async function toggleForumTopicPinned(
|
||||||
|
|
||||||
await client.call({
|
await client.call({
|
||||||
_: 'channels.updatePinnedForumTopic',
|
_: 'channels.updatePinnedForumTopic',
|
||||||
channel: toInputChannel(await resolvePeer(client, chatId), chatId),
|
channel: await resolveChannel(client, chatId),
|
||||||
topicId: typeof topicId === 'number' ? topicId : topicId.id,
|
topicId: typeof topicId === 'number' ? topicId : topicId.id,
|
||||||
pinned,
|
pinned,
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import { InputPeerLike } from '../../types/index.js'
|
import { InputPeerLike } from '../../types/index.js'
|
||||||
import { toInputChannel } from '../../utils/peer-utils.js'
|
import { resolveChannel } from '../users/resolve-peer.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set whether a supergroup is a forum.
|
* Set whether a supergroup is a forum.
|
||||||
|
@ -14,7 +13,7 @@ import { resolvePeer } from '../users/resolve-peer.js'
|
||||||
export async function toggleForum(client: ITelegramClient, chatId: InputPeerLike, enabled = false): Promise<void> {
|
export async function toggleForum(client: ITelegramClient, chatId: InputPeerLike, enabled = false): Promise<void> {
|
||||||
const res = await client.call({
|
const res = await client.call({
|
||||||
_: 'channels.toggleForum',
|
_: 'channels.toggleForum',
|
||||||
channel: toInputChannel(await resolvePeer(client, chatId), chatId),
|
channel: await resolveChannel(client, chatId),
|
||||||
enabled,
|
enabled,
|
||||||
})
|
})
|
||||||
client.handleClientUpdate(res)
|
client.handleClientUpdate(res)
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import { InputPeerLike, Message } from '../../types/index.js'
|
import { InputPeerLike, Message } from '../../types/index.js'
|
||||||
import { toInputChannel } from '../../utils/peer-utils.js'
|
|
||||||
import { _findMessageInUpdate } from '../messages/find-in-update.js'
|
import { _findMessageInUpdate } from '../messages/find-in-update.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
import { resolveChannel } from '../users/resolve-peer.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Toggle whether "General" topic in a forum is hidden or not
|
* Toggle whether "General" topic in a forum is hidden or not
|
||||||
|
@ -29,7 +28,7 @@ export async function toggleGeneralTopicHidden(
|
||||||
const { chatId, hidden, shouldDispatch } = params
|
const { chatId, hidden, shouldDispatch } = params
|
||||||
const res = await client.call({
|
const res = await client.call({
|
||||||
_: 'channels.editForumTopic',
|
_: 'channels.editForumTopic',
|
||||||
channel: toInputChannel(await resolvePeer(client, chatId), chatId),
|
channel: await resolveChannel(client, chatId),
|
||||||
topicId: 1,
|
topicId: 1,
|
||||||
hidden,
|
hidden,
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import { ArrayPaginated, ChatInviteLink, InputPeerLike, PeersIndex } from '../../types/index.js'
|
import { ArrayPaginated, ChatInviteLink, InputPeerLike, PeersIndex } from '../../types/index.js'
|
||||||
import { makeArrayPaginated } from '../../utils/index.js'
|
import { makeArrayPaginated } from '../../utils/index.js'
|
||||||
import { toInputUser } from '../../utils/peer-utils.js'
|
import { resolvePeer, resolveUser } from '../users/resolve-peer.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
|
||||||
|
|
||||||
// @exported
|
// @exported
|
||||||
export interface GetInviteLinksOffset {
|
export interface GetInviteLinksOffset {
|
||||||
|
@ -58,7 +57,7 @@ export async function getInviteLinks(
|
||||||
_: 'messages.getExportedChatInvites',
|
_: 'messages.getExportedChatInvites',
|
||||||
peer: await resolvePeer(client, chatId),
|
peer: await resolvePeer(client, chatId),
|
||||||
revoked,
|
revoked,
|
||||||
adminId: admin ? toInputUser(await resolvePeer(client, admin), admin) : { _: 'inputUserSelf' },
|
adminId: admin ? await resolveUser(client, admin) : { _: 'inputUserSelf' },
|
||||||
limit,
|
limit,
|
||||||
offsetDate: offset?.date,
|
offsetDate: offset?.date,
|
||||||
offsetLink: offset?.link,
|
offsetLink: offset?.link,
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import { InputPeerLike } from '../../types/index.js'
|
import { InputPeerLike } from '../../types/index.js'
|
||||||
import { toInputUser } from '../../utils/peer-utils.js'
|
import { resolvePeer, resolveUser } from '../users/resolve-peer.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Approve or decline join request to a chat.
|
* Approve or decline join request to a chat.
|
||||||
|
@ -19,7 +18,7 @@ export async function hideJoinRequest(
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const { chatId, user, action } = params
|
const { chatId, user, action } = params
|
||||||
|
|
||||||
const userId = toInputUser(await resolvePeer(client, user), user)
|
const userId = await resolveUser(client, user)
|
||||||
|
|
||||||
await client.call({
|
await client.call({
|
||||||
_: 'messages.hideChatJoinRequest',
|
_: 'messages.hideChatJoinRequest',
|
||||||
|
|
|
@ -2,8 +2,7 @@ import { tl } from '@mtcute/tl'
|
||||||
|
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import { InputText } from '../../types/misc/entities.js'
|
import { InputText } from '../../types/misc/entities.js'
|
||||||
import { toInputUser } from '../../utils/peer-utils.js'
|
import { resolveUser } from '../users/resolve-peer.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
|
||||||
|
|
||||||
const empty: [string, undefined] = ['', undefined]
|
const empty: [string, undefined] = ['', undefined]
|
||||||
|
|
||||||
|
@ -27,7 +26,7 @@ export async function _normalizeInputText(
|
||||||
for (const ent of entities) {
|
for (const ent of entities) {
|
||||||
if (ent._ === 'messageEntityMentionName') {
|
if (ent._ === 'messageEntityMentionName') {
|
||||||
try {
|
try {
|
||||||
const inputPeer = toInputUser(await resolvePeer(client, ent.userId), ent.userId)
|
const inputPeer = await resolveUser(client, ent.userId)
|
||||||
|
|
||||||
const ent_ = ent as unknown as tl.RawInputMessageEntityMentionName
|
const ent_ = ent as unknown as tl.RawInputMessageEntityMentionName
|
||||||
ent_._ = 'inputMessageEntityMentionName'
|
ent_._ = 'inputMessageEntityMentionName'
|
||||||
|
|
|
@ -10,9 +10,8 @@ import {
|
||||||
StickerSourceType,
|
StickerSourceType,
|
||||||
StickerType,
|
StickerType,
|
||||||
} from '../../types/index.js'
|
} from '../../types/index.js'
|
||||||
import { toInputUser } from '../../utils/peer-utils.js'
|
|
||||||
import { _normalizeFileToDocument } from '../files/normalize-file-to-document.js'
|
import { _normalizeFileToDocument } from '../files/normalize-file-to-document.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
import { resolveUser } from '../users/resolve-peer.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new sticker set.
|
* Create a new sticker set.
|
||||||
|
@ -98,7 +97,7 @@ export async function createStickerSet(
|
||||||
progressCallback?: (idx: number, uploaded: number, total: number) => void
|
progressCallback?: (idx: number, uploaded: number, total: number) => void
|
||||||
},
|
},
|
||||||
): Promise<StickerSet> {
|
): Promise<StickerSet> {
|
||||||
const owner = toInputUser(await resolvePeer(client, params.owner), params.owner)
|
const owner = await resolveUser(client, params.owner)
|
||||||
|
|
||||||
const inputStickers: tl.TypeInputStickerSetItem[] = []
|
const inputStickers: tl.TypeInputStickerSetItem[] = []
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import { assertTrue } from '../../../utils/type-assertions.js'
|
import { assertTrue } from '../../../utils/type-assertions.js'
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import { InputPeerLike, InputStickerSet, normalizeInputStickerSet } from '../../types/index.js'
|
import { InputPeerLike, InputStickerSet, normalizeInputStickerSet } from '../../types/index.js'
|
||||||
import { toInputChannel } from '../../utils/index.js'
|
import { resolveChannel } from '../users/resolve-peer.js'
|
||||||
import { resolvePeer } from '../users/resolve-peer.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set group sticker set for a supergroup
|
* Set group sticker set for a supergroup
|
||||||
|
@ -19,7 +18,7 @@ export async function setChatStickerSet(
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
const r = await client.call({
|
const r = await client.call({
|
||||||
_: 'channels.setStickers',
|
_: 'channels.setStickers',
|
||||||
channel: toInputChannel(await resolvePeer(client, chatId), chatId),
|
channel: await resolveChannel(client, chatId),
|
||||||
stickerset: normalizeInputStickerSet(setId),
|
stickerset: normalizeInputStickerSet(setId),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import { Chat, InputPeerLike } from '../../types/index.js'
|
import { Chat, InputPeerLike } from '../../types/index.js'
|
||||||
import { toInputUser } from '../../utils/peer-utils.js'
|
import { resolveUser } from './resolve-peer.js'
|
||||||
import { resolvePeer } from './resolve-peer.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of common chats you have with a given user
|
* Get a list of common chats you have with a given user
|
||||||
|
@ -13,7 +12,7 @@ export async function getCommonChats(client: ITelegramClient, userId: InputPeerL
|
||||||
return client
|
return client
|
||||||
.call({
|
.call({
|
||||||
_: 'messages.getCommonChats',
|
_: 'messages.getCommonChats',
|
||||||
userId: toInputUser(await resolvePeer(client, userId), userId),
|
userId: await resolveUser(client, userId),
|
||||||
maxId: 0,
|
maxId: 0,
|
||||||
limit: 100,
|
limit: 100,
|
||||||
})
|
})
|
||||||
|
|
|
@ -3,8 +3,7 @@ import { tl } from '@mtcute/tl'
|
||||||
import { assertTypeIs } from '../../../utils/type-assertions.js'
|
import { assertTypeIs } from '../../../utils/type-assertions.js'
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import { InputPeerLike, Photo } from '../../types/index.js'
|
import { InputPeerLike, Photo } from '../../types/index.js'
|
||||||
import { toInputUser } from '../../utils/peer-utils.js'
|
import { resolveUser } from './resolve-peer.js'
|
||||||
import { resolvePeer } from './resolve-peer.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a single profile picture of a user by its ID
|
* Get a single profile picture of a user by its ID
|
||||||
|
@ -20,7 +19,7 @@ export async function getProfilePhoto(
|
||||||
): Promise<Photo> {
|
): Promise<Photo> {
|
||||||
const res = await client.call({
|
const res = await client.call({
|
||||||
_: 'photos.getUserPhotos',
|
_: 'photos.getUserPhotos',
|
||||||
userId: toInputUser(await resolvePeer(client, userId), userId),
|
userId: await resolveUser(client, userId),
|
||||||
offset: -1,
|
offset: -1,
|
||||||
limit: 1,
|
limit: 1,
|
||||||
maxId: photoId,
|
maxId: photoId,
|
||||||
|
|
|
@ -6,8 +6,7 @@ import { assertTypeIs } from '../../../utils/type-assertions.js'
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import { ArrayPaginated, InputPeerLike, Photo } from '../../types/index.js'
|
import { ArrayPaginated, InputPeerLike, Photo } from '../../types/index.js'
|
||||||
import { makeArrayPaginated } from '../../utils/index.js'
|
import { makeArrayPaginated } from '../../utils/index.js'
|
||||||
import { toInputUser } from '../../utils/peer-utils.js'
|
import { resolveUser } from './resolve-peer.js'
|
||||||
import { resolvePeer } from './resolve-peer.js'
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a list of profile pictures of a user
|
* Get a list of profile pictures of a user
|
||||||
|
@ -40,7 +39,7 @@ export async function getProfilePhotos(
|
||||||
|
|
||||||
const res = await client.call({
|
const res = await client.call({
|
||||||
_: 'photos.getUserPhotos',
|
_: 'photos.getUserPhotos',
|
||||||
userId: toInputUser(await resolvePeer(client, userId), userId),
|
userId: await resolveUser(client, userId),
|
||||||
offset,
|
offset,
|
||||||
limit,
|
limit,
|
||||||
maxId: Long.ZERO,
|
maxId: Long.ZERO,
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { ITelegramClient } from '../../client.types.js'
|
||||||
import { InputPeerLike, User } from '../../types/index.js'
|
import { InputPeerLike, User } from '../../types/index.js'
|
||||||
import { toInputUser } from '../../utils/peer-utils.js'
|
import { toInputUser } from '../../utils/peer-utils.js'
|
||||||
import { _getUsersBatched } from '../chats/batched-queries.js'
|
import { _getUsersBatched } from '../chats/batched-queries.js'
|
||||||
import { resolvePeer } from './resolve-peer.js'
|
import { resolveUser } from './resolve-peer.js'
|
||||||
import { resolvePeerMany } from './resolve-peer-many.js'
|
import { resolvePeerMany } from './resolve-peer-many.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -17,7 +17,7 @@ import { resolvePeerMany } from './resolve-peer-many.js'
|
||||||
export async function getUsers(client: ITelegramClient, ids: MaybeArray<InputPeerLike>): Promise<(User | null)[]> {
|
export async function getUsers(client: ITelegramClient, ids: MaybeArray<InputPeerLike>): Promise<(User | null)[]> {
|
||||||
if (!Array.isArray(ids)) {
|
if (!Array.isArray(ids)) {
|
||||||
// avoid unnecessary overhead of Promise.all and resolvePeerMany
|
// avoid unnecessary overhead of Promise.all and resolvePeerMany
|
||||||
const res = await _getUsersBatched(client, toInputUser(await resolvePeer(client, ids)))
|
const res = await _getUsersBatched(client, await resolveUser(client, ids))
|
||||||
|
|
||||||
return [res ? new User(res) : null]
|
return [res ? new User(res) : null]
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import { InputPeerLike, Photo } from '../../types/index.js'
|
import { InputPeerLike, Photo } from '../../types/index.js'
|
||||||
import { toInputUser } from '../../utils/peer-utils.js'
|
|
||||||
import { getProfilePhotos } from './get-profile-photos.js'
|
import { getProfilePhotos } from './get-profile-photos.js'
|
||||||
import { resolvePeer } from './resolve-peer.js'
|
import { resolveUser } from './resolve-peer.js'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Iterate over profile photos
|
* Iterate over profile photos
|
||||||
|
@ -31,7 +30,7 @@ export async function* iterProfilePhotos(
|
||||||
): AsyncIterableIterator<Photo> {
|
): AsyncIterableIterator<Photo> {
|
||||||
if (!params) params = {}
|
if (!params) params = {}
|
||||||
|
|
||||||
const peer = toInputUser(await resolvePeer(client, userId), userId)
|
const peer = await resolveUser(client, userId)
|
||||||
|
|
||||||
const { limit = Infinity, chunkSize = 100 } = params
|
const { limit = Infinity, chunkSize = 100 } = params
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ import { getMarkedPeerId, parseMarkedPeerId, toggleChannelIdMark } from '../../.
|
||||||
import { ITelegramClient } from '../../client.types.js'
|
import { ITelegramClient } from '../../client.types.js'
|
||||||
import { MtPeerNotFoundError } from '../../types/errors.js'
|
import { MtPeerNotFoundError } from '../../types/errors.js'
|
||||||
import { InputPeerLike } from '../../types/peers/index.js'
|
import { InputPeerLike } from '../../types/peers/index.js'
|
||||||
import { toInputPeer } from '../../utils/peer-utils.js'
|
import { toInputChannel, toInputPeer, toInputUser } from '../../utils/peer-utils.js'
|
||||||
|
|
||||||
// @available=both
|
// @available=both
|
||||||
/**
|
/**
|
||||||
|
@ -159,3 +159,25 @@ export async function resolvePeer(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shorthand for `resolvePeer` that converts the input peer to `InputUser`.
|
||||||
|
*/
|
||||||
|
export async function resolveUser(
|
||||||
|
client: ITelegramClient,
|
||||||
|
peerId: InputPeerLike,
|
||||||
|
force = false,
|
||||||
|
): Promise<tl.TypeInputUser> {
|
||||||
|
return toInputUser(await resolvePeer(client, peerId, force), peerId)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shorthand for `resolvePeer` that converts the input peer to `InputChannel`.
|
||||||
|
*/
|
||||||
|
export async function resolveChannel(
|
||||||
|
client: ITelegramClient,
|
||||||
|
peerId: InputPeerLike,
|
||||||
|
force = false,
|
||||||
|
): Promise<tl.TypeInputChannel> {
|
||||||
|
return toInputChannel(await resolvePeer(client, peerId, force), peerId)
|
||||||
|
}
|
||||||
|
|
|
@ -184,6 +184,9 @@ export class RepliedMessageInfo {
|
||||||
/**
|
/**
|
||||||
* Offset of the start of the {@link quoteText} in the replied-to message.
|
* Offset of the start of the {@link quoteText} in the replied-to message.
|
||||||
*
|
*
|
||||||
|
* Note that this offset should only be used as a hint, as the actual
|
||||||
|
* quote offset may be different due to message being edited after the quote
|
||||||
|
*
|
||||||
* `null` if not available, in which case it should be assumed that the quote
|
* `null` if not available, in which case it should be assumed that the quote
|
||||||
* starts at `.indexOf(quoteText)` of the replied-to message text.
|
* starts at `.indexOf(quoteText)` of the replied-to message text.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Reference in a new issue