gram-js / gramjs

NodeJS/Browser MTProto API Telegram client library,
MIT License
1.28k stars 179 forks source link

Cannot send requests while disconnected #649

Closed alvvaysxxx closed 7 months ago

alvvaysxxx commented 7 months ago
      const session = new StringSession("");
      const client = new TelegramClient(session, user.apiId, user.apiHash, {});
      client.connect();
      const result = await client.invoke(
        new Api.auth.SendCode({
          phoneNumber: user.phone,
          apiId: parseInt(user.apiId),
          apiHash: user.apiHash,
          settings: new Api.CodeSettings({
            allowFlashcall: true,
            currentNumber: true,
            allowAppHash: true,
            allowMissedCall: true,
          }),
        })
      );

I'm building Telegram bot which gives users their session string. I cannot use client.start() because data should be received partially, message by message, so i chose manually collecting data from user, then sending security code and then prompt user to enter it, then getting session by logging into account. In the code above i tried to send code to user, but it says Cannot send requests while disconnected. You need to call .connect()

alvvaysxxx commented 7 months ago

Just figured it out. I didn't use the await while connecting