npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tdlnode

v1.2.0

Published

Telegram nodejs client

Downloads

36

Readme

tdlnode

Telegram nodejs client https://github.com/tdlib/td

Requirements

  1. Node.js >= 10 preferred (minimum >= 9.0.0)
  2. TDLib binary https://github.com/tdlib/td

Getting started

  • Build TDLib binary https://tdlib.github.io/td/build.html?language=JavaScript
  • npm i tdlnode
  • Execute any of TDLib API methods https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1_function.html
const path = require('path')
const { Client } = require('tdlnode')

const api_id = 'your api_id'
const api_hash = 'your api_hash'
const phone_number = '+12345679021' // or const token = 'your token'

const configuration = {
    path_to_binary_file: path.resolve(__dirname, '../lib/libtdjson'),
    database_directory: path.resolve(__dirname, '../storage'),
    files_directory: path.resolve(__dirname, '../downloads'),
    log_file_path: path.resolve(__dirname, '../logs/tdl.log'),
}

const up = async () => {
    const client = new Client({ api_id, api_hash, phone_number }, configuration)

    await client.init()

    const chats = await client.fetch({
        '@type': 'getChats',
        'offset_order': '9223372036854775807',
        'offset_chat_id': 0,
        'limit': 100,
    })

    console.log(chats)

    client.stop()
}

up()

Events

Subscribe to:

  • updates https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1_update.html
  • any of TDLib API return object type https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1_function.html
const callback = msg => {console.log('event', msg)}

client.on('updateOption', callback)

client.once('updateOption', callback)

client.off('updateOption', callback)

More examples

https://github.com/fonbah/tdlnode/tree/master/examples

Options

const conf = {
    path_to_binary_file: path.resolve(__dirname, '../lib/libtdjson'), //default 'libtdjson'
    enable_storage_optimizer: true, //default true
    use_message_database: true, //default true
    use_secret_chats: false, //default false
    system_language_code: 'en', //default 'en'
    application_version: version, //default pacage.json version
    device_model: 'nodejs', //default 'nodejs'
    system_version: '10', //default 10
    database_directory: path.resolve(__dirname, '../storage'), //default './storage'
    files_directory: path.resolve(__dirname, '../downloads'), //default './downloads'
    log_file_path: path.resolve(__dirname, '../logs/tdl.log'), //default './logs/tdl.log'
    use_test_dc: true, //default false If set to true, the Telegram test environment will be used instead of the production environment. 
    verbosity_level: 10, //default 2
    fatal_error_callback: e => { console.log(e) }, //default console.log
}

Client input handling

const types = client.input.getTypes()

const verificationCodeHandler = resolve => {
    const code = 'get somehow your code here'
    resolve(code)
}

const inputHandler = (type, resolve) => {
    switch (type) {
        case 'code':
            verificationCodeHandler(resolve)
            break
    }
}
const unsubscribe = client.input.subscribe(inputHandler)

full example https://github.com/fonbah/tdlnode/blob/master/examples/input.js

Errors handling

client.on('error', update => {
    console.log('client error', update)
    if (update.code == 429) {
        client.stop()
    }
})

Getting started with telegram TDLib

  • api_id and api_hash https://my.telegram.org/
  • documentation https://core.telegram.org/tdlib/getting-started
  • TDLib API updates objects https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1_update.html
  • list of all available TDLib API methods https://core.telegram.org/tdlib/docs/classtd_1_1td__api_1_1_function.html
  • building instructions https://tdlib.github.io/td/build.html?language=JavaScript