From 7b10cbcd1e368d8758f4c7082db4053c04e7d362 Mon Sep 17 00:00:00 2001 From: Keyrxng <106303466+Keyrxng@users.noreply.github.com> Date: Sun, 8 Sep 2024 14:37:28 +0100 Subject: [PATCH] chore: send message after closing chat --- src/bot/mtproto-api/workrooms.ts | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/bot/mtproto-api/workrooms.ts b/src/bot/mtproto-api/workrooms.ts index 2ad2339..20cce1b 100644 --- a/src/bot/mtproto-api/workrooms.ts +++ b/src/bot/mtproto-api/workrooms.ts @@ -30,12 +30,11 @@ export async function createChat(context: Context<"issues.labeled", SupportedEve export async function closeChat(context: Context<"issues.closed", SupportedEvents["issues.closed"]>): Promise { try { const { payload, adapters: { supabase: { chats } } } = context; - const chatName = payload.issue.title; const mtProto = new MtProto(context); await mtProto.initialize(); - context.logger.info("Closing chat with name: ", { chatName }); + context.logger.info("Closing chat with name: ", { chatName: payload.issue.title }); const chat = await chats.getChatByTaskNodeId(payload.issue.node_id); const fetchChat = await mtProto.client.invoke( @@ -74,7 +73,12 @@ export async function closeChat(context: Context<"issues.closed", SupportedEvent } } - + await mtProto.client.invoke( + new mtProto.api.messages.SendMessage({ + message: "This task has been closed and this chat has been archived.", + peer: new mtProto.api.InputPeerChat({ chatId: chat.chatId }), + }) + ); return { status: 200, reason: "chat_closed" }; } catch (er) { @@ -85,12 +89,16 @@ export async function closeChat(context: Context<"issues.closed", SupportedEvent export async function reopenChat(context: Context<"issues.reopened", SupportedEvents["issues.reopened"]>): Promise { try { - const { payload, env, config } = context; - const chatName = payload.issue.title; + const { payload, env, adapters: { supabase: { chats } } } = context; const mtProto = new MtProto(context); await mtProto.initialize(); + + /** + * TODO: Are we re-opening the old chat or creating a new one? + */ + return { status: 200, reason: "chat_reopened" }; } catch (er) { context.logger.error("Failed to reopen chat", { er });