Socket
Socket
Sign inDemoInstall

slimbot

Package Overview
Dependencies
53
Maintainers
1
Versions
66
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    slimbot

Simple and minimal Telegram Bot API for Node.js. No frills.


Version published
Weekly downloads
371
decreased by-7.02%
Maintainers
1
Install size
2.61 MB
Created
Weekly downloads
 

Readme

Source

Build Status Coverage Status Dependency Status MIT licensed

Slimbot

A fuss-free, thin wrapper around Telegram Bot API for Node.js. No frills.

Getting started

npm i slimbot
const Slimbot = require('slimbot');
const slimbot = new Slimbot(process.env['TELEGRAM_TOKEN']);

// Register listeners

slimbot.on('message', message => {
  slimbot.sendMessage(message.chat.id, 'Message received');
});

// Call API

slimbot.startPolling();

Now go ahead and type a message to your bot in Telegram. It should reply you with 'Message received' in the chat.

All methods return a promise. This means you can inspect the returned objects if you want to:

slimbot.sendMessage('123456789', 'Message received').then(message => {
  console.log(message);
});

In this case, the sendMessage method returns a Message object as stated in the documentation.

Events

Events you can listen to:

  • 'message'
  • 'edited_message'
  • 'callback_query'
  • 'inline_query'
  • 'chosen_inline_result'

Take note that inline_query and chosen_inline_result only works if you have sent /setinline and /setinlinefeedback commands to @BotFather. Read the docs for more information.

slimbot.on('message', message => {
  // do something with message
});

slimbot.on('edited_message', message => {
  // do something with message
});

slimbot.on('callback_query', query => {
  // do something with query
});

slimbot.on('inline_query', query => {
  // do something with query
});

slimbot.on('chosen_inline_result', result => {
  // do something with result
});

Methods

All methods found in the Telegram Bot API Documentation have been implemented.

Use them as they are described in the docs, providing the required parameters and if you wish, the optional parameters:

slimbot.sendMessage('123456789', 'text');

let optionalParams = {
  parse_mode: true,
  disable_web_page_preview: true,
  disable_notification: true,
  reply_to_message_id: 1234,
  reply_markup: {
    inline_keyboard: [[
      { text: 'Today', callback_data: 'pick_today' },
      { text: 'Pick a date', callback_data: 'pick_date' }
    ]]
  }
}

slimbot.sendMessage('123456789', 'text', optionalParams);

You can send files to chats using file_id or InputFile. This works for sendPhoto, sendAudio, sendDocument, sendSticker, sendVideo, and sendVoice.

Check out the example to see how you can do so:

const fs = require('fs');

let inputFile = fs.createReadStream(__dirname + '/bulb.png');

// this uploads the file to Telegram's servers
slimbot.sendPhoto(message.chat.id, inputFile).then(message => {
  // once successful, you can grab the file_id of the file
  console.log(message.result.photo[0].file_id);
});

Additional methods implemented are:

  • editInlineMessageText
  • editInlineMessageCaption
  • editInlineMessageReplyMarkup

Call these additional methods with inline_message_id rather than chat_id and message_id.


slimbot.editMessageText('123456789', 1234, 'edited message');

slimbot.editInlineMessageText('4321', 'edited message');

Keywords

FAQs

Last updated on 28 Oct 2016

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc