From 9edaa438fd77843577fea2d27aa78b3523b32421 Mon Sep 17 00:00:00 2001 From: teidesu Date: Sat, 10 Apr 2021 21:08:04 +0300 Subject: [PATCH] feat(client): createSupergroup method --- packages/client/src/client.ts | 10 ++++++ .../src/methods/chats/create-supergroup.ts | 32 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 packages/client/src/methods/chats/create-supergroup.ts diff --git a/packages/client/src/client.ts b/packages/client/src/client.ts index 1e3a1034..bf418d1c 100644 --- a/packages/client/src/client.ts +++ b/packages/client/src/client.ts @@ -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 { 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 { + return createSupergroup.apply(this, arguments) + } /** * Delete a channel or a supergroup diff --git a/packages/client/src/methods/chats/create-supergroup.ts b/packages/client/src/methods/chats/create-supergroup.ts new file mode 100644 index 00000000..a5300d93 --- /dev/null +++ b/packages/client/src/methods/chats/create-supergroup.ts @@ -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 { + 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]) +}