Guide
Customize client options

Client Options

NameTypeDescription
proxyProxyInterfaceConnect to telegram using MTProto proxy or Socks proxy.
testModeBooleanConnecting to telegram test server.
ipv6BooleanConnecting using ipv6. Default is false
deviceModelStringThe device model which is using for login.
systemVersionStringThe system version which is using for login.
appVersionStringThe App version which is using for login. Default same with tgsnake version
systemVersionStringA two-letter ISO 639-1 language code which is used by the system. Default is en
langCodeStringA two-letter ISO 639-1 language code that you use. Default is en
sleepTresholdIntegerSleep treshold when flood wait reached. Default is 10000
maxRetriesIntegerMax retries when execution is fail. Default is 5
isCdnBooleanConnenting to cdn telegram server. Default is false
noUpdatesBooleanPass true to disable incoming updates. Default is false
takeoutBooleanPass true to let the client use a takeout session instead of a normal one, implies noUpdates : true. Default is false
tcpTCPTCP modes. See »
localBooleanOnly for browser platform! Set false when you deployed your app offside the local machine. it wil use ws:// in local machine and wss:// in deployment.
maxConcurrentTransmissionsIntegerSet the maximum amount of concurrent transmissions (uploads & downloads). Default is 1
maxReconnectRetriesIntegerHow many attempts to connect to the telegram server when the connection is interrupted. Default is 3

Proxy Interface

Socks Proxy

Connecting to Telegram server using Socks Proxy. This proxy won’t work on browser platform.

NameTypeRequiredDescription
hostnameStringTrueIP destination for socks proxy.
portIntegerTruePort destination for socks proxy.
socksInteger (4 or 5)TrueSocks version. It should be 4 or 5. It marks using Socks4 or Socks5.
usernameStringFalseIf the proxy uses authentication, enter this using the authentication username.
passwordStringFalseIf the proxy uses authentication, enter this using the authentication password of given username.

Mtproto Proxy

NameTypeRequiredDescription
serverStringTrueDestination hostname or server for connecting MTProto Proxy server.
portIntegerTrueDestination port for connecting to MTProto Proxy server.
secretString or BytesTrueSecret of MTProto Proxy, can be encoded as hex string or buffer.

TCP

import { TCP } from '@tgsnake/core';

Available TCPs:

  • TCPFull
TCP.TCPFull;

Connecting to Telegram server using TCP Full. See ».

  • TCPAbridged
TCP.TCPAbridged;

Connecting to Telegram server using TCP Abridged. See ».

  • TCPIntermediate
TCP.TCPIntermediate;

Connecting to Telegram server using TCP Intermediate. See ».

  • TCPPaddedIntermediate
TCP.TCPPaddedIntermediate;

Connecting to Telegram server using TCP Padded Intermediate. See ».

  • TCPAbridgedO
TCP.TCPAbridgedO;

Connecting to Telegram server using TCP Obfuscation by using TCP Abridged as a packet sender-reader. In the browser platform or when you use MTProto proxy, you must use TCP or TCPIntermediateO. See ».

  • TCPIntermediateO
TCP.TCPIntermediateO;

Connecting to Telegram server using TCP Obfuscation by using TCP Intermediate as a packet sender-reader. In the browser platform or when you use MTProto proxy, you must use TCP or TCPAbridgedO. See ».

Reference

interface ClientOptions {
  /**
   * Connect to telegram using MTProto proxy or Socks proxy.
   */
  proxy?: ProxyInterface;
  /**
   * Connecting to telegram test server.
   */
  testMode?: boolean;
  /**
   * Connecting using ipv6.
   */
  ipv6?: boolean;
  /**
   * The device model which is using for login.
   */
  deviceModel?: string;
  /**
   * The system version which is using for login.
   */
  systemVersion?: string;
  /**
   * The App version which is using for login.
   */
  appVersion?: string;
  /**
   * What language is used by the system.
   */
  systemLangCode?: string;
  /**
   * What language do you use.
   */
  langCode?: string;
  /**
   * Sleep treshold when flood wait reached.
   */
  sleepTreshold?: number;
  /**
   * Max retries when execution is fail.
   */
  maxRetries?: number;
  /**
   * Connenting to cdn telegram server.
   */
  isCdn?: boolean;
  /**
   * Pass true to disable incoming updates.<br/>
   * When updates are disabled the client can't receive messages or other updates.<br/>
   * Useful for batch programs that don't need to deal with updates.
   */
  noUpdates?: boolean;
  /**
   * Pass true to let the client use a takeout session instead of a normal one, implies `noUpdates : true`.<br/>
   * Useful for exporting Telegram data. Methods invoked inside a takeout session (such as get_chat_history,download_media, ...) are less prone to throw FloodWait exceptions.<br/>
   * Only available for users, bots will ignore this parameter.
   */
  takeout?: boolean;
  /**
   * TCP Modes.<br/>
   * Fill with index of tcp modes if you want to switch from one tcp to another. <br/>
   * Default is 1 (TCPAbridge)
   */
  tcp?: TCP;
  /**
   * Only for browser platform! Set false when you deployed your app offside the local machine. it wil use `ws://` in local machine and `wss://` in deployment.
   */
  local?: boolean;
  /**
   * Set the maximum amount of concurrent transmissions (uploads & downloads).
   * A value that is too high may result in network related issues.
   * Defaults to 1.
   */
  maxConcurrentTransmissions?: number;
  /**
   * How many attempts to connect to the telegram server when the connection is interrupted.
   * Default is 3
   */
  maxReconnectRetries?: number;
}
 
interface SocksProxyInterface {
  /**
   * IP destination for socks proxy.
   */
  hostname: string;
  /**
   * Port destination for socks proxy.
   */
  port: number;
  /**
   * Socks version. It should be 4 or 5. It marks using Socks4 or Socks5.
   */
  socks: 4 | 5;
  /**
   * If the proxy uses authentication, enter this using the authentication username.
   */
  username?: string;
  /**
   * If the proxy uses authentication, enter this using the authentication password of given username.
   */
  password?: string;
}
interface MtprotoProxyInterface {
  /**
   * Destination hostname or server for connecting MTProto Proxy server.
   */
  server: string;
  /**
   * Destination port for connecting to MTProto Proxy server.
   */
  port: number;
  /**
   * Secret of MTProto Proxy, can be encoded as hex string or buffer.
   */
  secret: string | Buffer;
}
type ProxyInterface = SocksProxyInterface | MtprotoProxyInterface;
 
enum TCP {
  TCPFull = 0,
  TCPAbridged = 1,
  TCPIntermediate = 2,
  TCPPaddedIntermediate = 3,
  TCPAbridgedO = 4,
  TCPIntermediateO = 5,
}