xxtelebot  1.4.1.0
A simple Telegram Bot implementation in C++
bot.h
1 #ifndef TGBOT_BOT_H
2 #define TGBOT_BOT_H
3 
4 #include <exception>
5 #include <utility>
6 
7 #include "register_callback.h"
8 #include "utils/https.h"
9 
13 namespace tgbot {
14 
18  class TelegramException : public std::exception {
19  public:
20  explicit TelegramException(const std::string &_what) : __what(_what) {}
21 
22  const char *what() const noexcept override { return __what.c_str(); }
23 
24  private:
25  const std::string __what;
26  };
27 
31  class Bot : public methods::Api, public RegisterCallback {
32  public:
33  Bot(const Bot&) = default;
34  Bot(Bot&&) = default;
35 
36  Bot& operator=(const Bot&) = default;
37  Bot& operator=(Bot&&) = default;
38 
39  virtual ~Bot() = default;
40 
41  virtual void start() {}
42 
47  void notifyEachUpdate(bool t);
48 
49  protected:
50  template<typename... TyArgs>
51  explicit Bot(TyArgs &&... many) : Api(std::forward<TyArgs>(many)...) {
52  utils::http::__internal_Curl_GlobalInit();
53  }
54 
55  void makeCallback(const std::vector<types::Update> &updates) const;
56 
57  private:
58  bool __notifyEachUpdate{false};
59  };
60 
64  class LongPollBot : public Bot {
65  public:
75  explicit LongPollBot(const std::string &token,
76  const std::vector<types::UpdateType> &filterUpdates = {},
77  const int &limit = 100, const int &timeout = 60);
78 
79  LongPollBot(const LongPollBot &) = delete;
80 
81  LongPollBot(LongPollBot &&) = default;
82 
83  LongPollBot &operator=(const LongPollBot &) = delete;
84 
85  LongPollBot &operator=(LongPollBot &&) = default;
86 
90  void start() override;
91  };
92 
96  class WebhookBot : public Bot {
97  public:
101  WebhookBot() = delete;
102 
107  WebhookBot(const std::string &token) = delete;
108 
117  WebhookBot(const std::string &token, const std::string &url,
118  const int &maxConnections = 40,
119  const std::vector<types::UpdateType> &filterUpdates = {}) = delete;
120 
130  WebhookBot(const std::string &token, const std::string &url,
131  const std::string &certificate, const int &maxConnections = 40,
132  const std::vector<types::UpdateType> &filterUpdates = {}) = delete;
133 
134  WebhookBot(const WebhookBot &) = delete;
135 
136  WebhookBot(WebhookBot &&) = delete;
137 
138  WebhookBot &operator=(const WebhookBot &) = delete;
139 
140  WebhookBot &operator=(WebhookBot &&) = delete;
141 
142  // start()
143  };
144 
145 } // namespace tgbot
146 
147 #endif
Webhook bot (see WebhookBot::start() function)
Definition: bot.h:96
registers and holds callbacks for each type of update
Definition: register_callback.h:24
Exception raised when Bot API reports some kind of error.
Definition: bot.h:18
Main tgbot namespace.
Definition: bot.h:13
Basic Bot interface.
Definition: bot.h:31
Long polling bot, (see LongPollBot::start() function)
Definition: bot.h:64
Contains Telegram bot API methods.
Definition: api.h:19