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 b6c8b8e commit b2381c3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@
"dev": "tsc-watch --onSuccess \"tsx ./src/main.ts\"",
"start": "tsx ./src/main.ts",
"deploy": "wrangler deploy --minify src/main.ts",
"sms-auth": "npx tsx src/workflow-functions/bot/scripts/sms-auth.ts",
"user-auth": "npx tsx src/workflow-functions/bot/scripts/user-auth.ts"
"sms-auth": "npx tsx src/bot/mtproto-api/bot/scripts/sms-auth/sms-auth.ts"
},
"keywords": [
"typescript",
Expand Down
30 changes: 20 additions & 10 deletions src/bot/mtproto-api/workrooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,28 +44,38 @@ export async function createChat(context: Context<"issues.labeled", SupportedEve
return { status: 500, reason: "chat_create_failed", content: { error: er } };
}

let botId: bigInt.BigInteger;
let botId: bigInt.BigInteger | undefined;

try {
botId = new mtProto.api.PeerUser({ userId: bigInt(context.config.botId) }).userId;
if (!botId) {
throw new Error("Failed to fetch bot id");
}

console.log("using peer user", botId);
} catch (er) {
console.log(er);
throw new Error(`Failed to add bot to chat: ${JSON.stringify(er)}`);
}

if (!botId) {
console.log("fetching id from bot info");
botId = new mtProto.api.BotInfo({ userId: bigInt(context.config.botId) }).userId || bigInt(0);
try {
botId = new mtProto.api.BotInfo({ userId: bigInt(context.config.botId) }).userId
console.log("using bot info", botId);
} catch (er) {
console.log(er);
}
}

if (botId === bigInt(0)) {
throw new Error("Failed to fetch bot id");
if (!botId) {
try {
botId = new mtProto.api.User({ id: bigInt(context.config.botId), bot: true }).id
console.log("using user", botId);
} catch (er) {
console.log(er);
}
}

if (!botId) {
throw new Error("Failed to get bot id");
}


try {
await mtProto.client.invoke(
new mtProto.api.messages.AddChatUser({
Expand Down

0 comments on commit b2381c3

Please sign in to comment.