GramJS

InvokeWithLayer

Invoke the specified query using the specified API layer

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.InvokeWithLayer({
      layer: 43,
      query: new Api.AnyRequest({
        /*...*/
      }),
    })
  );
  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.AnyRequest = await client.invoke(
    new Api.InvokeWithLayer({
      layer: 43,
      query: new Api.AnyRequest({
        /*...*/
      }),
    })
  );
  console.log(result); // prints the result
})();

Parameters

NameTypeDescription
layerintThe layer to use
query!XThe query

Result

X

Possible errors

CodeTypeDescription
400AUTH_BYTES_INVALIDThe provided authorization is invalid.
400CDN_METHOD_INVALIDYou can't call this method in a CDN DC.
403CHAT_WRITE_FORBIDDENYou can't write in this chat.
400CONNECTION_API_ID_INVALIDThe provided API id is invalid.
400INVITE_HASH_EXPIREDThe invite link has expired.

Can bots use this method?

Yes

Calling API Methods

Additional options for calling methods.