feat(client): setChatUsername method
This commit is contained in:
parent
4371e9b63a
commit
cdd01d43fc
2 changed files with 46 additions and 0 deletions
|
@ -32,6 +32,7 @@ import { setChatDefaultPermissions } from './methods/chats/set-chat-default-perm
|
|||
import { setChatDescription } from './methods/chats/set-chat-description'
|
||||
import { setChatPhoto } from './methods/chats/set-chat-photo'
|
||||
import { setChatTitle } from './methods/chats/set-chat-title'
|
||||
import { setChatUsername } from './methods/chats/set-chat-username'
|
||||
import { setSlowMode } from './methods/chats/set-slow-mode'
|
||||
import { unarchiveChats } from './methods/chats/unarchive-chats'
|
||||
import { downloadAsBuffer } from './methods/files/download-buffer'
|
||||
|
@ -603,6 +604,20 @@ export class TelegramClient extends BaseTelegramClient {
|
|||
setChatTitle(chatId: InputPeerLike, title: string): Promise<void> {
|
||||
return setChatTitle.apply(this, arguments)
|
||||
}
|
||||
/**
|
||||
* Change supergroup/channel username
|
||||
*
|
||||
* You must be an administrator and have the appropriate permissions.
|
||||
*
|
||||
* @param chatId Chat ID or current username
|
||||
* @param username New username, or `null` to remove
|
||||
*/
|
||||
setChatUsername(
|
||||
chatId: InputPeerLike,
|
||||
username: string | null
|
||||
): Promise<void> {
|
||||
return setChatUsername.apply(this, arguments)
|
||||
}
|
||||
/**
|
||||
* Set supergroup's slow mode interval.
|
||||
*
|
||||
|
|
31
packages/client/src/methods/chats/set-chat-username.ts
Normal file
31
packages/client/src/methods/chats/set-chat-username.ts
Normal file
|
@ -0,0 +1,31 @@
|
|||
import { TelegramClient } from '../../client'
|
||||
import {
|
||||
InputPeerLike,
|
||||
MtCuteInvalidPeerTypeError,
|
||||
} from '../../types'
|
||||
import { normalizeToInputChannel } from '../../utils/peer-utils'
|
||||
|
||||
/**
|
||||
* Change supergroup/channel username
|
||||
*
|
||||
* You must be an administrator and have the appropriate permissions.
|
||||
*
|
||||
* @param chatId Chat ID or current username
|
||||
* @param username New username, or `null` to remove
|
||||
* @internal
|
||||
*/
|
||||
export async function setChatUsername(
|
||||
this: TelegramClient,
|
||||
chatId: InputPeerLike,
|
||||
username: string | null
|
||||
): Promise<void> {
|
||||
const chat = normalizeToInputChannel(await this.resolvePeer(chatId))
|
||||
if (!chat)
|
||||
throw new MtCuteInvalidPeerTypeError(chatId, 'channel')
|
||||
|
||||
await this.call({
|
||||
_: 'channels.updateUsername',
|
||||
channel: chat,
|
||||
username: username || ''
|
||||
})
|
||||
}
|
Loading…
Reference in a new issue