# Table of Contents - [FAQ | GramJS](#faq-gramjs) - [Authentication | GramJS](#authentication-gramjs) - [Advanced Installation | GramJS](#advanced-installation-gramjs) - [Integration with React | GramJS](#integration-with-react-gramjs) - [account.AcceptAuthorization | GramJS](#account-acceptauthorization-gramjs) - [account.CancelPasswordEmail | GramJS](#account-cancelpasswordemail-gramjs) - [account.ChangeAuthorizationSettings | GramJS](#account-changeauthorizationsettings-gramjs) - [account.ChangePhone | GramJS](#account-changephone-gramjs) - [account.CheckUsername | GramJS](#account-checkusername-gramjs) - [account.ConfirmPasswordEmail | GramJS](#account-confirmpasswordemail-gramjs) - [account.ConfirmPhone | GramJS](#account-confirmphone-gramjs) - [account.CreateTheme | GramJS](#account-createtheme-gramjs) - [account.DeclinePasswordReset | GramJS](#account-declinepasswordreset-gramjs) - [account.DeleteAccount | GramJS](#account-deleteaccount-gramjs) - [account.DeleteSecureValue | GramJS](#account-deletesecurevalue-gramjs) - [account.FinishTakeoutSession | GramJS](#account-finishtakeoutsession-gramjs) - [account.GetAccountTTL | GramJS](#account-getaccountttl-gramjs) - [account.GetAllSecureValues | GramJS](#account-getallsecurevalues-gramjs) --- # FAQ | GramJS FAQ[](https://gram.js.org/faq#faq) ----------------------------------- > Frequently asked questions Table of Contents[](https://gram.js.org/faq#table-of-contents) --------------------------------------------------------------- * [How do I stop logging?](https://gram.js.org/faq#how-do-i-stop-logging) * [Can I use a proxy?](https://gram.js.org/faq#can-i-use-a-proxy) How do I stop logging?[](https://gram.js.org/faq#how-do-i-stop-logging) ------------------------------------------------------------------------ logging is enabled by default to the most verbose option.to remove it you can do the following client.setLogLevel("none"); // no logging client.setLogLevel("error"); // only errors client.setLogLevel("warn"); // warnings too client.setLogLevel("info"); // info too client.setLogLevel("debug"); // everything client.setLogLevel("none"); // no logging client.setLogLevel("error"); // only errors client.setLogLevel("warn"); // warnings too client.setLogLevel("info"); // info too client.setLogLevel("debug"); // everything Can I use a proxy?[](https://gram.js.org/faq#can-i-use-a-proxy) ---------------------------------------------------------------- Yes you can, but only on Node! Currently only socks5,4 and MTProto proxies are supported. HTTP proxies are not supported as they required a completely different connection type. --- # Authentication | GramJS Authentication[](https://gram.js.org/getting-started/authorization#authentication) ----------------------------------------------------------------------------------- Signing in Table of Contents[](https://gram.js.org/getting-started/authorization#table-of-contents) ----------------------------------------------------------------------------------------- * [Getting API ID and API HASH](https://gram.js.org/getting-started/authorization#getting-api-id-and-api-hash) * [Logging in as a Bot](https://gram.js.org/getting-started/authorization#logging-in-as-a-bot) * [Logging in as a User](https://gram.js.org/getting-started/authorization#logging-in-as-a-user) * [Using MTProxies and Socks5 Proxies.](https://gram.js.org/getting-started/authorization#using-mtproxies-and-socks5-proxies) * [Persistent Session](https://gram.js.org/getting-started/authorization#persistent-session) * [String Session](https://gram.js.org/getting-started/authorization#string-session) * [Store Session](https://gram.js.org/getting-started/authorization#store-session) Getting API ID and API HASH[](https://gram.js.org/getting-started/authorization#getting-api-id-and-api-hash) ------------------------------------------------------------------------------------------------------------- Before working with Telegram’s API, you need to get your own API ID and hash: 1. [Login to your Telegram account](https://my.telegram.org/) with the phone number of the developer account to use. 2. Click under API Development tools. 3. A _Create new application_ window will appear. Fill in your application details. There is no need to enter any _URL_, and only the first two fields (_App title_ and _Short name_) can currently be changed later. 4. Click on _Create application_ at the end. Remember that your **API hash is secret** and Telegram won't let you revoke it. Don’t post it anywhere! Logging in as a Bot[](https://gram.js.org/getting-started/authorization#logging-in-as-a-bot) --------------------------------------------------------------------------------------------- Using GramJS you can use a bot token to log in. Doing this is simple const { TelegramClient } = require("telegram"); const { StringSession } = require("telegram/sessions"); const stringSession = ""; // leave this empty for now const BOT_TOKEN = ""; // put your bot token here (async () => { const client = new TelegramClient( new StringSession(stringSession), apiId, apiHash, { connectionRetries: 5 } ); await client.start({ botAuthToken: BOT_TOKEN, }); console.log(client.session.save()); })(); import { TelegramClient } from "telegram"; import { StringSession } from "telegram/sessions"; const stringSession = ""; // leave this empty for now const BOT_TOKEN = ""; // put your bot token here (async () => { const client = new TelegramClient( new StringSession(stringSession), apiId, apiHash, { connectionRetries: 5 } ); await client.start({ botAuthToken: BOT_TOKEN, }); console.log(client.session.save()); })(); Underneath this is just calling the RAW function `ImportBotAuthorization`. you can leave the string session empty for now. Logging in as a User[](https://gram.js.org/getting-started/authorization#logging-in-as-a-user) ----------------------------------------------------------------------------------------------- Logging in as a user is a bit more complex because you'll need to provide callbacks for when you receive the code from telegram. you can use the [input](https://www.npmjs.com/package/input) package to manage that on Node or [prompt](https://developer.mozilla.org/en-US/docs/Web/API/Window/prompt) on the browser const { TelegramClient } = require("telegram"); const { StringSession } = require("telegram/sessions"); const input = require("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("number ?"), password: async () => await input.text("password?"), phoneCode: async () => await input.text("Code ?"), 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!" }); })(); 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("number ?"), password: async () => await input.text("password?"), phoneCode: async () => await input.text("Code ?"), 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!" }); })(); Using MTProxies and Socks5 Proxies.[](https://gram.js.org/getting-started/authorization#using-mtproxies-and-socks5-proxies) ---------------------------------------------------------------------------------------------------------------------------- You can also use MTProxies or a normal Socks proxy to connect to telegram servers. const { TelegramClient } = require("telegram"); const apiId = 123456; const apiHash = "123456abcdfg"; (async () => { console.log("Loading interactive example..."); const client = new TelegramClient("session_name", apiId, apiHash, { useWSS: false, // Important. Most proxies cannot use SSL. proxy: { ip: "123.123.123.123", // Proxy host (IP or hostname) port: 123, // Proxy port MTProxy: false, // Whether it's an MTProxy or a normal Socks one secret: "00000000000000000000000000000000", // If used MTProxy then you need to provide a secret (or zeros). socksType: 5, // If used Socks you can choose 4 or 5. timeout: 2, // Timeout (in seconds) for connection, }, }); await client.connect(); console.log("You should now be connected."); })(); import { TelegramClient } from "telegram"; const apiId = 123456; const apiHash = "123456abcdfg"; (async () => { console.log("Loading interactive example..."); const client = new TelegramClient("session_name", apiId, apiHash, { useWSS: false, // Important. Most proxies cannot use SSL. proxy: { ip: "123.123.123.123", // Proxy host (IP or hostname) port: 123, // Proxy port MTProxy: false, // Whether it's an MTProxy or a normal Socks one secret: "00000000000000000000000000000000", // If used MTProxy then you need to provide a secret (or zeros). socksType: 5, // If used Socks you can choose 4 or 5. timeout: 2, // Timeout (in seconds) for connection, }, }); await client.connect(); console.log("You should now be connected."); })(); Persistent Session[](https://gram.js.org/getting-started/authorization#persistent-session) ------------------------------------------------------------------------------------------- To avoid having to logging each time you'll need to save the session after logging in. There are multiple types of sessions with the easiest being `StringSession` that will provide an Authorization string for you to use again. You can create your own Session by subclassing the `MemorySession` class. If you have async logic in your custom session put it in the `load()` function that's called before loading a session. String Session[](https://gram.js.org/getting-started/authorization#string-session) ----------------------------------------------------------------------------------- You can import it from `telegram/session` const { StringSession } = require("telegram/sessions"); import { StringSession } from "telegram/sessions"; If you're using it for the first login you need to provide an empty String to the constructor const stringSession = new StringSession(""); After logging in you'll need to call the `.save()` method to receive the string You can either do that by calling it directly on the `stringSession` variable or by using `client.session` console.log(client.session.save()); console.log(stringSession.save()); Store Session[](https://gram.js.org/getting-started/authorization#store-session) --------------------------------------------------------------------------------- Store session uses [store2](https://www.npmjs.com/package/store2) with the help of [node-localstorage](https://www.npmjs.com/search?q=node-localstorage) to save the session automatically in files. it's useful to save entities so you can access them later with just their ID and lowers the amount of requests needed to the telegram server. You just need to provide a session name to save it with const { StringSession } = require("telegram/sessions"); const storeSession = new StoreSession("my_session"); const client = new TelegramClient(storeSession, apiId, apiHash, { connectionRetries: 5, }); import { StringSession } from "telegram/sessions"; const storeSession = new StoreSession("my_session"); const client = new TelegramClient(storeSession, apiId, apiHash, { connectionRetries: 5, }); This session is still in Alpha and not tested that much so it might break. use carefully. --- # Advanced Installation | GramJS Advanced Installation[](https://gram.js.org/introduction/advanced-installation#advanced-installation) ------------------------------------------------------------------------------------------------------ This page will walk you through various types of installation Table of Contents[](https://gram.js.org/introduction/advanced-installation#table-of-contents) ---------------------------------------------------------------------------------------------- * [Node.js](https://gram.js.org/introduction/advanced-installation#nodejs) * [Browser](https://gram.js.org/introduction/advanced-installation#browser) Node.js[](https://gram.js.org/introduction/advanced-installation#nodejs) ------------------------------------------------------------------------- GramJS works out of the box in node and can be installed from npm: $ npm i telegram > The package name is telegram not gramjs. You can also install it from github where you will find the latest changes (possibly not stable): $ git clone https://github.com/gram-js/gramjs $ tsc Browser[](https://gram.js.org/introduction/advanced-installation#browser) -------------------------------------------------------------------------- GramJS uses webpack to provide a browser file if needed. You can also import it into your project and it will compile fine. To get a JS file first clone the repo and install all dev dependencies then simply use $ webpack you will find the bundle file in the `browser` folder. Currently, bundle files aren't provided separately and need to be compiled. GramJS has [a telegram group](https://t.me/GramJSChat) where you can ask for a file if building is out of the option for you. --- # Integration with React | GramJS Integration with React[](https://gram.js.org/introduction/integration-with-react#integration-with-react) --------------------------------------------------------------------------------------------------------- In this article, we will look at the combination of gramjs and React After creating the project and installing all the necessary dependencies, you can use gramjs in your projects Table of Contents[](https://gram.js.org/introduction/integration-with-react#table-of-contents) ----------------------------------------------------------------------------------------------- * [Client launch](https://gram.js.org/introduction/integration-with-react#client-launch) * [Save session](https://gram.js.org/introduction/integration-with-react#save-session) * [Catching errors](https://gram.js.org/introduction/integration-with-react#catching-errors) Client launch[](https://gram.js.org/introduction/integration-with-react#client-launch) --------------------------------------------------------------------------------------- In the example below you will see an example of an application that sends a confirmation code and starts the client import React, { useState } from 'react' import { TelegramClient } from 'telegram' import { StringSession } from 'telegram/sessions' const SESSION = new StringSession('') //create a new StringSession, also you can use StoreSession const API_ID = 00000000 // put your API id here const API_HASH = '111eb4dc492d4ae475d575c00bf0aa11' // put your API hash here const client = new TelegramClient(SESSION, API_ID, API_HASH, { connectionRetries: 5 }) // Immediately create a client using your application data const initialState = { phoneNumber: '', password: '', phoneCode: '' } // Initialize component initial state export function App () { const [{ phoneNumber, password, phoneCode }, setAuthInfo] = useState(initialState) async function sendCodeHandler () { await client.connect() // Connecting to the server await client.sendCode( { apiId: API_ID, apiHash: API_HASH }, phoneNumber ) } async function clientStartHandler () { await client.start({ phoneNumber, password: userAuthParamCallback(password), phoneCode: userAuthParamCallback(phoneCode), onError: () => {} }) await client.sendMessage('me', { message: "You're successfully logged in!" }) } function inputChangeHandler ({ target: { name, value } }) { setAuthInfo((authInfo) => ({ ...authInfo, [name]: value })) } function userAuthParamCallback (param) { return async function () { return await new (resolve => { resolve(param) })() } } return ( <> ) } import React, { type BaseSyntheticEvent, useState } from 'react' import { TelegramClient } from 'telegram' import { StringSession } from 'telegram/sessions' interface IInitialState { phoneNumber: string password: string phoneCode: string } const SESSION = new StringSession('') //create a new StringSession, also you can use StoreSession const API_ID = 00000000 // put your API id here const API_HASH = '111eb4dc492d4ae475d575c00bf0aa11' // put your API hash here const client = new TelegramClient(SESSION, API_ID, API_HASH, { connectionRetries: 5 }) // Immediately create a client using your application data const initialState: IInitialState = { phoneNumber: '', password: '', phoneCode: '' } // Initialize component initial state export function App (): JSX.Element { const [{ phoneNumber, password, phoneCode }, setAuthInfo] = useState(initialState) async function sendCodeHandler (): Promise { await client.connect() // Connecting to the server await client.sendCode( { apiId: API_ID, apiHash: API_HASH }, phoneNumber ) } async function clientStartHandler (): Promise { await client.start({ phoneNumber, password: userAuthParamCallback(password), phoneCode: userAuthParamCallback(phoneCode), onError: () => {} }) await client.sendMessage('me', { message: "You're successfully logged in!" }) } function inputChangeHandler ({ target: { name, value } }: BaseSyntheticEvent): void { setAuthInfo((authInfo) => ({ ...authInfo, [name]: value })) } function userAuthParamCallback (param: T): () => Promise { return async function () { return await new Promise(resolve => { resolve(param) }) } } return ( <> ) } Save session[](https://gram.js.org/introduction/integration-with-react#save-session) ------------------------------------------------------------------------------------- By making a few changes you can save the session /* After successfully launching the client, you can call a function client.session.save() that returns the current session, and then save it to local storage, for example. Note that we must save only session, having a valid session, you can specify random API_ID and API_HASH */ async function clientStartHandler () { await client.start({ phoneNumber, password: userAuthParamCallback(password), phoneCode: userAuthParamCallback(phoneCode), onError: () => {} }) localStorage.setItem('session', JSON.stringify(client.session.save())) // Save session to local storage await client.sendMessage('me', { message: "You're successfully logged in!" }) } /* Now we can get the saved session and run the client without re-authorization */ const SESSION = new StringSession(JSON.parse(localStorage.getItem('session'))) // Get session from local storage const client = new TelegramClient(SESSION, API_ID, API_HASH, { connectionRetries: 5 }) // Immediately create a client using your application data /* After successfully launching the client, you can call a function client.session.save() that returns the current session, and then save it to local storage, for example. Note that we must save only session, having a valid session, you can specify random API_ID and API_HASH */ async function clientStartHandler (): Promise { await client.start({ phoneNumber, password: userAuthParamCallback(password), phoneCode: userAuthParamCallback(phoneCode), onError: () => {} }) localStorage.setItem('session', JSON.stringify(client.session.save())) // Save session to local storage await client.sendMessage('me', { message: "You're successfully logged in!" }) } /* Now we can get the saved session and run the client without re-authorization */ const SESSION = new StringSession(JSON.parse(localStorage.getItem('session') as string)) // Get session from local storage const client = new TelegramClient(SESSION, API_ID, API_HASH, { connectionRetries: 5 }) // Immediately create a client using your application data Catching errors[](https://gram.js.org/introduction/integration-with-react#catching-errors) ------------------------------------------------------------------------------------------- In order to avoid crashes of the application, it is very important to catch errors in all critical parts of the application, for example in the case below async function clientStartHandler () { await client.start({ phoneNumber, password: userAuthParamCallback(password), phoneCode: userAuthParamCallback(phoneCode), onError: () => {} }) localStorage.setItem('session', JSON.stringify(client.session.save())) // Save session to local storage await client.sendMessage('me', { message: "You're successfully logged in!" }) } For example, if you try to start the client using an incorrect phone number or send a message to a non-existent user, your application may break or work incorrectly. You can fix this by using try-catch construct and handling the error async function clientStartHandler () { try { await client.start({ phoneNumber, password: userAuthParamCallback(password), phoneCode: userAuthParamCallback(phoneCode), onError: () => {} }) localStorage.setItem('session', JSON.stringify(client.session.save())) // Save session to local storage await client.sendMessage('me', { message: "You're successfully logged in!" }) } catch (error) { console.dir(error) // Error handling logic } } --- # account.AcceptAuthorization | GramJS account.AcceptAuthorization[](https://gram.js.org/tl/account/AcceptAuthorization#accountacceptauthorization) ------------------------------------------------------------------------------------------------------------- Sends a Telegram Passport authorization form, effectively sharing data with the service Example[](https://gram.js.org/tl/account/AcceptAuthorization#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.account.AcceptAuthorization({ botId: BigInt("-4156887774564"), scope: "some string here", publicKey: "some string here", valueHashes: [\ new Api.SecureValueHash({\ type: new Api.SecureValueTypePersonalDetails({}),\ hash: Buffer.from("arbitrary data here"),\ }),\ ], credentials: new Api.SecureCredentialsEncrypted({ data: Buffer.from("arbitrary data here"), hash: Buffer.from("arbitrary data here"), secret: Buffer.from("arbitrary data 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.Bool = await client.invoke( new Api.account.AcceptAuthorization({ botId: BigInt("-4156887774564"), scope: "some string here", publicKey: "some string here", valueHashes: [\ new Api.SecureValueHash({\ type: new Api.SecureValueTypePersonalDetails({}),\ hash: Buffer.from("arbitrary data here"),\ }),\ ], credentials: new Api.SecureCredentialsEncrypted({ data: Buffer.from("arbitrary data here"), hash: Buffer.from("arbitrary data here"), secret: Buffer.from("arbitrary data here"), }), }) ); console.log(result); // prints the result })(); Parameters[](https://gram.js.org/tl/account/AcceptAuthorization#parameters) ---------------------------------------------------------------------------- | Name | Type | Description | | --- | --- | --- | | **botId** | [long](https://core.telegram.org/type/long) | Bot ID | | **scope** | [string](https://core.telegram.org/type/string) | Telegram Passport element types requested by the service | | **publicKey** | [string](https://core.telegram.org/type/string) | Service's public key | | **valueHashes** | [Vector](https://core.telegram.org/type/Vector%20t)
<[SecureValueHash](https://core.telegram.org/type/SecureValueHash)
\> | Types of values sent and their hashes | | **credentials** | [SecureCredentialsEncrypted](https://core.telegram.org/type/SecureCredentialsEncrypted) | Encrypted values | Result[](https://gram.js.org/tl/account/AcceptAuthorization#result) -------------------------------------------------------------------- [Bool](https://core.telegram.org/type/Bool) Possible errors[](https://gram.js.org/tl/account/AcceptAuthorization#possible-errors) -------------------------------------------------------------------------------------- | Code | Type | Description | | --- | --- | --- | Can bots use this method?[](https://gram.js.org/tl/account/AcceptAuthorization#can-bots-use-this-method) --------------------------------------------------------------------------------------------------------- No Related pages[](https://gram.js.org/tl/account/AcceptAuthorization#related-pages) ---------------------------------------------------------------------------------- --- # account.CancelPasswordEmail | GramJS account.CancelPasswordEmail[](https://gram.js.org/tl/account/CancelPasswordEmail#accountcancelpasswordemail) ------------------------------------------------------------------------------------------------------------- Cancel the code that was sent to verify an email to use as [2FA recovery method](https://core.telegram.org/api/srp) . Example[](https://gram.js.org/tl/account/CancelPasswordEmail#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.account.CancelPasswordEmail({})); 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.Bool = await client.invoke( new Api.account.CancelPasswordEmail({}) ); console.log(result); // prints the result })(); Parameters[](https://gram.js.org/tl/account/CancelPasswordEmail#parameters) ---------------------------------------------------------------------------- | Name | Type | Description | | --- | --- | --- | Result[](https://gram.js.org/tl/account/CancelPasswordEmail#result) -------------------------------------------------------------------- [Bool](https://core.telegram.org/type/Bool) Possible errors[](https://gram.js.org/tl/account/CancelPasswordEmail#possible-errors) -------------------------------------------------------------------------------------- | Code | Type | Description | | --- | --- | --- | Can bots use this method?[](https://gram.js.org/tl/account/CancelPasswordEmail#can-bots-use-this-method) --------------------------------------------------------------------------------------------------------- No Related pages[](https://gram.js.org/tl/account/CancelPasswordEmail#related-pages) ---------------------------------------------------------------------------------- #### [Two-factor authentication](https://core.telegram.org/api/srp) [](https://gram.js.org/tl/account/CancelPasswordEmail#two-factor-authentication) How to login to a user's account if they have enabled 2FA, how to change password. --- # account.ChangeAuthorizationSettings | GramJS account.ChangeAuthorizationSettings[](https://gram.js.org/tl/account/ChangeAuthorizationSettings#accountchangeauthorizationsettings) ------------------------------------------------------------------------------------------------------------------------------------- Change authorization settings Example[](https://gram.js.org/tl/account/ChangeAuthorizationSettings#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.account.ChangeAuthorizationSettings({ hash: BigInt("-4156887774564"), encryptedRequestsDisabled: false, callRequestsDisabled: false, }) ); 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.Bool = await client.invoke( new Api.account.ChangeAuthorizationSettings({ hash: BigInt("-4156887774564"), encryptedRequestsDisabled: false, callRequestsDisabled: false, }) ); console.log(result); // prints the result })(); Parameters[](https://gram.js.org/tl/account/ChangeAuthorizationSettings#parameters) ------------------------------------------------------------------------------------ | Name | Type | Description | | --- | --- | --- | | **flags** | [#](https://core.telegram.org/type/%23) | Flags, see [TL conditional fields](https://core.telegram.org/mtproto/TL-combinators#conditional-fields) | | **hash** | [long](https://core.telegram.org/type/long) | Session ID from the [authorization](https://core.telegram.org/constructor/authorization)
constructor, fetchable using [account.getAuthorizations](https://core.telegram.org/method/account.getAuthorizations) | | **encryptedRequestsDisabled** | [flags](https://core.telegram.org/mtproto/TL-combinators#conditional-fields)
.0?[Bool](https://core.telegram.org/type/Bool) | Whether to enable or disable receiving encrypted chats: if the flag is not set, the previous setting is not changed | | **callRequestsDisabled** | [flags](https://core.telegram.org/mtproto/TL-combinators#conditional-fields)
.1?[Bool](https://core.telegram.org/type/Bool) | Whether to enable or disable receiving calls: if the flag is not set, the previous setting is not changed | Result[](https://gram.js.org/tl/account/ChangeAuthorizationSettings#result) ---------------------------------------------------------------------------- [Bool](https://core.telegram.org/type/Bool) Possible errors[](https://gram.js.org/tl/account/ChangeAuthorizationSettings#possible-errors) ---------------------------------------------------------------------------------------------- | Code | Type | Description | | --- | --- | --- | | 400 | HASH\_INVALID | The provided hash is invalid. | Can bots use this method?[](https://gram.js.org/tl/account/ChangeAuthorizationSettings#can-bots-use-this-method) ----------------------------------------------------------------------------------------------------------------- No Related pages[](https://gram.js.org/tl/account/ChangeAuthorizationSettings#related-pages) ------------------------------------------------------------------------------------------ #### [authorization](https://core.telegram.org/constructor/authorization) [](https://gram.js.org/tl/account/ChangeAuthorizationSettings#authorization) Logged-in session #### [account.getAuthorizations](https://core.telegram.org/method/account.getAuthorizations) [](https://gram.js.org/tl/account/ChangeAuthorizationSettings#accountgetauthorizations) Get logged-in sessions --- # account.ChangePhone | GramJS account.ChangePhone[](https://gram.js.org/tl/account/ChangePhone#accountchangephone) ------------------------------------------------------------------------------------- Change the phone number of the current account Example[](https://gram.js.org/tl/account/ChangePhone#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.account.ChangePhone({ phoneNumber: "some string here", phoneCodeHash: "some string here", phoneCode: "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.User = await client.invoke( new Api.account.ChangePhone({ phoneNumber: "some string here", phoneCodeHash: "some string here", phoneCode: "some string here", }) ); console.log(result); // prints the result })(); Parameters[](https://gram.js.org/tl/account/ChangePhone#parameters) -------------------------------------------------------------------- | Name | Type | Description | | --- | --- | --- | | **phoneNumber** | [string](https://core.telegram.org/type/string) | New phone number | | **phoneCodeHash** | [string](https://core.telegram.org/type/string) | Phone code hash received when calling [account.sendChangePhoneCode](https://core.telegram.org/method/account.sendChangePhoneCode) | | **phoneCode** | [string](https://core.telegram.org/type/string) | Phone code received when calling [account.sendChangePhoneCode](https://core.telegram.org/method/account.sendChangePhoneCode) | Result[](https://gram.js.org/tl/account/ChangePhone#result) ------------------------------------------------------------ [User](https://core.telegram.org/type/User) Possible errors[](https://gram.js.org/tl/account/ChangePhone#possible-errors) ------------------------------------------------------------------------------ | Code | Type | Description | | --- | --- | --- | | 400 | PHONE\_CODE\_EMPTY | phone\_code is missing. | | 400 | PHONE\_CODE\_EXPIRED | The phone code you provided has expired. | | 406 | PHONE\_NUMBER\_INVALID | The phone number is invalid. | | 400 | PHONE\_NUMBER\_OCCUPIED | The phone number is already in use. | Can bots use this method?[](https://gram.js.org/tl/account/ChangePhone#can-bots-use-this-method) ------------------------------------------------------------------------------------------------- No Related pages[](https://gram.js.org/tl/account/ChangePhone#related-pages) -------------------------------------------------------------------------- #### [account.sendChangePhoneCode](https://core.telegram.org/method/account.sendChangePhoneCode) [](https://gram.js.org/tl/account/ChangePhone#accountsendchangephonecode) Verify a new phone number to associate to the current account --- # account.CheckUsername | GramJS account.CheckUsername[](https://gram.js.org/tl/account/CheckUsername#accountcheckusername) ------------------------------------------------------------------------------------------- Check if a username is free and can be assigned to a channel/supergroup Example[](https://gram.js.org/tl/account/CheckUsername#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.account.CheckUsername({ username: "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.Bool = await client.invoke( new Api.account.CheckUsername({ username: "some string here", }) ); console.log(result); // prints the result })(); Parameters[](https://gram.js.org/tl/account/CheckUsername#parameters) ---------------------------------------------------------------------- | Name | Type | Description | | --- | --- | --- | | **channel** | [InputChannel](https://core.telegram.org/type/InputChannel) | The [channel/supergroup](https://core.telegram.org/api/channel)
that will assigned the specified username | | **username** | [string](https://core.telegram.org/type/string) | The username to check | Result[](https://gram.js.org/tl/account/CheckUsername#result) -------------------------------------------------------------- [Bool](https://core.telegram.org/type/Bool) Possible errors[](https://gram.js.org/tl/account/CheckUsername#possible-errors) -------------------------------------------------------------------------------- | Code | Type | Description | | --- | --- | --- | | 400 | CHANNELS\_ADMIN\_PUBLIC\_TOO\_MUCH | You're admin of too many public channels, make some channels private to change the username of this channel. | | 400 | CHANNEL\_INVALID | The provided channel is invalid. | | 400 | CHAT\_ID\_INVALID | The provided chat id is invalid. | | 400 | USERNAME\_INVALID | The provided username is not valid. | Can bots use this method?[](https://gram.js.org/tl/account/CheckUsername#can-bots-use-this-method) --------------------------------------------------------------------------------------------------- No Related pages[](https://gram.js.org/tl/account/CheckUsername#related-pages) ---------------------------------------------------------------------------- #### [Channels, supergroups, gigagroups and basic groups](https://core.telegram.org/api/channel) [](https://gram.js.org/tl/account/CheckUsername#channels-supergroups-gigagroups-and-basic-groups) How to handle channels, supergroups, gigagroups, basic groups, and what's the difference between them. --- # account.ConfirmPasswordEmail | GramJS account.ConfirmPasswordEmail[](https://gram.js.org/tl/account/ConfirmPasswordEmail#accountconfirmpasswordemail) ---------------------------------------------------------------------------------------------------------------- Verify an email to use as [2FA recovery method](https://core.telegram.org/api/srp) . Example[](https://gram.js.org/tl/account/ConfirmPasswordEmail#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.account.ConfirmPasswordEmail({ code: "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.Bool = await client.invoke( new Api.account.ConfirmPasswordEmail({ code: "some string here", }) ); console.log(result); // prints the result })(); Parameters[](https://gram.js.org/tl/account/ConfirmPasswordEmail#parameters) ----------------------------------------------------------------------------- | Name | Type | Description | | --- | --- | --- | | **code** | [string](https://core.telegram.org/type/string) | The phone code that was received after [setting a recovery email](https://core.telegram.org/api/srp#email-verification) | Result[](https://gram.js.org/tl/account/ConfirmPasswordEmail#result) --------------------------------------------------------------------- [Bool](https://core.telegram.org/type/Bool) Possible errors[](https://gram.js.org/tl/account/ConfirmPasswordEmail#possible-errors) --------------------------------------------------------------------------------------- | Code | Type | Description | | --- | --- | --- | | 400 | CODE\_INVALID | Code invalid. | | 400 | EMAIL\_HASH\_EXPIRED | Email hash expired. | Can bots use this method?[](https://gram.js.org/tl/account/ConfirmPasswordEmail#can-bots-use-this-method) ---------------------------------------------------------------------------------------------------------- No Related pages[](https://gram.js.org/tl/account/ConfirmPasswordEmail#related-pages) ----------------------------------------------------------------------------------- #### [Two-factor authentication](https://core.telegram.org/api/srp) [](https://gram.js.org/tl/account/ConfirmPasswordEmail#two-factor-authentication) How to login to a user's account if they have enabled 2FA, how to change password. --- # account.ConfirmPhone | GramJS account.ConfirmPhone[](https://gram.js.org/tl/account/ConfirmPhone#accountconfirmphone) ---------------------------------------------------------------------------------------- Confirm a phone number to cancel account deletion, for more info [click here »](https://core.telegram.org/api/account-deletion) Example[](https://gram.js.org/tl/account/ConfirmPhone#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.account.ConfirmPhone({ phoneCodeHash: "some string here", phoneCode: "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.Bool = await client.invoke( new Api.account.ConfirmPhone({ phoneCodeHash: "some string here", phoneCode: "some string here", }) ); console.log(result); // prints the result })(); Parameters[](https://gram.js.org/tl/account/ConfirmPhone#parameters) --------------------------------------------------------------------- | Name | Type | Description | | --- | --- | --- | | **phoneCodeHash** | [string](https://core.telegram.org/type/string) | Phone code hash, for more info [click here »](https://core.telegram.org/api/account-deletion) | | **phoneCode** | [string](https://core.telegram.org/type/string) | SMS code, for more info [click here »](https://core.telegram.org/api/account-deletion) | Result[](https://gram.js.org/tl/account/ConfirmPhone#result) ------------------------------------------------------------- [Bool](https://core.telegram.org/type/Bool) Possible errors[](https://gram.js.org/tl/account/ConfirmPhone#possible-errors) ------------------------------------------------------------------------------- | Code | Type | Description | | --- | --- | --- | | 400 | CODE\_HASH\_INVALID | Code hash invalid. | | 400 | PHONE\_CODE\_EMPTY | phone\_code is missing. | Can bots use this method?[](https://gram.js.org/tl/account/ConfirmPhone#can-bots-use-this-method) -------------------------------------------------------------------------------------------------- No Related pages[](https://gram.js.org/tl/account/ConfirmPhone#related-pages) --------------------------------------------------------------------------- #### [Account deletion](https://core.telegram.org/api/account-deletion) [](https://gram.js.org/tl/account/ConfirmPhone#account-deletion) How to reset an account if the 2FA password was forgotten. --- # account.CreateTheme | GramJS account.CreateTheme[](https://gram.js.org/tl/account/CreateTheme#accountcreatetheme) ------------------------------------------------------------------------------------- Create a theme Example[](https://gram.js.org/tl/account/CreateTheme#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.account.CreateTheme({ slug: "some string here", title: "My very normal title", document: new Api.InputDocument({ id: BigInt("-4156887774564"), accessHash: BigInt("-4156887774564"), fileReference: Buffer.from("arbitrary data here"), }), settings: [\ new Api.InputThemeSettings({\ baseTheme: new Api.BaseThemeClassic({}),\ accentColor: 43,\ messageColorsAnimated: true,\ outboxAccentColor: 43,\ messageColors: [43],\ wallpaper: new Api.InputWallPaper({\ id: BigInt("-4156887774564"),\ accessHash: BigInt("-4156887774564"),\ }),\ wallpaperSettings: new Api.WallPaperSettings({\ blur: true,\ motion: true,\ backgroundColor: 43,\ secondBackgroundColor: 43,\ thirdBackgroundColor: 43,\ fourthBackgroundColor: 43,\ intensity: 43,\ rotation: 43,\ }),\ }),\ ], }) ); 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.Theme = await client.invoke( new Api.account.CreateTheme({ slug: "some string here", title: "My very normal title", document: new Api.InputDocument({ id: BigInt("-4156887774564"), accessHash: BigInt("-4156887774564"), fileReference: Buffer.from("arbitrary data here"), }), settings: [\ new Api.InputThemeSettings({\ baseTheme: new Api.BaseThemeClassic({}),\ accentColor: 43,\ messageColorsAnimated: true,\ outboxAccentColor: 43,\ messageColors: [43],\ wallpaper: new Api.InputWallPaper({\ id: BigInt("-4156887774564"),\ accessHash: BigInt("-4156887774564"),\ }),\ wallpaperSettings: new Api.WallPaperSettings({\ blur: true,\ motion: true,\ backgroundColor: 43,\ secondBackgroundColor: 43,\ thirdBackgroundColor: 43,\ fourthBackgroundColor: 43,\ intensity: 43,\ rotation: 43,\ }),\ }),\ ], }) ); console.log(result); // prints the result })(); Parameters[](https://gram.js.org/tl/account/CreateTheme#parameters) -------------------------------------------------------------------- | Name | Type | Description | | --- | --- | --- | | **flags** | [#](https://core.telegram.org/type/%23) | Flags, see [TL conditional fields](https://core.telegram.org/mtproto/TL-combinators#conditional-fields) | | **slug** | [string](https://core.telegram.org/type/string) | Unique theme ID | | **title** | [string](https://core.telegram.org/type/string) | Theme name | | **document** | [flags](https://core.telegram.org/mtproto/TL-combinators#conditional-fields)
.2?[InputDocument](https://core.telegram.org/type/InputDocument) | Theme file | | **settings** | [flags](https://core.telegram.org/mtproto/TL-combinators#conditional-fields)
.3?[Vector](https://core.telegram.org/type/Vector%20t)
<[InputThemeSettings](https://core.telegram.org/type/InputThemeSettings)
\> | Theme settings | Result[](https://gram.js.org/tl/account/CreateTheme#result) ------------------------------------------------------------ [Theme](https://core.telegram.org/type/Theme) Possible errors[](https://gram.js.org/tl/account/CreateTheme#possible-errors) ------------------------------------------------------------------------------ | Code | Type | Description | | --- | --- | --- | | 400 | THEME\_MIME\_INVALID | The theme's MIME type is invalid. | Can bots use this method?[](https://gram.js.org/tl/account/CreateTheme#can-bots-use-this-method) ------------------------------------------------------------------------------------------------- No Related pages[](https://gram.js.org/tl/account/CreateTheme#related-pages) -------------------------------------------------------------------------- --- # account.DeclinePasswordReset | GramJS account.DeclinePasswordReset[](https://gram.js.org/tl/account/DeclinePasswordReset#accountdeclinepasswordreset) ---------------------------------------------------------------------------------------------------------------- Abort a pending 2FA password reset, [see here for more info »](https://core.telegram.org/api/srp#password-reset) Example[](https://gram.js.org/tl/account/DeclinePasswordReset#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.account.DeclinePasswordReset({})); 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.Bool = await client.invoke( new Api.account.DeclinePasswordReset({}) ); console.log(result); // prints the result })(); Parameters[](https://gram.js.org/tl/account/DeclinePasswordReset#parameters) ----------------------------------------------------------------------------- | Name | Type | Description | | --- | --- | --- | Result[](https://gram.js.org/tl/account/DeclinePasswordReset#result) --------------------------------------------------------------------- [Bool](https://core.telegram.org/type/Bool) Possible errors[](https://gram.js.org/tl/account/DeclinePasswordReset#possible-errors) --------------------------------------------------------------------------------------- | Code | Type | Description | | --- | --- | --- | | 400 | RESET\_REQUEST\_MISSING | No password reset is in progress. | Can bots use this method?[](https://gram.js.org/tl/account/DeclinePasswordReset#can-bots-use-this-method) ---------------------------------------------------------------------------------------------------------- No Related pages[](https://gram.js.org/tl/account/DeclinePasswordReset#related-pages) ----------------------------------------------------------------------------------- #### [Two-factor authentication](https://core.telegram.org/api/srp) [](https://gram.js.org/tl/account/DeclinePasswordReset#two-factor-authentication) How to login to a user's account if they have enabled 2FA, how to change password. --- # account.DeleteAccount | GramJS account.DeleteAccount[](https://gram.js.org/tl/account/DeleteAccount#accountdeleteaccount) ------------------------------------------------------------------------------------------- Delete the user's account from the telegram servers. Can be used, for example, to delete the account of a user that provided the login code, but forgot the [2FA password and no recovery method is configured](https://core.telegram.org/api/srp) . Example[](https://gram.js.org/tl/account/DeleteAccount#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.account.DeleteAccount({ reason: "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.Bool = await client.invoke( new Api.account.DeleteAccount({ reason: "some string here", }) ); console.log(result); // prints the result })(); Parameters[](https://gram.js.org/tl/account/DeleteAccount#parameters) ---------------------------------------------------------------------- | Name | Type | Description | | --- | --- | --- | | **reason** | [string](https://core.telegram.org/type/string) | Why is the account being deleted, can be empty | Result[](https://gram.js.org/tl/account/DeleteAccount#result) -------------------------------------------------------------- [Bool](https://core.telegram.org/type/Bool) Possible errors[](https://gram.js.org/tl/account/DeleteAccount#possible-errors) -------------------------------------------------------------------------------- | Code | Type | Description | | --- | --- | --- | | 420 | 2FA\_CONFIRM\_WAIT\_%d | Since this account is active and protected by a 2FA password, we will delete it in 1 week for security purposes. You can cancel this process at any time, you'll be able to reset your account in %d seconds. | Can bots use this method?[](https://gram.js.org/tl/account/DeleteAccount#can-bots-use-this-method) --------------------------------------------------------------------------------------------------- No Related pages[](https://gram.js.org/tl/account/DeleteAccount#related-pages) ---------------------------------------------------------------------------- #### [Two-factor authentication](https://core.telegram.org/api/srp) [](https://gram.js.org/tl/account/DeleteAccount#two-factor-authentication) How to login to a user's account if they have enabled 2FA, how to change password. --- # account.DeleteSecureValue | GramJS account.DeleteSecureValue[](https://gram.js.org/tl/account/DeleteSecureValue#accountdeletesecurevalue) ------------------------------------------------------------------------------------------------------- Delete stored [Telegram Passport](https://core.telegram.org/passport) documents, [for more info see the passport docs »](https://core.telegram.org/passport/encryption#encryption) Example[](https://gram.js.org/tl/account/DeleteSecureValue#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.account.DeleteSecureValue({ types: [new Api.SecureValueTypePersonalDetails({})], }) ); 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.Bool = await client.invoke( new Api.account.DeleteSecureValue({ types: [new Api.SecureValueTypePersonalDetails({})], }) ); console.log(result); // prints the result })(); Parameters[](https://gram.js.org/tl/account/DeleteSecureValue#parameters) -------------------------------------------------------------------------- | Name | Type | Description | | --- | --- | --- | | **types** | [Vector](https://core.telegram.org/type/Vector%20t)
<[SecureValueType](https://core.telegram.org/type/SecureValueType)
\> | Document types to delete | Result[](https://gram.js.org/tl/account/DeleteSecureValue#result) ------------------------------------------------------------------ [Bool](https://core.telegram.org/type/Bool) Possible errors[](https://gram.js.org/tl/account/DeleteSecureValue#possible-errors) ------------------------------------------------------------------------------------ | Code | Type | Description | | --- | --- | --- | Can bots use this method?[](https://gram.js.org/tl/account/DeleteSecureValue#can-bots-use-this-method) ------------------------------------------------------------------------------------------------------- No Related pages[](https://gram.js.org/tl/account/DeleteSecureValue#related-pages) -------------------------------------------------------------------------------- #### [Telegram Passport Manual](https://core.telegram.org/passport) [](https://gram.js.org/tl/account/DeleteSecureValue#telegram-passport-manual) #### [Telegram Passport Encryption Details](https://core.telegram.org/passport/encryption) [](https://gram.js.org/tl/account/DeleteSecureValue#telegram-passport-encryption-details) --- # account.FinishTakeoutSession | GramJS account.FinishTakeoutSession[](https://gram.js.org/tl/account/FinishTakeoutSession#accountfinishtakeoutsession) ---------------------------------------------------------------------------------------------------------------- Finish account takeout session Example[](https://gram.js.org/tl/account/FinishTakeoutSession#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.account.FinishTakeoutSession({ success: true, }) ); 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.Bool = await client.invoke( new Api.account.FinishTakeoutSession({ success: true, }) ); console.log(result); // prints the result })(); Parameters[](https://gram.js.org/tl/account/FinishTakeoutSession#parameters) ----------------------------------------------------------------------------- | Name | Type | Description | | --- | --- | --- | | **flags** | [#](https://core.telegram.org/type/%23) | Flags, see [TL conditional fields](https://core.telegram.org/mtproto/TL-combinators#conditional-fields) | | **success** | [flags](https://core.telegram.org/mtproto/TL-combinators#conditional-fields)
.0?[true](https://core.telegram.org/constructor/true) | Data exported successfully | Result[](https://gram.js.org/tl/account/FinishTakeoutSession#result) --------------------------------------------------------------------- [Bool](https://core.telegram.org/type/Bool) Possible errors[](https://gram.js.org/tl/account/FinishTakeoutSession#possible-errors) --------------------------------------------------------------------------------------- | Code | Type | Description | | --- | --- | --- | | 403 | TAKEOUT\_REQUIRED | A takeout session has to be initialized, first. | Can bots use this method?[](https://gram.js.org/tl/account/FinishTakeoutSession#can-bots-use-this-method) ---------------------------------------------------------------------------------------------------------- No Related pages[](https://gram.js.org/tl/account/FinishTakeoutSession#related-pages) ----------------------------------------------------------------------------------- --- # account.GetAccountTTL | GramJS account.GetAccountTTL[](https://gram.js.org/tl/account/GetAccountTTL#accountgetaccountttl) ------------------------------------------------------------------------------------------- Get days to live of account Example[](https://gram.js.org/tl/account/GetAccountTTL#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.account.GetAccountTTL({})); 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.AccountDaysTTL = await client.invoke( new Api.account.GetAccountTTL({}) ); console.log(result); // prints the result })(); Parameters[](https://gram.js.org/tl/account/GetAccountTTL#parameters) ---------------------------------------------------------------------- | Name | Type | Description | | --- | --- | --- | Result[](https://gram.js.org/tl/account/GetAccountTTL#result) -------------------------------------------------------------- [AccountDaysTTL](https://core.telegram.org/type/AccountDaysTTL) Possible errors[](https://gram.js.org/tl/account/GetAccountTTL#possible-errors) -------------------------------------------------------------------------------- | Code | Type | Description | | --- | --- | --- | Can bots use this method?[](https://gram.js.org/tl/account/GetAccountTTL#can-bots-use-this-method) --------------------------------------------------------------------------------------------------- No Related pages[](https://gram.js.org/tl/account/GetAccountTTL#related-pages) ---------------------------------------------------------------------------- --- # account.GetAllSecureValues | GramJS account.GetAllSecureValues[](https://gram.js.org/tl/account/GetAllSecureValues#accountgetallsecurevalues) ---------------------------------------------------------------------------------------------------------- Get all saved [Telegram Passport](https://core.telegram.org/passport) documents, [for more info see the passport docs »](https://core.telegram.org/passport/encryption#encryption) Example[](https://gram.js.org/tl/account/GetAllSecureValues#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.account.GetAllSecureValues({})); 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.Vector = await client.invoke( new Api.account.GetAllSecureValues({}) ); console.log(result); // prints the result })(); Parameters[](https://gram.js.org/tl/account/GetAllSecureValues#parameters) --------------------------------------------------------------------------- | Name | Type | Description | | --- | --- | --- | Result[](https://gram.js.org/tl/account/GetAllSecureValues#result) ------------------------------------------------------------------- [Vector](https://core.telegram.org/type/Vector%20t) <[SecureValue](https://core.telegram.org/type/SecureValue) \> Possible errors[](https://gram.js.org/tl/account/GetAllSecureValues#possible-errors) ------------------------------------------------------------------------------------- | Code | Type | Description | | --- | --- | --- | Can bots use this method?[](https://gram.js.org/tl/account/GetAllSecureValues#can-bots-use-this-method) -------------------------------------------------------------------------------------------------------- No Related pages[](https://gram.js.org/tl/account/GetAllSecureValues#related-pages) --------------------------------------------------------------------------------- #### [Telegram Passport Manual](https://core.telegram.org/passport) [](https://gram.js.org/tl/account/GetAllSecureValues#telegram-passport-manual) #### [Telegram Passport Encryption Details](https://core.telegram.org/passport/encryption) [](https://gram.js.org/tl/account/GetAllSecureValues#telegram-passport-encryption-details) ---