From 16746bdbdcdb132f5ca063a2b9ab33f2653c0bf7 Mon Sep 17 00:00:00 2001 From: Keyrxng <106303466+Keyrxng@users.noreply.github.com> Date: Sun, 8 Sep 2024 19:20:13 +0100 Subject: [PATCH] chore: test --- src/bot/mtproto-api/workrooms.ts | 35 ++++++++++++++------------------ 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/src/bot/mtproto-api/workrooms.ts b/src/bot/mtproto-api/workrooms.ts index fa6cb73..e982ed2 100644 --- a/src/bot/mtproto-api/workrooms.ts +++ b/src/bot/mtproto-api/workrooms.ts @@ -1,6 +1,5 @@ import { Context, SupportedEvents } from "#root/types/context"; import { CallbackResult } from "#root/types/proxy.js"; -import bigInt from "big-integer"; import { MtProto } from "./bot/mtproto"; import { Api } from "telegram"; import { addCommentToIssue } from "#root/helpers/add-comment-to-issues.js"; @@ -51,39 +50,35 @@ export async function createChat(context: Context<"issues.labeled", SupportedEve if (!promoteBotToAdmin) { throw new Error("Failed to promote bot to admin"); } + } catch (er) { + console.log("Error in creating chat: ", er); + return { status: 500, reason: "chat_create_failed", content: { error: er } }; + } - const inviteLink = await mtProto.client.invoke( + await context.adapters.supabase.chats.saveChat(chatId, payload.issue.title, payload.issue.node_id); + + try { + + const chatInviteLink = await mtProto.client.invoke( new mtProto.api.messages.ExportChatInvite({ - peer: chatId, - requestNeeded: true, - title: chatName, + peer: await mtProto.client.getEntity(payload.issue.title) }) ); - if (!inviteLink) { - throw new Error("Failed to get invite link"); - } - - context.logger.info("Invite link: ", { inviteLink }); - const [owner, repo] = payload.repository.full_name.split("/"); let link; - if (inviteLink.className === "ChatInviteExported") { - link = inviteLink.link; - } else { - throw new Error("Failed to get invite link"); + if ("link" in chatInviteLink) { + link = chatInviteLink.link; } await addCommentToIssue(context, `Workroom has been created for this task. [Join chat](${link})`, owner, repo, payload.issue.number); - - } catch (er) { - console.log("Error in creating chat: ", er); - return { status: 500, reason: "chat_create_failed", content: { error: er } }; + } catch (err) { + console.log("Error in creating chat invite link: ", err); + return { status: 500, reason: "chat_create_failed", content: { error: err } }; } - await context.adapters.supabase.chats.saveChat(chatId, payload.issue.title, payload.issue.node_id); return { status: 200, reason: "chat_created" }; }