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

vvlad1973-telegram-framework

v7.9.7

Published

Current version: *7.9.5*

Downloads

99

Readme

Telegram Bot API implementation

Current version: 7.9.5

This package partially implements interaction with Telegram as a bot.

Supported version of Telegram Bot API - 5.6

Description

This package provides:

  • data exchange with Telegram in webhook mode
  • work in asynchronous mode
  • control of the load on the Telegram Bot API
  • prioritization of method calls of Telegram Bot API depending on the type of call
  • control of size of the send queue
  • preprocessing of received data

Installation

npm install vvlad1973-telegram-framework

Usage

import TelegramBot from 'vvlad1973-telegram-framework';

/** 
 * Express or any other HTTP/HTTPS service can be used to process 
 * webhook requests
 */
import express from 'express';
import bodyParser from 'body-parser';

let
  chatId = 90844863,
  text = 'Test message',
  token = '2039667923:AAHwlugV92qBNXrn_XrTGaQjFPuCJAtUnfs',
  webhookUrl = 'https://some.url.for.webhook/',
  response;

/** 
 * Creating an instance of TelegramBot
 */
const bot = new TelegramBot(token);

/** 
 * Creating instance of HTTP-server and starting listening
 */
const app = express();
app.use(bodyParser.json());
app.listen(port);

/** 
 * Subscription on POST-queries to HTTP-server
 */
app.post(`/${token}/`, function (request, response) {
    response.sendStatus(200); // Sending response on POST-query ...
    bot.processUpdate(request.body); // ... and start processing received data
});

/** 
 * Subscription on incoming updates from Telegram
 */
bot.on('*', function (userId, chatId, senderData, properties, contents) {
  console.log(`[userId=${userId}] Received update:`);
  console.log(`\t chat=[${JSON.stringify(chatId, 0, '\t')}]`);
  console.log(`\t senderData=[${JSON.stringify(senderData, 0, '\t')}]`);
  console.log(`\t properties=[${JSON.stringify(properties, 0, '\t')}]`);
  console.log(`\t contents=[${JSON.stringify(contents, 0, '\t')}]`);
  
  /**
   * Sending response message
   */
  bot.sendMessage(chatId, 'OK')
    .then(response => {
      console.log(response);
    })
    .catch(error => {
      console.error(error);
    });
});

/**
 * Getting info about bot from Telegram
 */
response = await bot.getMe();
console.log(response);

/**
 * Setting webhook
 */
response = await bot.setWebhook(webhookUrl);
console.log(response);

/**
 * Getting webhook info from Telegram
 */
response = await bot.getWebhookInfo();
console.log(response);

/**
 * Sending a message to Telegram chat
 */
response = await bot.sendMessage(chatId, text);
console.log(response);

Implemented methods

Bot control methods

  • getMe
  • getMyCommands
  • setMyCommands
  • deleteMyCommands

Webhook control methods

  • getWebhookInfo
  • setWebhook
  • deleteWebhook

Sending data methods

  • sendMessage
  • sendPhoto
  • sendVideo
  • sendVideoNote
  • sendAudio
  • sendVoice
  • sendDocument
  • sendAnimation
  • forwardMessage
  • copyMessage
  • answerCallbackQuery
  • sendChatAction
  • sendSticker
  • sendDice
  • sendPoll
  • sendMediaGroup
  • sendContact

Modifying messages

  • editMessageText
  • editMessageCaption
  • editMessageReplyMarkup
  • editMessageMedia
  • stopPoll

Control messages in chat

  • deleteMessage
  • pinChatMessage
  • unpinChatMessage
  • unpinAllChatMessages

Chat manageement

  • getChat
  • getChatMember
  • getChatMemberCount
  • getChatAdministrators
  • banChatMember
  • unbanChatMember
  • restrictChatMember
  • promoteChatMember
  • approveChatJoinRequest
  • declineChatJoinRequest

Getting info

  • getFile