Giter Site home page Giter Site logo

slimbot's Introduction

Build Status Coverage Status Dependency Status MIT licensed

Slimbot

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

Updated for Bot API 4.1. Works with Node 11.5.0.

Resources

Getting started

npm i slimbot
const Slimbot = require('slimbot');
const slimbot = new Slimbot(process.env['TELEGRAM_BOT_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.

How it works

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.

You can also use callbacks instead of promises:

const Slimbot = require('./src/slimbot');
const slimbot = new Slimbot(process.env['TELEGRAM_BOT_TOKEN']);

function callback(err, obj) {
  if (err) {
    // handle error
    console.log(obj);
  }
  // handle returned object
  console.log(obj);
};

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

slimbot.startPolling(callback);

Examples

Documentation (Wiki)

Learn more about the implementation details in the Wiki. Feel free to contribute to the Wiki or add more examples.

Contributing

The guiding principle for this library is to be as simple as possible. I put serious thought into adding features to guard against bloat. Nonetheless, I am very open to dialogue and contributions are most welcome.

If you have built a public bot using this library, send me a PM and I'll feature it here.

slimbot's People

Contributors

ago avatar arthot avatar edisonchee avatar jakimenko avatar lgg avatar matteocontrini avatar rpaskin avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.