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_EXPIREDAccess token expired.
400ACCESS_TOKEN_INVALIDAccess token invalid.
400API_ID_INVALIDAPI ID invalid.
400API_ID_PUBLISHED_FLOODThis API id was published somewhere, you can't use it now.

Can bots use this method?

Yes

Bots: An introduction for developers