1.1.1 • Published 10 years ago

bub v1.1.1

Weekly downloads
4
License
Apache-2.0
Repository
github
Last release
10 years ago

bub

Telegram bot framework

Please go through the Telegram Bot API first.

Get

npm install bub --save

Set

Try and keep your config in a separate JSON file, say bub.json. That way, you can share your code without sharing your API token.

{
  "token": "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11",
  "timeout": 3600
}

If your bot doesn't receive any messages for timeout number of seconds, it will stop checking for more. Default is 10 days.

Go

var config = require('./bub.json');
var Bub = require('bub');
var bot = new Bub(config);

var fs = require('fs');

// User commands are handled with `on()`
bot.on('/start', function (result) {
  // Quick responses are easy-peasy
  result.respond('Hello, ' + result.message.from.first_name);
  // Shoot a stream for photos, audio and video
  result.respond(fs.createReadStream('/home/me/image.png'));
});

bot.on('/longstory', function (result) {
  // Plain old API methods
  bot.sendChatAction({
    chat_id: 123456789,
    action: 'typing'
  }, function (body) {
    console.log('Typing…');
  });
});

// Anything without handlers goes here
bot.on('_default', console.log);

// Start checking for updates and handle them
bot.init();

Roadmap

  • Add a convenience method respond() for quick responses
  • Improve respond() to send any kind of message based on the argument
  • Add webhook support
  • Somewhere down the road: integrate a proper test framework and manage it with Gulp
1.1.1

10 years ago

1.1.0

10 years ago

1.0.0

10 years ago

0.5.3

10 years ago

0.5.2

10 years ago

0.5.1

10 years ago

0.5.0

10 years ago

0.5.0-0

10 years ago

0.4.2

10 years ago

0.4.1

10 years ago

0.4.0

10 years ago

0.3.2

10 years ago

0.3.1

10 years ago

0.3.0

10 years ago

0.2.0

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago