2
0
mirror of https://github.com/yagop/node-telegram-bot-api synced 2025-08-29 13:27:44 +00:00

Binds in TelegramBotPolling.prototype._polling

This commit is contained in:
Yago 2016-01-11 18:49:02 +01:00
parent 186d1e3a5c
commit 7e6c220aa3

View File

@ -25,30 +25,30 @@ var TelegramBotPolling = function (token, options, callback) {
}; };
TelegramBotPolling.prototype._polling = function () { TelegramBotPolling.prototype._polling = function () {
var self = this; this.lastRequest = this._getUpdates()
.then(function (updates) {
this.lastRequest = this._getUpdates().then(function (updates) { this.lastUpdate = Date.now();
self.lastUpdate = Date.now(); debug('polling data %j', updates);
debug('polling data %j', updates); updates.forEach(function (update, index) {
updates.forEach(function (update, index) { // If is the latest, update the offset.
// If is the latest, update the offset. if (index === updates.length - 1) {
if (index === updates.length - 1) { this.offset = update.update_id;
self.offset = update.update_id; debug('updated offset: %s', this.offset);
debug('updated offset: %s', self.offset); }
this.callback(update);
});
}.bind(this))
.catch(function (err) {
debug('polling error: %j', err);
})
.finally(function () {
if (this.abort) {
debug('Polling is aborted!');
} else {
debug('setTimeout for %s miliseconds', this.interval);
setTimeout(this._polling.bind(this), this.interval);
} }
self.callback(update); }.bind(this));
});
}).catch(function (err) {
debug('polling error: %j', err);
}).finally(function () {
if (self.abort) {
debug('Polling is aborted!');
return;
}
debug('setTimeout for %s miliseconds', self.interval);
setTimeout(self._polling.bind(self), self.interval);
});
}; };
TelegramBotPolling.prototype._getUpdates = function () { TelegramBotPolling.prototype._getUpdates = function () {