add userbot login options via env vars
This commit is contained in:
parent
c3319fafe1
commit
3c7afeec61
4 changed files with 17 additions and 5 deletions
|
|
@ -1,2 +1,5 @@
|
|||
API_ID=
|
||||
API_HASH=
|
||||
USERBOT_PHONE=
|
||||
USERBOT_2FACODE=
|
||||
USERBOT_PASSWORD=
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "mtproto_exporter",
|
||||
"type": "module",
|
||||
"version": "0.0.1",
|
||||
"version": "1.0.0",
|
||||
"packageManager": "pnpm@10.6.5",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
|
|
|
|||
|
|
@ -3,8 +3,12 @@ import process from "node:process";
|
|||
const API_ID = Number.parseInt(process.env.API_ID!);
|
||||
const API_HASH = process.env.API_HASH!;
|
||||
|
||||
const USERBOT_PHONE = process.env.USERBOT_PHONE;
|
||||
const USERBOT_2FACODE = process.env.USERBOT_2FACODE;
|
||||
const USERBOT_PASSWORD = process.env.USERBOT_PASSWORD;
|
||||
|
||||
if (Number.isNaN(API_ID) || !API_HASH) {
|
||||
throw new Error("API_ID or API_HASH not set!");
|
||||
}
|
||||
|
||||
export { API_HASH, API_ID };
|
||||
export { API_HASH, API_ID, USERBOT_2FACODE, USERBOT_PASSWORD, USERBOT_PHONE };
|
||||
|
|
|
|||
11
src/main.ts
11
src/main.ts
|
|
@ -58,6 +58,14 @@ const tg = new TelegramClient({
|
|||
|
||||
const dp = Dispatcher.for(tg);
|
||||
|
||||
const user = await tg.start({
|
||||
phone: () => env.USERBOT_PHONE ?? tg.input("Phone > "),
|
||||
code: () => env.USERBOT_2FACODE ?? tg.input("Code > "),
|
||||
password: () => env.USERBOT_PASSWORD ?? tg.input("Password > "),
|
||||
});
|
||||
|
||||
console.log("Logged in as", user.username);
|
||||
|
||||
registry.registerMetric(metrics.newStaticPeerInfoGauge(tg));
|
||||
registry.registerMetric(metrics.newUnreadCountGauge(tg));
|
||||
registry.registerMetric(metrics.newMessagesCounter(dp));
|
||||
|
|
@ -69,6 +77,3 @@ if (keywords.length > 0) {
|
|||
if (cli["words-counter"]) {
|
||||
registry.registerMetric(metrics.newWordsCounter(dp));
|
||||
}
|
||||
|
||||
const user = await tg.start();
|
||||
console.log("Logged in as", user.username);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue