Package detail

@tgsnake/core

tgsnake168(GPL-3.0 OR LGPL-3.0)1.13.15

Pure Telegram MTProto library for nodejs

tgsnake, mtproto, telegram

readme

tgsnake core


Layer 201

Pure Telegram MTProto framework for Javascript or Typescript.

⚡ Using less dependencies to make it fast.
🔓 Open Source, you can contribute to make this framework better.
🗒️ Using Pure Telegram Raw Api, all JSON object is pure from telegram, nothing has changed at all. So that it makes it easier for you to learn the telegram schema docs.
🦕 Deno Support.

Example use

import { Client, Raw, Storages } from '@tgsnake/core';
process.env.LOGLEVEL = 'debug'; // set log level, see @tgsnake/log for more information.
const client = new Client(
  // you can fill with Telethon or Pyrogram string session.
  new Storages.StringSession(''),
  apiHash,
  apiId,
);
// handle update
client.addHandler((update) => {
  console.log(update);
});

// if you already pass the string session, don't fill any arguments in start function, leave it empty.
client.start({
  botToken: '', // if you want login as bot, you can login as user too.
  /* Remove "botToken" if you want to login as user.
  phoneNumber : async () => {}, // Phone number with international phone code (include plus sign (+)) will be used to login, the return of function must be a string.
  code : async () => {}, // OTP code, the return of function must be a string.
  password : async () => {}, // if you account has 2FA, the return of function must be a string.
  authError : async (error) => {} // when error BadRequest attempt, this function will be running.
  */
});

Exporting Session.

For exporting string session, use client.exportSession(). It will be return Promise<string>.

const exported = await client.exportSession();

Development Guidelines

  • Cloning Repository
$ git clone https://github.com/tgsnake/core
  • Installing Dependencies

Required to use yarn!

$ yarn install
  • Building TLSchema and Error class
$ yarn build:api
$ yarn build:error
  • Testing your app! Create test folder and you can create index.js file for testing the app. This folder will automatically ignored and not pushing to GitHub.

Notes

  • This framework is porting of pyrogram for connecting to telegram server. I have dedicated 2 months of my time to complete this framework from scratch. Research after research I do to improve this framework. So big thanks for pyrogram for the source, without that source code, this framework maybe unavailable.
  • For more questions, ask on telegram group (@tgsnake) or open github issue.

GPL v3 License

Build with ♥️ by tgsnake dev.

changelog

1.13.14

2025-01-09

Add

  • defaultDCId options ### Change

  • Update CHANGELOG.md - add nodeModulesDir in deno.json

1.13.13

2025-01-08

Change

  • Update CHANGELOG.md - TypeBuffer to Buffer - update license year - sync errors - Update TLSchema - Update TLSchema ### Fix

  • 'npm:ip-address@9.0.5' in the node_modules directory error.

1.13.12

2024-12-27

Add

  • better jsdoc - better jsdoc ### Change

  • Update CHANGELOG.md - Update TLSchema - Update CHANGELOG.md - Update TLSchema - Update TLSchema ### Fix

  • browser support ### Fixed

  • typing error ### Remove

  • override on File.ts

1.13.11

2024-11-01

Change

  • Update CHANGELOG.md - Update TLSchema ### Update

  • version to 1.13.11

1.13.10

2024-10-26

Change

  • Update CHANGELOG.md - target and module versions in tsconfig.json - Update TLSchema - Update TLSchema - Update Error Reference - Update TLSchema

1.13.9

2024-09-15

Change

  • Update CHANGELOG.md - Update TLSchema - Update Error Reference

1.13.8

2024-08-25

Change

  • Update TLSchema - Update CHANGELOG.md - changing function context using .call

1.13.7

2024-08-01

Change

  • Update CHANGELOG.md - Update Error Reference - Update TLSchema - Update TLSchema

1.13.6

2024-07-02

Change

  • Update TLSchema - saveFileStream - Update Error Reference - Update CHANGELOG.md - using query className when do invoke constructor of invokeWith* ### Fix

  • case sensitive on resolve peer by username

1.13.5

2024-06-11

Change

  • use moduleResolution nodenext in browser - Update CHANGELOG.md - module to nodenext and esnext - require engine version to node >= 12 ### Remove

  • unused import and parameters

1.13.4

2024-06-04

Change

  • Update CHANGELOG.md

1.13.3

2024-06-04

Change

  • Update CHANGELOG.md

1.13.2

2024-06-03

Change

  • Update CHANGELOG.md - by default using TCPO on browser

1.13.1

2024-06-02

Add

  • async download - async download - surrfix in browser version ### Change

  • Update TLSchema - Update CHANGELOG.md ### Remove

  • fileSize cause unless

