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
Name | Type | Description |
---|---|---|
flags | # | Flags, see TL conditional fields |
apiId | int | Application identifier (see. App configuration) |
deviceModel | string | Device model |
systemVersion | string | Operation system version |
appVersion | string | Application version |
systemLangCode | string | Code for the language used on the device's OS, ISO 639-1 standard |
langPack | string | Language pack to use |
langCode | string | Code for the language used on the client, ISO 639-1 standard |
proxy | flags.0?InputClientProxy | Info about an MTProto proxy |
params | flags.1?JSONValue | Additional initConnection parameters. For now, only the tz_offset field is supported, for specifying timezone offset in seconds. |
query | !X | The query itself |
Result
X
Possible errors
Code | Type | Description |
---|---|---|
400 | CONNECTION_LAYER_INVALID | Layer invalid. |
Can bots use this method?
Yes