`
import { TelegramClient } from "telegram";
import { StringSession } from "telegram/sessions";
import { ipc } from "@/utils/ipcRenderer";
/**
@name initializeGramjs
*/
export async function initGramjs(session) {
console.log(1);
let config = await ipc.invoke("controller.tg.getConfig", {});
console.log("config", config);
let client = new TelegramClient(
new StringSession(session || ""),
config.apiId,
config.apiHash,
{
connectionRetries: 5,
useWSS: false,
},
);
await client.connect();
return client;
}
/**`
@name loginWithQRCodeToObtainTheQRCode
*/
export async function qrLoginGetQr(twoPas, qrCb) {
let client = await initGramjs("");
let globalConfig = await ipc.invoke("controller.tg.getConfig", {});
const user = await client.signInUserWithQrCode(
{ apiId: globalConfig.apiId, apiHash: globalConfig.apiHash },
{
onError: async function (p1) {
console.log("error", p1);
// true = stop the authentication processes
return true;
},
qrCode: async (code) => {
console.log("Convert the next string to a QR code and scan it");
console.log(tg://login?token=${code.token.toString("base64url")});
qrCb(tg://login?token=${code.token.toString("base64url")});
},
password: async (hint) => {
return twoPas;
},
},
);
console.log("user is", user);
return { x: 1 };
}
`
I tried to use gramjs on electron, but it doesn't seem to work, I get an error when I get the login QR code, can someone help me
My code is like this. I called the qrLoginGetQr method, which will call initGramjs. An error occurred here.
` import { TelegramClient } from "telegram"; import { StringSession } from "telegram/sessions"; import { ipc } from "@/utils/ipcRenderer"; /**
/**`
tg://login?token=${code.token.toString("base64url")}
); qrCb(tg://login?token=${code.token.toString("base64url")}
); }, password: async (hint) => { return twoPas; }, }, ); console.log("user is", user); return { x: 1 }; } `I tried to use gramjs on electron, but it doesn't seem to work, I get an error when I get the login QR code, can someone help me My code is like this. I called the qrLoginGetQr method, which will call initGramjs. An error occurred here.