1.13.0

2024-05-31

Add

  • Workflow to test building source code - dts file in browser folder - browser package builder - workflow for publish package to github registry ### Change

  • add push, on property - log warning to info - static import - salts when is bad - scripts.prepare on browser build - Update CHANGELOG.md ### Fix

  • auto reconnect - file in node - websocket ### Fixed

  • TCPO on Deno ### Remove

  • github registry

1.12.0

2024-05-14

Add

  • mtproxy (untested) - TCP Padded Intermediate ### Change

  • using aes-256-ctr from node:crypto - Update CHANGELOG.md ### Fixed

  • TCPO ### Remove

  • build-doc workflow ### Rewrite

  • TCP Obfuscation

1.11.0

2024-05-05

Add

  • catch in timeout task - maxReconnextRetries options - option to autoreconnect - list of affected error in error.json ### Change

  • invoke getMe when client is reconnecting - Update TLSchema - Update TLSchema - Update CHANGELOG.md ### Fix

  • 2fa error ### Remove

  • notify

1.10.10

2024-04-03

Change

  • Update TLSchema - Update CHANGELOG.md - make required api id ### Fix

  • condition ### Remove

  • getState

1.10.9

2024-03-09

Add

  • get update state ### Change

  • Update CHANGELOG.md - Update TLSchema - Update Error Reference - Update TLSchema

1.10.8

2024-02-04

Change

  • Update CHANGELOG.md - Update TLSchema - Update Error Reference - Update TLSchema - Update TLSchema

1.1.0.7

2024-01-14

Add

  • default getPts - date on qts - way to save pts ### Change

  • Update Error Reference - Update TLSchema - Update TLSchema - Update CHANGELOG.md

1.10.6

2023-12-24

Change

  • Update TLSchema - export as type - Update CHANGELOG.md - export type Progress

1.10.5

2023-12-18

Add

  • workflow for automatic fetch error refference - all possible error - generator for sync possible error ### Change

  • trying to escape double quote - escaping double quote in tsv - improve rpc raise - sync with latest source - compatibility with json file - Update CHANGELOG.md ### Remove

  • all double quote in tsv - replace possible error with single file

1.10.4

2023-12-02

Add

  • gh-pages builder ### Change

  • Update TLSchema - Update CHANGELOG.md ### Fix

  • sync-schema

1.10.3

2023-10-29

Add

  • REPLY_TO_INVALID error ### Change

  • Update CHANGELOG.md

1.10.2

2023-10-05

Change

  • Update CHANGELOG.md - Update TLSchema - Update TLSchema - Update TLSchema

1.10.1

2023-09-10

Change

  • Update CHANGELOG.md - Update TLSchema ### Fix

  • security error in secret chat - bug file part missing when uploading file

1.10.0

2023-08-27

Add

  • download file - saveFile and saveFileStream method - import streamable library - Streamable file class - error types when upload file - queue ### Change

  • dont show undefined or null in console and json stringify - ignore auth params when session is already - target to ES2022 and moduleResolution to node - Update TLSchema - Update CHANGELOG.md

1.9.1

2023-08-14

Change

  • update version - update version - Update CHANGELOG.md ### Fix

  • looping types in raw api

1.9.0

2023-08-12

Add

  • env to node process - notification to group when layer updated ### Change

  • update version - client.invoke now can prediction the results - Update TLSchema - silent sending - Update CHANGELOG.md - update to layer 160 ### Fix

  • generator to sync latest layer

1.8.0

2023-07-02

Change

  • Update CHANGELOG.md - improve update handler - refactoring raw api ### Fix

  • race condition on secret chat

1.7.1

2023-06-29

Change

  • Update CHANGELOG.md ### Fix

  • handler not receive update from secret chat

1.7.0

2023-06-28

Add

  • remove secret chat from session when destroyed - support secret chat - secret chat schema ### Change

  • Update CHANGELOG.md - Update TLSchema - Update CHANGELOG.md ### Fix

  • failed to decrypt message from secret chat

1.6.5

2023-04-10

Change

  • Update CHANGELOG.md - experimental swicth from deno std/node to built-in node modules

1.6.4

2023-03-28

Add

  • possible to automatic restart when client is disconnected ### Change

  • Update CHANGELOG.md

1.6.3

2023-03-28

Change

  • Update CHANGELOG.md - Update CHANGELOG.md - Update CHANGELOG.md ### Fix

  • cannot read property .reject and cant convert to BigInt

1.6.2

2023-03-12

Change

  • Update TLSchema

1.6.1

2023-03-11

Change

  • Update TLSchema - Update CHANGELOG.md

1.6.0

