From 927c39f848f1b0aaee64ccaf83f7fb23722e8837 Mon Sep 17 00:00:00 2001 From: Keyrxng <106303466+Keyrxng@users.noreply.github.com> Date: Sun, 8 Sep 2024 16:09:11 +0100 Subject: [PATCH] chore: test --- src/bot/mtproto-api/workrooms.ts | 35 +++++++++++++++++--------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/bot/mtproto-api/workrooms.ts b/src/bot/mtproto-api/workrooms.ts index 61ed6a8..e182646 100644 --- a/src/bot/mtproto-api/workrooms.ts +++ b/src/bot/mtproto-api/workrooms.ts @@ -4,15 +4,16 @@ import bigInt from "big-integer"; import { MtProto } from "./bot/mtproto"; export async function createChat(context: Context<"issues.labeled", SupportedEvents["issues.labeled"]>): Promise { - try { - const { payload, env, config } = context; - const chatName = payload.issue.title; - - const mtProto = new MtProto(context); - await mtProto.initialize(); + const { payload, env, config } = context; + const chatName = payload.issue.title; - context.logger.info("Creating chat with name: ", { chatName }); + const mtProto = new MtProto(context); + await mtProto.initialize(); + let chatId: number; + let chatIdBigInt: bigInt.BigInteger; + context.logger.info("Creating chat with name: ", { chatName }); + try { const chat = await mtProto.client.invoke( new mtProto.api.messages.CreateChat({ title: chatName, @@ -20,8 +21,7 @@ export async function createChat(context: Context<"issues.labeled", SupportedEve }) ); - let chatId: number; - let chatIdBigInt: bigInt.BigInteger; + if ("chats" in chat.updates) { chatId = chat.updates.chats[0].id.toJSNumber(); @@ -31,22 +31,25 @@ export async function createChat(context: Context<"issues.labeled", SupportedEve } await context.adapters.supabase.chats.saveChat(chatId, payload.issue.title, payload.issue.node_id); + } catch (er) { + context.logger.error("Failed to create chat", { er }); + return { status: 500, reason: "chat_create_failed", content: { error: er } }; + } - + try { const botId = config.botId; - await mtProto.client.invoke( new mtProto.api.messages.AddChatUser({ chatId: chatIdBigInt, - userId: bigInt(botId) + userId: bigInt(botId), + fwdLimit: 50, }) ); - - return { status: 200, reason: "chat_created" }; } catch (er) { - context.logger.error("Failed to create chat", { er }); - return { status: 500, reason: "chat_creation_failed", content: { error: er } }; + console.log(er); + throw new Error(`Failed to add bot to chat: ${JSON.stringify(er)}`); } + } export async function closeChat(context: Context<"issues.closed", SupportedEvents["issues.closed"]>): Promise {