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 fe73844 commit a6c64dc
Showing 1 changed file with 2 additions and 29 deletions.
31 changes: 2 additions & 29 deletions src/bot/mtproto-api/workrooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,41 +23,14 @@ export async function createChat(context: Context<"issues.labeled", SupportedEve
let chatIdBigInt: bigInt.BigInteger;

context.logger.info("Creating chat with name: ", { chatName });
let user;
let userId;
let userAccessHash;
try {
const contacts = await mtProto.client.invoke(new mtProto.api.contacts.GetContacts({}))
if ("users" in contacts) {
user = contacts.users.find((user) => user.id.toJSNumber() === config.botId);

if (!user) {
throw new Error("Bot user not found");
}

if ("id" in user) {
userId = user.id;
}

if ("accessHash" in user) {
userAccessHash = user.accessHash;
}
const bot = await mtProto.client.getPeerId(config.botUsername);

context.logger.info("Bot user found", { user });
}
} catch (er) {
console.log("Failed to get contacts", er);
throw new Error("Failed to get contacts");
}

if (!userId || !userAccessHash) {
throw new Error("Failed to get bot user");
}

const chat = await mtProto.client.invoke(
new mtProto.api.messages.CreateChat({
title: chatName,
users: [new mtProto.api.InputUser({ userId: userId, accessHash: userAccessHash })],
users: [bot],
})
);

Expand Down

0 comments on commit a6c64dc

Please sign in to comment.