代码之家  ›  专栏  ›  技术社区  ›  Sando Philip

Gramjs多次登录

  •  -1
  • Sando Philip  · 技术社区  · 2 年前

    如何使用gramjs设置多个会话?文档中没有任何关于多会话的内容。

    我已经尝试了以下代码。

    import { TelegramClient } from "telegram";
    import { StringSession } from "telegram/sessions";
    import input from "input"; // npm i input
    
    const apiId = 123456;
    const apiHash = "123456abcdfg";
    const stringSession = new StringSession(""); // fill this later with the value from session.save()
    
    (async () => {
      console.log("Loading interactive example...");
      const client = new TelegramClient(stringSession, apiId, apiHash, {
        connectionRetries: 5,
      });
    
      await client.start({
        phoneNumber: async () => await input.text("Please enter your number: "),
        password: async () => await input.text("Please enter your password: "),
        phoneCode: async () =>
          await input.text("Please enter the code you received: "),
        onError: (err) => console.log(err),
      });
    
      console.log("You should now be connected.");
      console.log(client.session.save()); // Save this string to avoid logging in again
    
      await client.sendMessage("me", { message: "Hello!" });
    })();
    
    0 回复  |  直到 2 年前