This package has been deprecated

Author message:

very old and doesn't work

telecore

0.1.0 • Public • Published

TeleCore

Make Telegram Bot is very simple!

var bot = new (require('telecore'))({
  "token": "Bot Auth Token"
}).on('error', function(err){
  // errors?
}).on('/hi', function(args, msg){
  bot.api.sendMessage({
    "chat_id": msg.chat.id,
    "text": "How are you?"
  });
}).on('/help', function(args, msg){
  bot.api.sendMessage({
    "chat_id": msg.chat.id,
    "text": "This bot likes to say \"how are you?\"\r\nJust tell him /hi"
  }, callback);
}).start();

Install

$ npm install telecore

How to create and configure the bot?

read this

How to use Telegram Bot API?

TeleCore uses TeleAPI

// example using TeleAPI of TeleCore
var bot = new (require('telecore'))({
  "token": "Bot Auth Token"
});
bot.api.getMe(callback);

More instructions

Options

Options is Object

  • token : String — Bot Authentication Token. (Required)
  • webhook : Boolean — If you want to use webhook. (Default: false)
  • hook : Object — Options for the current hook controller. (See below)

hook if webhook is false or not declared. (Optional)

  • interval : Number — The delay in millisecond between requests. (Default: 100)
  • last_update : Number — Set if do not want to receive old messages at start. (Default: 0)

hook if webhook is true. (Required)

  • server : https.Server — If you do want use custom server object. (Default: own server)
  • port : Number — Listen port. (Default: from url or 3000)
  • host : String — Listen host. (Default: from url or localhost)
  • url : String — HTTPS URL for listen requests from telegram. (Required)

Example poolhook

var bot = new (require('telecore'))({
  "token": "Bot Auth Token",
  "hook": {
    "interval": 300,
    "last_update": 0
  }
});

Example webhook

var bot = new (require('telecore'))({
  "token": "Bot Auth Token",
  "webhook": true,
  "hook": {
    "port": 443,
    "host": "localhost",
    "url": "https://example.com/telegram/hook"
  }
});

Available methods

var bot = new (require('telecore'))({
  "token": "Bot Auth Token"
});
 
// Launches bot, if are you using webhook, then launches and the server.
bot.start();
 
// Stop listen and stop server if are you using webhook.
bot.stop();

Events

var bot = new (require('telecore'))({
  "token": "Bot Auth Token"
});
 
// Emitted when poolhook listen or webhook the server is launched
bot.on('start', function() {
  ...
});
 
// Emitted when poolhook to cease the listen or webhook stopped the server.
bot.on('stop', function() {
  ...
});
 
// Emitted when there is any errors
bot.on('error', function(err) {
  ...
});
 
// Emitted when there is any messages from user or group chat(if you have permission)
bot.on('message', function(msg, update) {
  // "update" is last update time
  if (msg['text'] && msg['text'] == '/twi') {
    bot.api.sendMessage({
      "chat_id": msg.chat.id,
      "text": "https://twitter.com/nof1000"
    }, callback);
  }
});
 
// Emitted when user or users send any command
bot.on('command', function(cmd, msg, args) {
  if (cmd == 'join' && args != null) {
    rooms.move(msg.from.id, args[0]);
  }
});

Custom Events

var bot = new (require('telecore'))({
  "token": "Bot Auth Token"
});
 
bot.on('/start', function(msg, args) {
  bot.api.sendMessage({
    "chat_id": msg.chat.id,
    "text": "NO!"
  });
});
 
bot.on('/leave', function(msg, args) {
  rooms.leave(msg.from.id);
  bot.api.sendMessage({
    "chat_id": msg.chat.id,
    "text": "bye-bye!"
  }, callback);
});
 
bot.on('/random', function(msg, args) {
  bot.api.sendMessage({
    "chat_id": msg.chat.id,
    "text": "Oh, stop it!"
  });
});
 
// etc.

LICENSE

MIT

Readme

Keywords

Package Sidebar

Install

npm i telecore

Weekly Downloads

0

Version

0.1.0

License

MIT

Last publish

Collaborators

  • nof1000