31 _lanstUpdateTime = QDateTime::currentMSecsSinceEpoch();
44void TelegramRestBot::startUpdates() {
48 long long delta = QDateTime::currentMSecsSinceEpoch() - _lanstUpdateTime;
51 if (delta >= _updateDelay) {
52 auto&& replay =
sendRequest(QSharedPointer<TelegramGetUpdate>::create(_lanstUpdateid + 1));
54 replay.then([
this](
const QByteArray &result){
55 handleReceiveUpdates(result);
56 }).onFailed([
this](
const HttpException &e){
57 handleReceiveUpdatesErr(e.code());
63 QTimer::singleShot( _updateDelay - delta,
this, [
this](){startUpdates();});
72 _updateDelay = newUpdateDelay;
76 auto&& it = std::min_element(newProcessed.begin(), newProcessed.end());
77 if (it != newProcessed.end()) {
84void TelegramRestBot::handleReceiveUpdates(
const QByteArray &replay) {
86 if (telegramMsg->isValid()) {
88 _lanstUpdateTime = QDateTime::currentMSecsSinceEpoch();
90 auto && resultArray = telegramMsg->result().toArray();
91 for (
const auto& ref: resultArray) {
94 if (_lanstUpdateid < update->updateId()) {
95 _lanstUpdateid = update->updateId();
103void TelegramRestBot::handleReceiveUpdatesErr(QNetworkReply::NetworkError err) {
105 qDebug() <<
"Network error occured. code: " << err;
static QSharedPointer< MessageType > makeMesasge(const QByteArray &data, Args &&...args)
makeMesasge This is a factory method that can create a message type from raw byte data.
const QByteArray & token() const
token This is the token value for authentication on the remote server (bot).
void incomeNewUpdate(const QSharedPointer< iUpdate > &message)
incomeNewUpdate This method saves incoming messages into the store.
QFuture< QByteArray > sendRequest(const QSharedPointer< iRequest > &rquest)
sendRequest This method sends a custom request to the server.
virtual void setProcessed(const QSet< unsigned long long > &newProcessed)
setProcessed This method sets a new list of processed messages.
virtual void logout()
logout This method removes the login token of the bot.
bool login(const QByteArray &token) override
login This method gets basic information of the bot from the remote server.
void logout() override
logout This method stops the long polling of the updates and removes the login token of the bot.
void setUpdateDelay(int newUpdateDelay)
setUpdateDelay This method sets a new value for the TelegramRestBot::updateDelay property.
void setProcessed(const QSet< unsigned long long > &newProcessed) override
setProcessed This method sets a new list of processed updates. The bot will start to receive the upda...
bool login(const QByteArray &token) override
login This method gets basic information of the bot from the remote server and starts the long pollin...
int updateDelay() const
updateDelay This is the interval "how many msecs the bot will wait to send the next request for updat...
TelegramRestBot()
TelegramRestBot default constructor.
~TelegramRestBot()
~TelegramRestBot destructor. Stops the update polling.