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
Name | Type | Description |
---|---|---|
flags | int | Reserved for future use |
apiId | int | Application identifier (see. App configuration) |
apiHash | string | Application identifier hash (see. App configuration) |
botAuthToken | string | Bot token (see bots) |
Result
Returns an auth.Authorization object with information on the new authorization.
Possible errors
Code | Type | Description |
---|---|---|
400 | ACCESS_TOKEN_EXPIRED | Access token expired. |
400 | ACCESS_TOKEN_INVALID | Access token invalid. |
400 | API_ID_INVALID | API ID invalid. |
400 | API_ID_PUBLISHED_FLOOD | This API id was published somewhere, you can't use it now. |
Can bots use this method?
Yes