GramJS

auth.ImportBotAuthorization

Login as a bot

Example

const { Api, TelegramClient } = require("telegram");
const { StringSession } = require("telegram/sessions");

const session = new StringSession(""); // You should put your string session here
const client = new TelegramClient(session, apiId, apiHash, {});

(async function run() {
  await client.connect(); // This assumes you have already authenticated with .start()

  const result = await client.invoke(
    new Api.auth.ImportBotAuthorization({
      flags: 43,
      apiId: 43,
      apiHash: "some string here",
      botAuthToken: "some string here",
    })
  );
  console.log(result); // prints the result
})();
import { Api, TelegramClient } from "telegram";
import { StringSession } from "telegram/sessions";

const session = new StringSession(""); // You should put your string session here
const client = new TelegramClient(session, apiId, apiHash, {});

(async function run() {
  await client.connect(); // This assumes you have already authenticated with .start()

  const result: Api.auth.Authorization = await client.invoke(
    new Api.auth.ImportBotAuthorization({
      flags: 43,
      apiId: 43,
      apiHash: "some string here",
      botAuthToken: "some string here",
    })
  );
  console.log(result); // prints the result
})();

Parameters

NameTypeDescription
flagsintReserved for future use
apiIdintApplication identifier (see. App configuration)
apiHashstringApplication identifier hash (see. App configuration)
botAuthTokenstringBot token (see bots)

Result

Returns an auth.Authorization object with information on the new authorization.

Possible errors

CodeTypeDescription
400ACCESS_TOKEN_EXPIREDBot token expired
400ACCESS_TOKEN_INVALIDThe provided token is not valid
400API_ID_INVALIDThe api_id/api_hash combination is invalid
401AUTH_KEY_INVALIDAuth key invalid

Can bots use this method?

Yes

Bots: An introduction for developers