Giter VIP home page Giter VIP logo

node-tlg's Introduction

node-tlg

NodeJS API for the TDLib. It helps you build your own Telegram Client. Full support Secret Chat feature.


Installation

  1. Build the binary (https://github.com/tdlib/td#building)
  2. npm i tlg

Usage

const { Client } = require('tlg')

main()

async function main() {
	const client = new Client({
		apiId: 999999, 
		apiHash: '7cb3e46a69d2e69753744e216eb4e613'
	})

	try {
		await client.connect('user', 'YOUR_PHONE_NUMBER')

		await client.getChats()
		await client.createPrivateChat('USER_ID')
		await client.sendMessage('USER_ID', 'Hello my friend!')
		
		client.on('__updateMessageSendSucceeded', client.close)

	} catch(e) {
		console.error('ERROR', e)
	}
}

Examples

See examples/ folder.


Requirements

  • TDLib binary (libtdjson.so on Linux, libtdjson.dylib on macOS, tdjson.dll on Windows)
  • NodeJs version >= 10.0.0

Building for Linux Debian 9.5

apt-get update
apt-get install cmake gperf ccache libssl-dev zlib1g-dev libreadline-dev clang ninja-build

git clone https://github.com/tdlib/td.git
cd td  
mkdir build
cd build

CXX=clang++ CC=clang cmake -GNinja -DCMAKE_BUILD_TYPE=Release ..
ninja

cp libtdjson.so /path/to/your-app-folder

node-tlg's People

Contributors

dilongfa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

node-tlg's Issues

Unable to install

Environment:
MacOS 10.14

$ yarn add tlg
yarn add v1.12.3
[1/5] ๐Ÿ”  Validating package.json...
[2/5] ๐Ÿ”  Resolving packages...
[3/5] ๐Ÿšš  Fetching packages...
[4/5] ๐Ÿ”—  Linking dependencies...
warning "[email protected]" is missing a bundled dependency "node-pre-gyp". This should be reported to the package maintainer.
[5/5] ๐Ÿ“ƒ  Building fresh packages...
[1/2] โก€ ref-napi
error .../node_modules/ref-napi: Command failed.
Exit code: 1
Command: node-gyp rebuild
Arguments: 
Directory: .../node_modules/ref-napi
Output:
gyp info it worked if it ends with ok
gyp info using [email protected]
gyp info using [email protected] | darwin | x64
gyp http GET https://nodejs.org/download/release/v10.15.0/node-v10.15.0-headers.tar.gz
gyp http 200 https://nodejs.org/download/release/v10.15.0/node-v10.15.0-headers.tar.gz
gyp http GET https://nodejs.org/download/release/v10.15.0/SHASUMS256.txt
gyp http 200 https://nodejs.org/download/release/v10.15.0/SHASUMS256.txt
gyp info spawn /usr/bin/python
gyp info spawn args [ '/Users/a/.nvm/versions/node/v10.15.0/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'make',
gyp info spawn args   '-I',
gyp info spawn args   '.../node_modules/ref-napi/build/config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/a/.nvm/versions/node/v10.15.0/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   '/Users/a/.node-gyp/10.15.0/include/node/common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=/Users/a/.node-gyp/10.15.0',
gyp info spawn args   '-Dnode_gyp_dir=/Users/a/.nvm/versions/node/v10.15.0/lib/node_modules/npm/node_modules/node-gyp',
gyp info spawn args   '-Dnode_lib_file=/Users/a/.node-gyp/10.15.0/<(target_arch)/node.lib',
gyp info spawn args   '-Dmodule_root_dir=.../node_modules/ref-napi',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'build',
gyp info spawn args   '-Goutput_dir=.' ]
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
  CC(target) Release/obj.target/nothing/node_modules/node-addon-api/src/nothing.o
  LIBTOOL-STATIC Release/nothing.a
  CXX(target) Release/obj.target/binding/src/binding.o
In file included from ../src/binding.cc:1:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/stdlib.h:94:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/stdlib.h:66:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/sys/wait.h:110:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/sys/resource.h:72:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
In file included from /usr/local/include/stdint.h:59:
/usr/local/include/stdint.h:2:10: error: #include nested too deeply
#include <stddef.h>
         ^
/usr/local/include/stdint.h:59:11: error: #include nested too deeply
# include <stdint.h>
          ^
/usr/local/include/stdint.h:72:11: error: #include nested too deeply
# include <sys/types.h>
          ^
/usr/local/include/stdint.h:76:10: error: #include nested too deeply
#include <limits.h>
         ^
/usr/local/include/stdint.h:82:11: error: #include nested too deeply
# include <inttypes.h>
          ^
In file included from ../src/binding.cc:1:
In file included from /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include/c++/v1/stdlib.h:94:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/stdlib.h:66:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/sys/wait.h:110:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/sys/resource.h:197:2: error: unknown type name 'uint64_t'
        uint64_t ri_user_time;
        ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/sys/resource.h:198:2: error: unknown type name 'uint64_t'
        uint64_t ri_system_time;
        ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/sys/resource.h:199:2: error: unknown type name 'uint64_t'
        uint64_t ri_pkg_idle_wkups;
        ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/sys/resource.h:200:2: error: unknown type name 'uint64_t'
        uint64_t ri_interrupt_wkups;
        ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/sys/resource.h:201:2: error: unknown type name 'uint64_t'
        uint64_t ri_pageins;
        ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/sys/resource.h:202:2: error: unknown type name 'uint64_t'
        uint64_t ri_wired_size;
        ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/sys/resource.h:203:2: error: unknown type name 'uint64_t'
        uint64_t ri_resident_size;
        ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/sys/resource.h:204:2: error: unknown type name 'uint64_t'
        uint64_t ri_phys_footprint;
        ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/sys/resource.h:205:2: error: unknown type name 'uint64_t'
        uint64_t ri_proc_start_abstime;
        ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/sys/resource.h:206:2: error: unknown type name 'uint64_t'
        uint64_t ri_proc_exit_abstime;
        ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/sys/resource.h:211:2: error: unknown type name 'uint64_t'
        uint64_t ri_user_time;
        ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/sys/resource.h:212:2: error: unknown type name 'uint64_t'
        uint64_t ri_system_time;
        ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/sys/resource.h:213:2: error: unknown type name 'uint64_t'
        uint64_t ri_pkg_idle_wkups;
        ^
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk/usr/include/sys/resource.h:214:2: error: unknown type name 'uint64_t'
        uint64_t ri_interrupt_wkups;
        ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make: *** [Release/obj.target/binding/src/binding.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/a/.nvm/versions/node/v10.15.0/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:262:23)
gyp ERR! stack     at ChildProcess.emit (events.js:182:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:240:12)
gyp ERR! System Darwin 18.2.0
gyp ERR! command "/Users/a/.nvm/versions/node/v10.15.0/bin/node" "/Users/a/.nvm/versions/node/v10.15.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd .../node_modules/ref-napi
gyp ERR! node -v v10.15.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok

Dynamic Linking Error

backend: Error: Dynamic Linking Error: dlopen(/Users/kumarabhirup/Documents/Repositories/propagateAt/packages/backend/libtdjson.dylib, 2): image not found
backend:     at new DynamicLibrary (/Users/kumarabhirup/Documents/Repositories/propagateAt/node_modules/ffi-napi/lib/dynamic_library.js:74:11)
backend:     at Object.Library (/Users/kumarabhirup/Documents/Repositories/propagateAt/node_modules/ffi-napi/lib/library.js:45:14)
backend:     at new TDLib (/Users/kumarabhirup/Documents/Repositories/propagateAt/node_modules/tlg/lib/tdlib.js:22:20)
backend:     at new Client (/Users/kumarabhirup/Documents/Repositories/propagateAt/node_modules/tlg/lib/client.js:7:3)
backend:     at connectToTelegram (/Users/kumarabhirup/Documents/Repositories/propagateAt/packages/backend/dist/src/resolvers/mutations/connectToTelegram.js:15:20)
backend:     at processTicksAndRejections (internal/process/task_queues.js:93:5)
backend:     at async Promise.all (index 0)

Looks like you abandoned this project. Anyway, would love to get help here.

client.getChatHistory is not a function

TLG is working for me as far as connecting, getting the list of chats, and getting info about any individual chat... but when I want to get some messages FROM an individual chat, the TDLib docs suggest that I should use getChatHistory, but doing this just gives the error TypeError: client.getChatHistory is not a function.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.