Skip to content

Commit

Permalink
chore: send message after closing chat
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng committed Sep 8, 2024
1 parent 7dd5559 commit 7b10cbc
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/bot/mtproto-api/workrooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<CallbackResult> {
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(
Expand Down Expand Up @@ -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) {
Expand All @@ -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<CallbackResult> {
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 });
Expand Down

0 comments on commit 7b10cbc

Please sign in to comment.