Socket
Book a DemoInstallSign in
Socket

@xalbex/telegram-bot

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@xalbex/telegram-bot

Telegram Bot API for Node.js

Source
npmnpm
Version
0.0.3
Version published
Weekly downloads
46
43.75%
Maintainers
1
Weekly downloads
 
Created
Source

Telegram Bot API for Node.js

This is a Node.js module to comunicate with official Telegram Bot API. To use this module the bot token is required and can be obtained by talking to @botfather.

This module is written in Typescript and contains the definitions of all official methods and structures useful for type checking.

For all the requests it return a Promise, this simplify the asynchronous procedures.

This module exports two objects:

  • Raw that provide all the official methods without any abstraction. All methods accept the same parameters specified in the Telegram Bot API documentation and return a Promise with the result specified in the official documentation.
import * as TelegramBot from 'telegram-bot-js'

// Replace the value below with the Telegram token you receive from @BotFather
const token = '<BOT-TOKEN>';

// Create an object that manages the Telegram bot and receives the updates.
const bot = new TelegramBot.Raw (token);

// Send the message to a specific chat
let promise = bot.sendMessage ({ chat_id: '<A chat id>', text: 'Hello world!' });
  • Manager (recommanded) that simplifies the management of updates. It is a EventEmitter and is possible to add listner. The events emitted have the same name of the update specified in the Update object in the documentation: message, edited_message, channel_post, ...

It contains a member api that is the raw client discussed above.

import * as TelegramBot from 'telegram-bot-js'

// Replace the value below with the Telegram token you receive from @BotFather
const token = '<BOT-TOKEN>';

// Create an object that manages the Telegram bot and receives the updates.
const bot = new TelegramBot.Manager (token);

// Listen for any kind of message. There are different kinds of
// messages.
bot.on ('message', async msg => 
{
   // Send a message to the chat acknowledging receipt of their message
   let result = await bot.api.sendMessage ({ chat_id: msg.chat.id, text: 'Hi!' });

   // Write the server response to the terminal
   console.log (result);
});

Keywords

Telegram

FAQs

Package last updated on 28 Sep 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts