feat(client): createSupergroup method
This commit is contained in:
parent
f81329eecf
commit
9edaa438fd
2 changed files with 42 additions and 0 deletions
|
@ -16,6 +16,7 @@ import { start } from './methods/auth/start'
|
|||
import { addChatMembers } from './methods/chats/add-chat-members'
|
||||
import { archiveChats } from './methods/chats/archive-chats'
|
||||
import { createChannel } from './methods/chats/create-channel'
|
||||
import { createSupergroup } from './methods/chats/create-supergroup'
|
||||
import { deleteChannel } from './methods/chats/delete-channel'
|
||||
import { getChatPreview } from './methods/chats/get-chat-preview'
|
||||
import { getChat } from './methods/chats/get-chat'
|
||||
|
@ -365,6 +366,15 @@ export class TelegramClient extends BaseTelegramClient {
|
|||
createChannel(title: string, description?: string): Promise<Chat> {
|
||||
return createChannel.apply(this, arguments)
|
||||
}
|
||||
/**
|
||||
* Create a new supergroup
|
||||
*
|
||||
* @param title Title of the supergroup
|
||||
* @param description (default: `''`) Description of the supergroup
|
||||
*/
|
||||
createSupergroup(title: string, description?: string): Promise<Chat> {
|
||||
return createSupergroup.apply(this, arguments)
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a channel or a supergroup
|
||||
|
|
32
packages/client/src/methods/chats/create-supergroup.ts
Normal file
32
packages/client/src/methods/chats/create-supergroup.ts
Normal file
|
@ -0,0 +1,32 @@
|
|||
import { TelegramClient } from '../../client'
|
||||
import { Chat, MtCuteTypeAssertionError } from '../../types'
|
||||
|
||||
/**
|
||||
* Create a new supergroup
|
||||
*
|
||||
* @param title Title of the supergroup
|
||||
* @param description Description of the supergroup
|
||||
* @internal
|
||||
*/
|
||||
export async function createSupergroup(
|
||||
this: TelegramClient,
|
||||
title: string,
|
||||
description = ''
|
||||
): Promise<Chat> {
|
||||
const res = await this.call({
|
||||
_: 'channels.createChannel',
|
||||
title,
|
||||
about: description,
|
||||
megagroup: true
|
||||
})
|
||||
|
||||
if (!(res._ === 'updates' || res._ === 'updatesCombined')) {
|
||||
throw new MtCuteTypeAssertionError(
|
||||
'createChannel (@ channels.createChannel)',
|
||||
'updates | updatesCombined',
|
||||
res._
|
||||
)
|
||||
}
|
||||
|
||||
return new Chat(this, res.chats[0])
|
||||
}
|
Loading…
Reference in a new issue