feat(client): createSupergroup method

This commit is contained in:
teidesu 2021-04-10 21:08:04 +03:00
parent f81329eecf
commit 9edaa438fd
2 changed files with 42 additions and 0 deletions

View file

@ -16,6 +16,7 @@ import { start } from './methods/auth/start'
import { addChatMembers } from './methods/chats/add-chat-members' import { addChatMembers } from './methods/chats/add-chat-members'
import { archiveChats } from './methods/chats/archive-chats' import { archiveChats } from './methods/chats/archive-chats'
import { createChannel } from './methods/chats/create-channel' import { createChannel } from './methods/chats/create-channel'
import { createSupergroup } from './methods/chats/create-supergroup'
import { deleteChannel } from './methods/chats/delete-channel' import { deleteChannel } from './methods/chats/delete-channel'
import { getChatPreview } from './methods/chats/get-chat-preview' import { getChatPreview } from './methods/chats/get-chat-preview'
import { getChat } from './methods/chats/get-chat' import { getChat } from './methods/chats/get-chat'
@ -365,6 +366,15 @@ export class TelegramClient extends BaseTelegramClient {
createChannel(title: string, description?: string): Promise<Chat> { createChannel(title: string, description?: string): Promise<Chat> {
return createChannel.apply(this, arguments) 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 * Delete a channel or a supergroup

View 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])
}