feat(client): setChatTitle and setChatDescription methods
This commit is contained in:
parent
173647dda6
commit
a06c03eda9
3 changed files with 97 additions and 0 deletions
|
@ -28,7 +28,9 @@ import { getChat } from './methods/chats/get-chat'
|
||||||
import { getFullChat } from './methods/chats/get-full-chat'
|
import { getFullChat } from './methods/chats/get-full-chat'
|
||||||
import { joinChat } from './methods/chats/join-chat'
|
import { joinChat } from './methods/chats/join-chat'
|
||||||
import { leaveChat } from './methods/chats/leave-chat'
|
import { leaveChat } from './methods/chats/leave-chat'
|
||||||
|
import { setChatDescription } from './methods/chats/set-chat-description'
|
||||||
import { setChatPhoto } from './methods/chats/set-chat-photo'
|
import { setChatPhoto } from './methods/chats/set-chat-photo'
|
||||||
|
import { setChatTitle } from './methods/chats/set-chat-title'
|
||||||
import { unarchiveChats } from './methods/chats/unarchive-chats'
|
import { unarchiveChats } from './methods/chats/unarchive-chats'
|
||||||
import { downloadAsBuffer } from './methods/files/download-buffer'
|
import { downloadAsBuffer } from './methods/files/download-buffer'
|
||||||
import { downloadToFile } from './methods/files/download-file'
|
import { downloadToFile } from './methods/files/download-file'
|
||||||
|
@ -524,6 +526,20 @@ export class TelegramClient extends BaseTelegramClient {
|
||||||
leaveChat(chatId: InputPeerLike, clear?: boolean): Promise<void> {
|
leaveChat(chatId: InputPeerLike, clear?: boolean): Promise<void> {
|
||||||
return leaveChat.apply(this, arguments)
|
return leaveChat.apply(this, arguments)
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Change chat description
|
||||||
|
*
|
||||||
|
* You must be an administrator and have the appropriate permissions.
|
||||||
|
*
|
||||||
|
* @param chatId Chat ID or username
|
||||||
|
* @param description New chat description, 0-255 characters
|
||||||
|
*/
|
||||||
|
setChatDescription(
|
||||||
|
chatId: InputPeerLike,
|
||||||
|
description: string
|
||||||
|
): Promise<void> {
|
||||||
|
return setChatDescription.apply(this, arguments)
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Set a new chat photo or video.
|
* Set a new chat photo or video.
|
||||||
*
|
*
|
||||||
|
@ -544,6 +560,17 @@ export class TelegramClient extends BaseTelegramClient {
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
return setChatPhoto.apply(this, arguments)
|
return setChatPhoto.apply(this, arguments)
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Change chat title
|
||||||
|
*
|
||||||
|
* You must be an administrator and have the appropriate permissions.
|
||||||
|
*
|
||||||
|
* @param chatId Chat ID or username
|
||||||
|
* @param title New chat title, 1-255 characters
|
||||||
|
*/
|
||||||
|
setChatTitle(chatId: InputPeerLike, title: string): Promise<void> {
|
||||||
|
return setChatTitle.apply(this, arguments)
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* Unarchive one or more chats
|
* Unarchive one or more chats
|
||||||
*
|
*
|
||||||
|
|
31
packages/client/src/methods/chats/set-chat-description.ts
Normal file
31
packages/client/src/methods/chats/set-chat-description.ts
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
|
import {
|
||||||
|
InputPeerLike,
|
||||||
|
MtCuteInvalidPeerTypeError,
|
||||||
|
} from '../../types'
|
||||||
|
import { normalizeToInputPeer } from '../../utils/peer-utils'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change chat description
|
||||||
|
*
|
||||||
|
* You must be an administrator and have the appropriate permissions.
|
||||||
|
*
|
||||||
|
* @param chatId Chat ID or username
|
||||||
|
* @param description New chat description, 0-255 characters
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
export async function setChatDescription(
|
||||||
|
this: TelegramClient,
|
||||||
|
chatId: InputPeerLike,
|
||||||
|
description: string
|
||||||
|
): Promise<void> {
|
||||||
|
const chat = normalizeToInputPeer(await this.resolvePeer(chatId))
|
||||||
|
if (!(chat._ === 'inputPeerChat' || chat._ === 'inputPeerChannel'))
|
||||||
|
throw new MtCuteInvalidPeerTypeError(chatId, 'chat or channel')
|
||||||
|
|
||||||
|
await this.call({
|
||||||
|
_: 'messages.editChatAbout',
|
||||||
|
peer: chat,
|
||||||
|
about: description
|
||||||
|
})
|
||||||
|
}
|
39
packages/client/src/methods/chats/set-chat-title.ts
Normal file
39
packages/client/src/methods/chats/set-chat-title.ts
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
import { TelegramClient } from '../../client'
|
||||||
|
import {
|
||||||
|
InputPeerLike,
|
||||||
|
MtCuteInvalidPeerTypeError,
|
||||||
|
} from '../../types'
|
||||||
|
import { normalizeToInputChannel, normalizeToInputPeer } from '../../utils/peer-utils'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change chat title
|
||||||
|
*
|
||||||
|
* You must be an administrator and have the appropriate permissions.
|
||||||
|
*
|
||||||
|
* @param chatId Chat ID or username
|
||||||
|
* @param title New chat title, 1-255 characters
|
||||||
|
* @internal
|
||||||
|
*/
|
||||||
|
export async function setChatTitle(
|
||||||
|
this: TelegramClient,
|
||||||
|
chatId: InputPeerLike,
|
||||||
|
title: string
|
||||||
|
): Promise<void> {
|
||||||
|
const chat = normalizeToInputPeer(await this.resolvePeer(chatId))
|
||||||
|
if (!(chat._ === 'inputPeerChat' || chat._ === 'inputPeerChannel'))
|
||||||
|
throw new MtCuteInvalidPeerTypeError(chatId, 'chat or channel')
|
||||||
|
|
||||||
|
if (chat._ === 'inputPeerChat') {
|
||||||
|
await this.call({
|
||||||
|
_: 'messages.editChatTitle',
|
||||||
|
chatId: chat.chatId,
|
||||||
|
title
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
await this.call({
|
||||||
|
_: 'channels.editTitle',
|
||||||
|
channel: normalizeToInputChannel(chat)!,
|
||||||
|
title
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue