Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There was a problem using gramjs in electron #645

Open
yl108305 opened this issue Mar 1, 2024 · 1 comment
Open

There was a problem using gramjs in electron #645

yl108305 opened this issue Mar 1, 2024 · 1 comment

Comments

@yl108305
Copy link

yl108305 commented Mar 1, 2024

image
`
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.

@plepisnew
Copy link

What error are you getting?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants