Telegram-user: add login method picker

This commit is contained in:
Muhammed Mukhthar CM 2026-01-23 05:22:52 +00:00
parent 26ac86cbb5
commit c9fe83b3f7
2 changed files with 13 additions and 5 deletions

View File

@ -28,6 +28,7 @@
"@mtcute/core": "^0.27.6",
"@mtcute/dispatcher": "^0.27.6",
"@mtcute/node": "^0.27.6",
"@clack/prompts": "^0.8.2",
"qrcode-terminal": "^0.12.0",
"clawdbot": "workspace:*"
}

View File

@ -1,6 +1,7 @@
import qrcode from "qrcode-terminal";
import { createInterface } from "node:readline/promises";
import { stdin as input, stdout as output } from "node:process";
import { isCancel, select } from "@clack/prompts";
import type { RuntimeEnv } from "clawdbot/plugin-sdk";
import { createTelegramUserClient } from "./client.js";
@ -17,11 +18,17 @@ async function promptText(message: string): Promise<string> {
}
async function promptLoginMode(): Promise<"qr" | "phone"> {
const response = await promptText("Login method (qr/phone) [qr]: ");
const normalized = response.trim().toLowerCase();
if (!normalized) return "qr";
if (normalized === "phone" || normalized === "otp") return "phone";
return "qr";
if (!input.isTTY || !output.isTTY) return "qr";
const response = await select({
message: "Telegram login method",
options: [
{ value: "qr", label: "QR code (scan with Telegram)" },
{ value: "phone", label: "Phone code (SMS/Telegram)" },
],
initialValue: "qr",
});
if (isCancel(response)) return "qr";
return response;
}
export async function loginTelegramUser(params: {