GramJS

InitConnection

Initialize connection

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.InitConnection({
      apiId: 43,
      deviceModel: "some string here",
      systemVersion: "some string here",
      appVersion: "some string here",
      systemLangCode: "some string here",
      langPack: "some string here",
      langCode: "some string here",
      query: new Api.AnyRequest({
        /*...*/
      }),
      proxy: new Api.InputClientProxy({
        address: "some string here",
        port: 43,
      }),
      params: new Api.JsonNull({}),
    })
  );
  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.InitConnection({
      apiId: 43,
      deviceModel: "some string here",
      systemVersion: "some string here",
      appVersion: "some string here",
      systemLangCode: "some string here",
      langPack: "some string here",
      langCode: "some string here",
      query: new Api.AnyRequest({
        /*...*/
      }),
      proxy: new Api.InputClientProxy({
        address: "some string here",
        port: 43,
      }),
      params: new Api.JsonNull({}),
    })
  );
  console.log(result); // prints the result
})();

Parameters

NameTypeDescription
flags#Flags, see TL conditional fields
apiIdintApplication identifier (see. App configuration)
deviceModelstringDevice model
systemVersionstringOperation system version
appVersionstringApplication version
systemLangCodestringCode for the language used on the device's OS, ISO 639-1 standard
langPackstringLanguage pack to use
langCodestringCode for the language used on the client, ISO 639-1 standard
proxyflags.0?InputClientProxyInfo about an MTProto proxy
paramsflags.1?JSONValueAdditional initConnection parameters.
For now, only the tz\_offset field is supported, for specifying timezone offset in seconds.
query!XThe query itself

Result

X

Possible errors

CodeTypeDescription
400CONNECTION_LAYER_INVALIDLayer invalid

Can bots use this method?

Yes