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 🙏

© 2025 – Pkg Stats / Ryan Hefner

bot22api-telegram

v0.0.7

Published

Framework for Telegram's Bot API

Readme

Framework for the Telegram Bot API

see Telegram's introduction and documentation for Telegram Bots

npm npm npm GitHub stars

Documentation: https://sk22.github.io/botapijs-telegram

Core

This module is based on bot22api. If you want to create a bot for another bot API, you should use that instead, since this module contains Telegram-related features.

const telegram22api = require('bot22api-telegram');
const { TelegramBot } = telegram22api;
const { Command } = telegram22api.handlers;
const { Manual } = telegram22api.manuals;

const bot = new TelegramBot({
  token: '123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11',
});

bot.register(new Command({
  name: 'echo',
  callable: (done, { data, processor, params }) => {
    console.log(data);
    processor.send('sendMessage', {
      text: params.command.args,
      chat_id: data.message.chat.id
    });
    done();
  },
  manual: new Manual({
    description: 'Parrot command. Pretty boring though.',
    explanation: 'Prints whatever you tell this command.',
    syntax: '<squee>'
  })
}));

bot.register(new Command('hello', (done, { processor, data }) => {
  processor.send('sendMessage', {
    text: 'Hey!',
    chat_id: data.chat.id
  })
}, new Manual({ description: 'Says hey' })));


bot.listen(3000, 'localhost');

installation

npm install bot22api-telegram

getting started

You should understand the module this Telegram-specified framework depends on, so I suggest reading this first: botapijs and its Docs

So to get started, firstly require the module and define the classes.

const telegram22api = require('bot22api-telegram');
const { TelegramBot } = telegram22api;
const { Command } = telegram22api.handlers;
const { Manual } = telegram22api.manuals;

TelegramBot /docs/

extends Bot /docs/

To create a new Telegram bot, call its constructor.

const bot = new TelegramBot({
  token: '123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11',
});

Now that you have a Bot object, you need to register so-called Handlers using the Bot's register method. Each Callable (Handler or Requirement) must have a unique name. Read more here.

Bot#register /docs/

bot.register(handler);

Command /docs/

extends Handler /docs/

Command is a special Handler that was made to handle only a specific command. It automatically requires preset Requirements that make sure the message's command equals the Command Handler's command. It also seperates the message to multiple pieces that can be accessed using params.command. Read more about Requirement params here.

bot.register(new Command({
  name: 'echo',
  callable: (done, { data, processor, params }) => {
    console.log(data);
    processor.send('sendMessage', {
      text: params.command.args,
      chat_id: data.message.chat.id
    });
    done();
  },
  manual: new Manual({
    description: 'Parrot command. Pretty boring though.',
    explanation: 'Prints whatever you tell this command.',
    syntax: '<squee>'
  })
}));

Manual /docs/

The Manual class was made to use with the Command class. Every Command has an own documentation in terms of a Manual object. It is used to generate the help page by the default command /help.

Manual {
  command: string,     // e.g. 'echo'
  syntax: string,      // e.g. '<text>'
  description: string, // e.g. 'Echoes text'
  explanation: string, // a longer text that explains the Command
}

Defaults /docs/

Different from the original botapijs module, there are some default Commands registered to your TelegramBot object.

Note that both defaults have an options object so there are fully configurable. To do so, edit the Commands' options.

bot.handlers.helpCommand.options

You can also edit the defaults before creating a TelegramBot to edit them globally.

const { defaults } = telegram22api;
defaults.handlers

/help [<command>]

Sends a list of all available Command Handlers registered to the bot, or outputs all information (stated in the Command's Manual) about a Command.

/start

Welcomes the user and refers to /help.

Finalization

Once everything is set up, you need to tell the bot's server to start listening. To do that, simply call the Bot's listen method. If your server runs more than one Bot, call the Server's listen method instead.

bot.listen(3000, 'localhost');

Now to make HTTP requests, call your URL, which consists of your hostname, port, an optional route followed by ?url= and the set API URL. The data is submit in the POST request's body.

So just give the full URL to your bot API.

https://yourbot.rhcloud.com/?url=https://api.telegram.org/bot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11/

license

MIT