2023-02-20

Add

  • custom console on deno - browser compatibility - local option ### Change

  • update version - remove forceSMS param - switch big-integer deno framework to node cdn version - make RPCError.raise as asyncronous - make Mtproto.unpack as asyncronous - make TLObject.read as asyncronous - using notranspile_aes as crypto in deno - switch to Socket class - Update TLSchema - default TCP to TCPFull - Update CHANGELOG.md ### Fix

  • session.invoke return undefined on deno - fix 400 CONNECTION_SYSTEM_EMPTY error - deno connection - Aes encryption on deno using aes-js - login with botToken - TCPFull - TCPAbridge cause the security check error ### Revert

  • bring back WebSocket class and make it support with node,deno,browser

1.5.0

2023-01-23

Add

  • forceSMS params - logger error when failed connecting to telegram server ### Change

  • Update CHANGELOG.md - ungitignore static file - add support to deno - split client code to different file - remove Primitive.Int.write in TCPFull ### Fix

  • sendCode is not a function

1.4.0

2023-01-07

Add

  • proxy support - types TypeTLRequest for invoke method - support fetch peer when user has multiple username - workflows to automatic change the api.tl amd update api.tl to layer 151 - logger number, better for debuging - class client error - workflows for building docs with typedoc - changelog workflows - config for git-chglog - stack in json of errors - SecurityMismatch error description - Logger.error when got SecurityMismatch error ### Add

  • WebSocketError class - Show TimeoutError in console Change: Change InitConfig timeout Fix: NetworkWorker not started when client restarting - Security error message - Socket.unref() when disconnecting websocket ### Change

  • int to uint - update copyright year - webSocket to promise-socket - improve jsdoc - switch to primitive loop instead of while true - async Mtproto.unpack and Mtproto.pack - checking security error with static class method instead of create new class - move git-chglog config location ### Change

  • Automatic ask recovery code when 3 times try fill 2fa password - do nothing when receive timeout - AES-256-CTR node:crypto - default TCP mode to TCPAbridge - Promise reject instead of trow TimeoutError - support @tgsnake/log latest version ### Fix

  • bug security errors ### Fix

  • module not found - TCPAbridged crash when receive update content ### Fixed

  • Expected 1 arguments, but got 2. ### Improve

  • generator to change the layer number in readme ### Revert

  • revert network task ### Pull Requests

  • Merge pull request #2 from tgsnake/dev

1.3.0

2022-12-03

1.2.0

2022-10-17

1.1.3

2022-08-28

1.1.2

2022-08-08

1.1.1

2022-07-29

Changelog

  • ---- package.json: Update version to 1.1.1. src/Timeout.ts: Make a Timeout class, it better than runWithTimeout function. src/connection/TCP/tcp.ts: Change runWithTimeout to Timeout class. src/connection/TCP/tcp.ts: Clear all timeout task when connection is disconnected. src/connection/TCP/tcp.ts: Bug fix got timeout error when connection is dissconnected. src/connection/TCP/tcp.ts: Bring back to throwing timeout error. src/helpers.ts: Remove runWithTimeout. src/session/Session.ts: Change runWithTimeout to Timeout class. src/session/Session.ts: Clear all timeour task when connection is disconnected.

1.1.0

2022-07-23

Changelog

  • --- generator/api/index.js: Fixed classType. package.json: Update version to 1.1.0. package.json: Add config version (isBeta,isPrivate). package.json: Change main file from "./lib/index.js" to "./lib/src/index.js". src/Client.ts: Add options noUpdates,takeout. src/Client.ts: Invoke updates.GetState when client started. src/Client.ts: Using InvokeWithoutUpdate when options noUpdates is true and InvokeWithTakeout when options takeout is true. src/Client.ts: Invoke account.InitTakeSession when options takeout is true. src/Version.ts: Using package.json as config file. src/raw/core/TLObject.ts: Hide property when starting with underscore ("_").

1.0.2

2022-07-22

Changelog

  • ---- src/Version.ts: Change version to 1.0.2. src/storage/Abstract.ts: Add save() method to abstract class. src/storage/Session.ts: Add default save() function.

1.0.1

2022-07-17

Changelog

  • ----------- src/Version.ts: Update version to 1.0.1. src/Client.ts: Change max retries for client.start to 0 (Only one try invoke). src/connection/TCP/tcp.ts: Change timeout to 10s. src/connection/TCP/tcp.ts: Change timeout error to Logger.error instead of throw. src/connection/webSocket.ts: Make a public connectionClosed property. src/errors/RpcError.ts: Format error message before throwing. src/session/Session.ts: Break network worker when connection closed.

1.0.0

2022-07-17