blob: 9c50407cdf4c63755807e5f50897c2a0729176b9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
#ifndef TGBOT_TGLONGPOLL_H
#define TGBOT_TGLONGPOLL_H
#include "tgbot/Api.h"
#include "tgbot/export.h"
#include <cstdint>
#include <memory>
#include <string>
#include <vector>
namespace TgBot {
class Bot;
class EventHandler;
/**
* @brief This class handles long polling and updates parsing.
*
* @ingroup net
*/
class TGBOT_API TgLongPoll {
public:
TgLongPoll(const Api* api, const EventHandler* eventHandler, std::int32_t limit, std::int32_t timeout, std::shared_ptr<std::vector<std::string>> allowUpdates);
TgLongPoll(const Bot& bot, std::int32_t limit = 100, std::int32_t timeout = 10, const std::shared_ptr<std::vector<std::string>>& allowUpdates = nullptr);
/**
* @brief Starts long poll. After new update will come, this method will parse it and send to EventHandler which invokes your listeners. Designed to be executed in a loop.
*/
void start();
private:
const Api* _api;
const EventHandler* _eventHandler;
std::int32_t _lastUpdateId = 0;
std::int32_t _limit;
std::int32_t _timeout;
std::shared_ptr<std::vector<std::string>> _allowUpdates;
std::vector<Update::Ptr> _updates;
};
}
#endif //TGBOT_TGLONGPOLL_H
|