Skip to content

Commit

Permalink
chore: test
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng committed Sep 8, 2024
1 parent 8d3e52e commit 5f54641
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/bot/mtproto-api/workrooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,23 @@ export async function createChat(context: Context<"issues.labeled", SupportedEve
return { status: 500, reason: "chat_create_failed", content: { error: er } };
}

const dialogs = await mtProto.client.invoke(new mtProto.api.messages.GetDialogs({ limit: 100 }));

let bot;
if ("users" in dialogs) {
const users = dialogs.users;
bot = users.find((user) => user.id.toJSNumber() === config.botId);

if (!bot) {
throw new Error("Bot not found in users list");
}
}

try {
const botId = config.botId;
await mtProto.client.invoke(
new mtProto.api.messages.AddChatUser({
chatId: chatIdBigInt,
userId: botId,
userId: bot?.id,
fwdLimit: 50,
})
);
Expand All @@ -58,6 +69,7 @@ export async function createChat(context: Context<"issues.labeled", SupportedEve
throw new Error(`Failed to add bot to chat: ${JSON.stringify(er)}`);
}

return { status: 200, reason: "chat_created" };
}

export async function closeChat(context: Context<"issues.closed", SupportedEvents["issues.closed"]>): Promise<CallbackResult> {
Expand Down

0 comments on commit 5f54641

Please sign in to comment.