Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-telegram-bot-api

Package Overview
Dependencies
Maintainers
1
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-telegram-bot-api - npm Package Compare versions

Comparing version 0.10.0 to 0.11.0

src/telegramPolling.js

2

package.json
{
"name": "node-telegram-bot-api",
"version": "0.10.0",
"version": "0.11.0",
"description": "Telegram Bot API",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -1,2 +0,2 @@

[![Build Status](https://travis-ci.org/yagop/node-telegram-bot-api.svg?branch=master)](https://travis-ci.org/yagop/node-telegram-bot-api) [![Coverage Status](https://coveralls.io/repos/yagop/node-telegram-bot-api/badge.svg?branch=master)](https://coveralls.io/r/yagop/node-telegram-bot-api?branch=master) [![Build status](https://ci.appveyor.com/api/projects/status/ujko6bsum3g5msjh/branch/master?svg=true)](https://ci.appveyor.com/project/yagop/node-telegram-bot-api/branch/master)
[![Build Status](https://travis-ci.org/yagop/node-telegram-bot-api.svg?branch=master)](https://travis-ci.org/yagop/node-telegram-bot-api) [![Build status](https://ci.appveyor.com/api/projects/status/ujko6bsum3g5msjh/branch/master?svg=true)](https://ci.appveyor.com/project/yagop/node-telegram-bot-api/branch/master) [![Coverage Status](https://coveralls.io/repos/yagop/node-telegram-bot-api/badge.svg?branch=master)](https://coveralls.io/r/yagop/node-telegram-bot-api?branch=master) [![bitHound Score](https://www.bithound.io/github/yagop/node-telegram-bot-api/badges/score.svg)](https://www.bithound.io/github/yagop/node-telegram-bot-api)

@@ -3,0 +3,0 @@ Node.js module to interact with official [Telegram Bot API](https://core.telegram.org/bots/api). A bot token is needed, to obtain one, talk to [@botfather](telegram.me/BotFather) and create a new bot.

var TelegramBotWebHook = require('./telegramWebHook');
var TelegramBotPolling = require('./telegramPolling');
var debug = require('debug')('node-telegram-bot-api');

@@ -34,14 +35,11 @@ var EventEmitter = require('events').EventEmitter;

this.token = token;
this.offset = 0;
this._webServer = null;
var processUpdate = this._processUpdate.bind(this);
if (options.polling) {
// By default polling for 4 seconds
var timeout = options.polling.timeout || 4;
this._polling(timeout);
this._polling = new TelegramBotPolling(token, options.polling, processUpdate);
}
if (options.webHook) {
var binded = this._processUpdate.bind(this);
this._WebHook = new TelegramBotWebHook(token, options.webHook, binded);
this._WebHook = new TelegramBotWebHook(token, options.webHook, processUpdate);
}

@@ -52,14 +50,2 @@ };

TelegramBot.prototype._polling = function (timeout) {
var self = this;
this.getUpdates(timeout).then(function (data) {
self._processUpdates(data);
self._polling(timeout);
}).catch(function (err) {
debug('polling error: %j', err);
// Wait for 2 seconds before retry
setTimeout(self._polling.bind(self), 2000, timeout);
});
};
TelegramBot.prototype._processUpdate = function (update) {

@@ -73,8 +59,2 @@ debug('Process Update', update);

TelegramBot.prototype._processUpdates = function (updates) {
for (var i = 0; i < updates.length; i++) {
this._processUpdate(updates[i]);
}
};
TelegramBot.prototype._request = function (path, options) {

@@ -142,5 +122,4 @@ if (!this.token) {

TelegramBot.prototype.getUpdates = function (timeout, limit, offset) {
var self = this;
var query = {
offset: offset || this.offset+1,
offset: offset,
limit: limit,

@@ -150,10 +129,3 @@ timeout: timeout

return this._request('getUpdates', {qs: query})
.then(function (result) {
var last = result[result.length-1];
if (last) {
self.offset = last.update_id;
}
return result;
});
return this._request('getUpdates', {qs: query});
};

@@ -198,3 +170,3 @@

if (data instanceof stream.Stream) {
fileName = path.basename(data.path);
fileName = URL.parse(path.basename(data.path)).pathname;
formData = {};

@@ -201,0 +173,0 @@ formData[type] = {

@@ -0,1 +1,2 @@

var TelegramPolling = require('../src/telegramPolling');
var Telegram = require('../index');

@@ -34,23 +35,2 @@ var request = require('request');

describe('#Polling', function () {
it('should emit a `message` on polling', function (done) {
var bot = new Telegram(TOKEN);
bot.on('message', function (msg) {
msg.should.be.an.instanceOf(Object);
bot._polling = function () {};
done();
});
bot.getUpdates = function() {
return {
then: function (cb) {
cb([{update_id: 0, message: {}}]);
return this;
},
catch: function () {}
};
};
bot._polling();
});
});
describe('#WebHook', function () {

@@ -382,1 +362,25 @@ it('should reject request if same token not provided', function (done) {

}); // End Telegram
describe('#TelegramBotPolling', function () {
it('should call the callback on polling', function (done) {
function onUpdate (update) {
update.should.be.an.instanceOf(Object);
done();
}
var polling = new TelegramPolling(null, {interval: 500}, onUpdate);
// Not the best way to mock, but it works
polling._getUpdates = function() {
return {
then: function (cb) {
cb([{update_id: 10, message: {}}]);
return this;
},
catch: function () {
return this;
},
finally: function () {}
};
};
});
});
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc