|
|
|
@ -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) { |
|
|
|
self.offset = update.update_id; |
|
|
|
this.offset = update.update_id; |
|
|
|
debug('updated offset: %s', self.offset); |
|
|
|
debug('updated offset: %s', this.offset); |
|
|
|
} |
|
|
|
} |
|
|
|
self.callback(update); |
|
|
|
this.callback(update); |
|
|
|
}); |
|
|
|
}); |
|
|
|
}).catch(function (err) { |
|
|
|
}.bind(this)) |
|
|
|
|
|
|
|
.catch(function (err) { |
|
|
|
debug('polling error: %j', err); |
|
|
|
debug('polling error: %j', err); |
|
|
|
}).finally(function () { |
|
|
|
}) |
|
|
|
if (self.abort) { |
|
|
|
.finally(function () { |
|
|
|
|
|
|
|
if (this.abort) { |
|
|
|
debug('Polling is aborted!'); |
|
|
|
debug('Polling is aborted!'); |
|
|
|
return; |
|
|
|
} else { |
|
|
|
|
|
|
|
debug('setTimeout for %s miliseconds', this.interval); |
|
|
|
|
|
|
|
setTimeout(this._polling.bind(this), this.interval); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
}.bind(this)); |
|
|
|
debug('setTimeout for %s miliseconds', self.interval); |
|
|
|
|
|
|
|
setTimeout(self._polling.bind(self), self.interval); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
TelegramBotPolling.prototype._getUpdates = function () { |
|
|
|
TelegramBotPolling.prototype._getUpdates = function () { |
|
|
|
|