xxtelebot  1.4.1.0
A simple Telegram Bot implementation in C++
api.h
1 #ifndef TGBOT_METHODS_API_H
2 #define TGBOT_METHODS_API_H
3 
4 #include "../logger.h"
5 #include "types.h"
6 
7 namespace tgbot {
8 
12  namespace methods {
13 
14  namespace api_types = ::tgbot::types;
15 
19  class Api {
20  public:
21  Api() = delete;
22 
23  api_types::Message sendMessage(
24  const std::string &chatId, const std::string &text,
25  const types::ParseMode & = types::ParseMode::DEFAULT,
26  const bool &disableWebPagePreview = false,
27  const bool &disableNotification = false,
28  const types::ReplyMarkup &replyMarkup = "") const;
29 
30  api_types::Message sendMessage(
31  const std::string &chatId, const std::string &text,
32  const int &replyToMessageId,
33  const types::ParseMode & = types::ParseMode::DEFAULT,
34  const bool &disableWebPagePreview = false,
35  const bool &disableNotification = false,
36  const types::ReplyMarkup &replyMarkup = "") const;
37 
38  api_types::Message forwardMessage(
39  const std::string &chatId, const std::string &fromChatId,
40  const int &messageId, const bool &disableNotification = false) const;
41 
42  api_types::Message sendPhoto(
43  const std::string &chatId, const std::string &photo,
45  const std::string &mimeType = "", const std::string &caption = "",
46  const bool &disableNotification = false, const int &replyToMessageId = -1,
47  const types::ReplyMarkup &replyMarkup = "") const;
48 
49  api_types::Message sendAudio(
50  const std::string &chatId, const std::string &audio,
52  const std::string &mimeType = "", const std::string &caption = "",
53  const int &duration = -1, const std::string &performer = "",
54  const std::string &title = "", const bool &disableNotification = false,
55  const int &replyToMessageId = -1,
56  const types::ReplyMarkup &replyMarkup = "") const;
57 
58  api_types::Message sendDocument(
59  const std::string &chatId, const std::string &document,
61  const std::string &mimeType = "", const std::string &caption = "",
62  const bool &disableNotification = false, const int &replyToMessageId = -1,
63  const types::ReplyMarkup &replyMarkup = "") const;
64 
65  api_types::Message sendVideo(
66  const std::string &chatId, const std::string &video,
68  const std::string &mimeType = "", const int &duration = -1,
69  const int &width = -1, const int &height = -1,
70  const std::string &caption = "", const bool &supportsStreaming = false,
71  const bool &disableNotification = false, const int &replyToMessageId = -1,
72  const types::ReplyMarkup &replyMarkup = "") const;
73 
74  api_types::Message sendVoice(
75  const std::string &chatId, const std::string &voice,
77  const std::string &caption = "", const int &duration = -1,
78  const bool &disableNotification = false, const int &replyToMessageId = -1,
79  const types::ReplyMarkup &replyMarkup = "") const;
80 
81  api_types::Message sendVideoNote(
82  const std::string &chatId, const std::string &videoNote,
84  const std::string &caption = "", const int &duration = -1,
85  const bool &disableNotification = false, const int &replyToMessageId = -1,
86  const types::ReplyMarkup &replyMarkup = "") const;
87 
88  api_types::Message sendLocation(
89  const std::string &chatId, const double &latitude,
90  const double &longitude, const int &liveLocation = -1,
91  const bool &disableNotification = false, const int &replyToMessageId = -1,
92  const types::ReplyMarkup &replyMarkup = "") const;
93 
94  api_types::Message sendVenue(
95  const std::string &chatId, const double &latitude,
96  const double &longitude, const std::string &title,
97  const std::string &address, const std::string& foursquareType = "",
98  const std::string &foursquareId = "",
99  const bool &disableNotification = false, const int &replyToMessageId = -1,
100  const types::ReplyMarkup &replyMarkup = "") const;
101 
102  api_types::Message sendContact(
103  const std::string &chatId, const std::string &phoneNumber,
104  const std::string &firstName, const std::string &vCard = "",
105  const std::string &lastName = "",
106  const bool &disableNotification = false, const int &replyToMessageId = -1,
107  const types::ReplyMarkup &replyMarkup = "") const;
108 
109  api_types::Message sendSticker(
110  const std::string &chatId, const std::string &sticker,
112  const bool &disableNotification = false, const int &replyToMessageId = -1,
113  const types::ReplyMarkup &replyMarkup = "") const;
114 
118  api_types::Message sendInvoice(const int &chatId,
119  const types::Invoice &invoice,
120  const bool &disableNotification = false,
121  const int &replyToMessageId = -1) const;
122 
126  api_types::Message sendInvoice(const int &chatId,
127  const types::Invoice &invoice,
128  const types::InlineKeyboardMarkup &replyMarkup,
129  const bool &disableNotification = false,
130  const int &replyToMessageId = -1) const;
131 
132  std::vector<api_types::Message> sendMediaGroup(
133  const std::string &chatId,
134  const std::vector<tgbot::types::Ptr<types::InputMedia>> &media,
135  const bool &disableNotification = false,
136  const int &replyToMessageId = -1) const;
137 
138  api_types::Message sendGame(const int &chatId,
139  const std::string &gameShortName,
140  const bool &disableNotification = false,
141  const int &replyToMessageId = -1,
142  const types::ReplyMarkup &replyMarkup = "") const;
143 
144  api_types::Message sendPoll(const std::string& chatId,
145  const std::string& question,
146  const std::vector<std::string>& options,
147  const bool &disableNotification = false,
148  const int &replyToMessageId = -1,
149  const types::ReplyMarkup &replyMarkup = "") const;
150 
151  tgbot::types::Poll stopPoll(const std::string& chatId,
152  const int& messageId,
153  const types::ReplyMarkup &replyMarkup = "") const;
154 
155  api_types::Message setGameScore(const std::string &userId, const int &score,
156  const std::string &inlineMessageId,
157  const bool &force = false,
158  const bool &disableEditMessage = false) const;
159 
160  api_types::Message setGameScore(const std::string &userId, const int &score,
161  const int &chatId, const int &messageId,
162  const bool &force = false,
163  const bool &disableEditMessage = false) const;
164 
165  std::vector<api_types::GameHighScore> getGameHighScores(
166  const int &userId, const std::string &inlineMessageId) const;
167 
168  std::vector<api_types::GameHighScore> getGameHighScores(
169  const int &userId, const int &chatId, const int &messageId) const;
170 
174  bool answerShippingQuery(const std::string &shippingQueryId,
175  const std::string &errorMessage) const;
176 
180  bool answerShippingQuery(
181  const std::string &shippingQueryId,
182  const std::vector<types::ShippingOption> &shippingOptions) const;
183 
187  bool answerPreCheckoutQuery(const std::string &preCheckoutQueryId,
188  const std::string &errorMessage) const;
189 
193  bool answerPreCheckoutQuery(const std::string &preCheckoutQueryId) const;
194 
195  api_types::StickerSet getStickerSet(const std::string &name) const;
196 
197  api_types::File uploadStickerFile(
198  const int &userId, const std::string &pngSticker,
199  const types::FileSource &source = types::FileSource::EXTERNAL) const;
200 
201  bool createNewStickerSet(
202  const int &userId, const std::string &name, const std::string &title,
203  const std::string &emoji, const std::string &pngSticker,
204  const types::FileSource &source = types::FileSource::EXTERNAL) const;
205 
206  bool createNewStickerSet(
207  const int &userId, const std::string &name, const std::string &title,
208  const std::string &emoji, const std::string &pngSticker,
209  const api_types::MaskPosition &maskPosition,
210  const types::FileSource &source = types::FileSource::EXTERNAL) const;
211 
212  bool addStickerToSet(
213  const int &userId, const std::string &name, const std::string &emoji,
214  const std::string &pngSticker,
215  const types::FileSource &source = types::FileSource::EXTERNAL) const;
216 
217  bool addStickerToSet(
218  const int &userId, const std::string &name, const std::string &emoji,
219  const std::string &pngSticker,
220  const api_types::MaskPosition &maskPosition,
221  const types::FileSource &source = types::FileSource::EXTERNAL) const;
222 
223  bool setStickerPositionInSet(const std::string &sticker,
224  const int &position) const;
225 
226  bool deleteStickerFromSet(const std::string &sticker) const;
227 
228  bool sendChatAction(const std::string &chatId,
229  const types::ChatAction &action) const;
230 
231  bool kickChatMember(const std::string &chatId, const int &userId,
232  const int &untilDate = -1) const;
233 
234  bool unbanChatMember(const std::string &chatId, const int &userId) const;
235 
236  bool restrictChatMember(const std::string &chatId, const int &userId,
237  const types::ChatMemberRestrict &permissions,
238  const int &untilDate = -1) const;
239 
240  bool promoteChatMember(const std::string &chatId, const int &userId,
241  const types::ChatMemberPromote &permissions) const;
242 
243  std::string exportChatInviteLink(const std::string &chatId) const;
244 
245  bool setChatPhoto(const std::string &chatId, const std::string &filename,
246  const std::string &mimeType) const;
247 
248  bool deleteChatPhoto(const std::string &chatId) const;
249 
250  bool setChatTitle(const std::string &chatId, const std::string &title) const;
251 
252  bool setChatDescription(const std::string &chatId,
253  const std::string &description) const;
254 
255  bool pinChatMessage(const std::string &chatId, const std::string &messageId,
256  const bool &disableNotification = false) const;
257 
258  bool unpinChatMessage(const std::string &chatId) const;
259 
260  bool leaveChat(const std::string &chatId) const;
261 
262  bool answerCallbackQuery(const std::string &callbackQueryId,
263  const std::string &text = "",
264  const bool &showAlert = false,
265  const std::string &url = "",
266  const int &cacheTime = 0) const;
267 
268  bool answerInlineQuery(
269  const std::string &inlineQueryId,
270  const std::vector<::tgbot::types::Ptr<types::InlineQueryResult>> &results,
271  const int &cacheTime = 0, const bool &isPersonal = true,
272  const std::string &nextOffset = "", const std::string &switchPmText = "",
273  const std::string &switchPmParameter = "") const;
274 
275  api_types::Message editMessageText(
276  const std::string &inlineMessageId, const std::string &text,
277  const types::ParseMode &parseMode = types::ParseMode::DEFAULT,
278  const bool &disableWebPagePreview = false) const;
279 
280  api_types::Message editMessageText(
281  const std::string &inlineMessageId,
282  const types::InlineKeyboardMarkup &replyMarkup, const std::string &text,
283  const types::ParseMode &parseMode = types::ParseMode::DEFAULT,
284  const bool &disableWebPagePreview = false) const;
285 
286  api_types::Message editMessageText(
287  const std::string &chatId, const std::string &messageId,
288  const std::string &text,
289  const types::ParseMode &parseMode = types::ParseMode::DEFAULT,
290  const bool &disableWebPagePreview = false) const;
291 
292  api_types::Message editMessageText(
293  const std::string &chatId, const std::string &messageId,
294  const types::InlineKeyboardMarkup &replyMarkup, const std::string &text,
295  const types::ParseMode &parseMode = types::ParseMode::DEFAULT,
296  const bool &disableWebPagePreview = false) const;
297 
298  api_types::Message editMessageReplyMarkup(
299  const std::string &inlineMessageId,
300  const types::InlineKeyboardMarkup &replyMarkup) const;
301 
302  api_types::Message editMessageReplyMarkup(
303  const std::string &chatId, const std::string &messageId,
304  const types::InlineKeyboardMarkup &replyMarkup) const;
305 
306  api_types::Message editMessageCaption(const std::string &chatId,
307  const std::string &messageId,
308  const std::string &caption) const;
309 
310  api_types::Message editMessageCaption(const std::string &inlineMessageId,
311  const std::string &caption) const;
312 
313  api_types::Message editMessageCaption(
314  const std::string &chatId, const std::string &messageId,
315  const types::InlineKeyboardMarkup &replyMarkup,
316  const std::string &caption) const;
317 
318  api_types::Message editMessageCaption(
319  const std::string &inlineMessageId,
320  const types::InlineKeyboardMarkup &replyMarkup,
321  const std::string &caption) const;
322 
323  api_types::Message editMessageLiveLocation(
324  const double &longitude, const double &latitude, const int &chatId,
325  const int &messageId, const types::ReplyMarkup &replyMarkup = "") const;
326 
327  api_types::Message editMessageLiveLocation(
328  const double &longitude, const double &latitude,
329  const std::string &inlineMessageId,
330  const types::ReplyMarkup &replyMarkup = "") const;
331 
332  api_types::Message editMessageMedia(
333  const std::string &inlineMessageId,
334  const types::InputMedia &media,
335  const types::ReplyMarkup &replyMarkup = ""
336  ) const;
337 
338  api_types::Message editMessageMedia(
339  const std::string &chatId,
340  const int &messageId,
341  const types::InputMedia &media,
342  const types::ReplyMarkup &replyMarkup = ""
343  ) const;
344 
345  api_types::Message stopMessageLiveLocation(
346  const int &chatId, const int &messageId,
347  const types::ReplyMarkup &replyMarkup = "") const;
348 
349  api_types::Message stopMessageLiveLocation(
350  const std::string &inlineMessageId,
351  const types::ReplyMarkup &replyMarkup = "") const;
352 
353  bool setChatStickerSet(const int &chatId,
354  const std::string &stickerSetName) const;
355 
356  bool setChatStickerSet(const std::string &chatId,
357  const std::string &stickerSetName) const;
358 
359  bool deleteChatStickerSet(const int &chatId) const;
360 
361  bool deleteChatStickerSet(const std::string &chatId) const;
362 
363  bool deleteMessage(const std::string &chatId,
364  const std::string &messageId) const;
365 
366  api_types::User getMe() const;
367 
368  api_types::File getFile(const std::string &fileId) const;
369 
370  api_types::Chat getChat(const std::string &chatId) const;
371 
372  std::vector<api_types::ChatMember> getChatAdministrators(
373  const std::string &chatId) const;
374 
375  unsigned getChatMembersCount(const std::string &chatId) const;
376 
377  api_types::ChatMember getChatMember(const std::string &chatId,
378  const int &userId) const;
379 
380  api_types::UserProfilePhotos getUserProfilePhotos(
381  const int &userId, const unsigned &offset = 0,
382  const unsigned &limit = 100) const;
383 
384  bool deleteWebhook() const;
385 
386  api_types::WebhookInfo getWebhookInfo() const;
387 
388  bool setWebhook(
389  const std::string &url, const int &maxConnections = 40,
390  const std::vector<api_types::UpdateType> &allowedUpdates = {});
391 
392  bool setWebhook(
393  const std::string &url, const std::string &certificate,
394  const int &maxConnections = 40,
395  const std::vector<api_types::UpdateType> &allowedUpdates = {});
396 
397  inline Logger const &getLogger() const { return logger; }
398 
399  inline Logger &getLogger() { return logger; }
400 
401  protected:
402  explicit Api(const std::string &token);
403 
404  Api(const std::string &token,
405  const std::vector<api_types::UpdateType> &allowedUpdates,
406  const int &timeout, const int &limit);
407 
408  Api(const std::string &token, const std::string &url,
409  const int &maxConnections,
410  const std::vector<api_types::UpdateType> &allowedUpdates);
411 
412  Api(const std::string &token, const std::string &url,
413  const std::string &certificate, const int &maxConnections,
414  const std::vector<api_types::UpdateType> &allowedUpdates);
415 
416  int getUpdates(void *c, std::vector<api_types::Update> &updates);
417 
418  std::string urlWebhook{""};
419 
420  private:
421  std::string baseApi{""};
422  std::string updateApiRequest{""};
423  int currentOffset{0};
424  tgbot::Logger logger;
425  };
426 
427  } // namespace methods
428 
429 } // namespace tgbot
430 
431 #endif
bool answerPreCheckoutQuery(const std::string &preCheckoutQueryId, const std::string &errorMessage) const
Use this overload if the checkout phase can take place.
Definition: types.h:502
API-interacting types.
Definition: types.h:16
Definition: types.h:308
Definition: types.h:194
This struct contains parameters for sendInvoice method.
Definition: types.h:543
FileSource
Choose if filename should be treated as file_id or uploaded via multipart.
Definition: types.h:70
ChatAction
What the bot is doing.
Definition: types.h:53
Definition: types.h:128
Definition: types.h:67
Main tgbot namespace.
Definition: bot.h:13
Definition: types.h:478
Definition: types.h:335
Definition: types.h:524
ParseMode
Parsing mode to be used.
Definition: types.h:46
Definition: types.h:218
Logging facility for telegram-bot-api, see also: tgbot::methods::Api::getLogger() ...
Definition: logger.h:12
Definition: types.h:345
bool answerShippingQuery(const std::string &shippingQueryId, const std::string &errorMessage) const
Use this overload if the shipping query cannot proceed.
Definition: types.h:487
Definition: types.h:576
Contains Telegram bot API methods.
Definition: api.h:19
api_types::Message sendInvoice(const int &chatId, const types::Invoice &invoice, const bool &disableNotification=false, const int &replyToMessageId=-1) const
Please refer to tgbot::methods::types::Invoice struct.