xxtelebot  1.4.1.0
A simple Telegram Bot implementation in C++
types.h
1 #ifndef TGBOT_TYPES_H
2 #define TGBOT_TYPES_H
3 
4 #include <memory>
5 #include <string>
6 #include <vector>
7 
8 namespace Json {
9  struct Value;
10 }
11 
12 namespace tgbot {
16  namespace types {
17 
21  template<typename _Ty>
22  using Ptr = std::unique_ptr<_Ty>;
23 
24  struct Message; // forward declaration
25 
26  enum class UpdateType {
27  MESSAGE,
28  EDITED_MESSAGE,
29  EDITED_CHANNEL_POST,
30  INLINE_QUERY,
31  CHOSEN_INLINE_RESULT,
32  CALLBACK_QUERY,
33  SHIPPING_QUERY,
34  PRE_CHECKOUT_QUERY,
35  CHANNEL_POST
36  };
37 
38  enum class ChatType {
39  PRIVATE, GROUP, SUPERGROUP, CHANNEL
40  };
41 
42  enum class MessageEntityType {
43  MENTION,
44  HASHTAG,
45  BOT_COMMAND,
46  URL,
47  EMAIL,
48  BOLD,
49  ITALIC,
50  CODE,
51  PRE,
52  TEXT_LINK,
53  TEXT_MENTION,
54  CASHTAG,
55  PHONE_NUMBER
56  };
57 
58  enum class ChatMemberStatus {
59  CREATOR,
60  ADMINISTRATOR,
61  MEMBER,
62  RESTRICTED,
63  LEFT,
64  KICKED
65  };
66 
67  struct User {
68  public:
69  explicit User(const Json::Value &object);
70 
71  std::string firstName;
72  Ptr<std::string> lastName;
73  Ptr<std::string> username;
74  Ptr<std::string> languageCode;
75  int id;
76  bool isBot : 1;
77  };
78 
79  struct ChatPhoto {
80  public:
81  explicit ChatPhoto(const Json::Value &object);
82 
83  std::string smallFileId;
84  std::string bigFileId;
85  };
86 
87  struct MessageEntity {
88  public:
89  explicit MessageEntity(const Json::Value &object);
90 
91  Ptr<User> user;
92  Ptr<std::string> url;
93  int offset;
94  int length;
95  MessageEntityType type;
96  };
97 
98  struct PhotoSize {
99  public:
100  PhotoSize() = default;
101 
102  explicit PhotoSize(const Json::Value &object);
103 
104  std::string fileId;
105  int fileSize;
106  int width;
107  int height;
108  };
109 
110  struct Audio {
111  public:
112  explicit Audio(const Json::Value &object);
113 
114  std::string fileId;
115  Ptr<std::string> performer;
116  Ptr<std::string> title;
117  Ptr<std::string> mimeType;
118  Ptr<PhotoSize> thumb;
119  int fileSize;
120  int duration;
121  };
122  struct Document {
123  public:
124  explicit Document(const Json::Value &object);
125 
126  std::string fileId;
127  Ptr<PhotoSize> thumb;
128  Ptr<std::string> fileName;
129  Ptr<std::string> mimeType;
130  int fileSize;
131  };
132 
133  struct Voice {
134  public:
135  explicit Voice(const Json::Value &object);
136 
137  std::string fileId;
138  Ptr<std::string> mimeType;
139  int fileSize;
140  int duration;
141  };
142 
143  struct Contact {
144  public:
145  explicit Contact(const Json::Value &object);
146 
147  std::string phoneNumber;
148  std::string firstName;
149  Ptr<std::string> lastName;
150  int userId;
151  };
152 
153  struct Location {
154  public:
155  explicit Location(const Json::Value &object);
156 
157  double longitude;
158  double latitude;
159  };
160 
161  struct Animation {
162  public:
163  explicit Animation(const Json::Value &object);
164 
165  std::string fileId;
166  Ptr<PhotoSize> thumb;
167  Ptr<std::string> fileName;
168  Ptr<std::string> mimeType;
169  int fileSize;
170  };
171 
172  struct Venue {
173  public:
174  explicit Venue(const Json::Value &object);
175 
176  Location location;
177  std::string title;
178  std::string address;
179  Ptr<std::string> foursquareId;
180  Ptr<std::string> foursquareType;
181  };
182 
183  struct VideoNote {
184  public:
185  explicit VideoNote(const Json::Value &object);
186 
187  std::string fileId;
188  Ptr<PhotoSize> thumb;
189  int fileSize;
190  int length;
191  int duration;
192  };
193 
194  struct MaskPosition {
195  public:
196  explicit MaskPosition(const Json::Value &object);
197 
198  std::string point;
199  double xShift;
200  double yShift;
201  double scale;
202  };
203 
204  struct Sticker {
205  public:
206  explicit Sticker(const Json::Value &object);
207 
208  std::string fileId;
209  Ptr<MaskPosition> maskPosition;
210  Ptr<PhotoSize> thumb;
211  Ptr<std::string> emoji;
212  Ptr<std::string> setName;
213  int width;
214  int height;
215  int fileSize;
216  };
217 
218  struct StickerSet {
219  public:
220  explicit StickerSet(const Json::Value &object);
221 
222  std::string name;
223  std::string title;
224  std::vector<Sticker> stickers;
225  bool containsMasks : 1;
226  };
227 
228  struct Video {
229  public:
230  explicit Video(const Json::Value &object);
231 
232  std::string fileId;
233  Ptr<PhotoSize> thumb;
234  Ptr<std::string> mimeType;
235  int fileSize;
236  int width;
237  int height;
238  int duration;
239  };
240 
241  struct Invoice {
242  public:
243  explicit Invoice(const Json::Value &object);
244 
245  std::string title;
246  std::string description;
247  std::string startParameter;
248  std::string currency;
249  int totalAmount;
250  };
251 
253  public:
254  explicit ShippingAddress(const Json::Value &object);
255 
256  std::string countryCode;
257  std::string state;
258  std::string city;
259  std::string streetLineOne;
260  std::string streetLineTwo;
261  std::string postCode;
262  };
263 
264  struct OrderInfo {
265  public:
266  explicit OrderInfo(const Json::Value &object);
267 
268  Ptr<ShippingAddress> shippingAddress;
269  Ptr<std::string> name;
270  Ptr<std::string> phoneNumber;
271  Ptr<std::string> email;
272  };
273 
275  public:
276  explicit SuccessfulPayment(const Json::Value &object);
277 
278  std::string currency;
279  std::string invoicePayload;
280  std::string telegramPaymentChargeId;
281  std::string providerPaymentChargeId;
282  Ptr<std::string> shippingOptionId;
283  Ptr<OrderInfo> orderInfo;
284  int totalAmount;
285  };
286 
287  struct Game {
288  public:
289  explicit Game(const Json::Value &object);
290 
291  std::string title;
292  std::string description;
293  std::vector<PhotoSize> photo;
294  Ptr<Animation> animation;
295  Ptr<std::vector<MessageEntity>> textEntities;
296  Ptr<std::string> text;
297  };
298 
299  struct GameHighScore {
300  public:
301  explicit GameHighScore(const Json::Value &object);
302 
303  User user;
304  int position;
305  int score;
306  };
307 
308  struct Chat {
309  public:
310  explicit Chat(const Json::Value &object);
311 
312  ChatType type;
313  Ptr<Message> pinnedMessage;
314  Ptr<ChatPhoto> photo;
315  Ptr<std::string> title;
316  Ptr<std::string> username;
317  Ptr<std::string> firstName;
318  Ptr<std::string> lastName;
319  Ptr<std::string> description;
320  Ptr<std::string> inviteLink;
321  Ptr<std::string> stickerSetName;
322  std::int64_t id;
323  bool allMembersAreAdministrators : 1;
324  bool canSetStickerSet : 1;
325  };
326 
327  struct PollOptions {
328  public:
329  explicit PollOptions(const Json::Value &object);
330 
331  std::string text;
332  int voterCount;
333  };
334 
335  struct Poll {
336  public:
337  explicit Poll(const Json::Value &object);
338 
339  std::vector<PollOptions> options;
340  std::string question;
341  int id;
342  bool isClosed : 1;
343  };
344 
345  struct Message {
346  public:
347  explicit Message(const Json::Value &object);
348 
349  Chat chat; // guranteed
350  Ptr<User> from;
351  Ptr<User> forwardFrom;
352  Ptr<Chat> forwardFromChat;
353  Ptr<std::string> forwardSignature;
354  Ptr<Message> replyToMessage;
355  Ptr<std::string> authorSignature;
356  Ptr<std::string> text;
357  Ptr<std::vector<MessageEntity>> entities;
358  Ptr<Audio> audio;
359  Ptr<Document> document;
360  Ptr<Game> game;
361  Ptr<std::vector<PhotoSize>> photo;
362  Ptr<Sticker> sticker;
363  Ptr<Video> video;
364  Ptr<Voice> voice;
365  Ptr<VideoNote> videoNote;
366  Ptr<std::string> caption;
367  Ptr<Contact> contact;
368  Ptr<Location> location;
369  Ptr<Venue> venue;
370  Ptr<std::vector<User>> newChatMembers;
371  Ptr<User> leftChatMember;
372  Ptr<std::string> newChatTitle;
373  Ptr<std::vector<PhotoSize>> newChatPhoto;
374  Ptr<Message> pinnedMessage;
375  Ptr<Invoice> invoice;
376  Ptr<SuccessfulPayment> successfulPayment;
377  Ptr<std::vector<MessageEntity>> captionEntities;
378  Ptr<std::string> connectedWebsite;
379  Ptr<Animation> animation;
380  Ptr<std::string> forwardSenderName;
381  Ptr<Poll> poll;
382  std::int64_t migrateToChatId;
383  std::int64_t migrateFromChatId;
384  int forwardFromMessageId;
385  int forwardDate;
386  int editDate;
387  int messageId; // guranteed
388  int date; // guranteed
389  bool deleteChatPhoto : 1;
390  bool groupChatCreated : 1;
391  bool supergroupChatCreated : 1;
392  bool channelChatCreated : 1;
393  };
394 
395  struct InlineQuery {
396  public:
397  explicit InlineQuery(const Json::Value &object);
398 
399  User from;
400  std::string id;
401  std::string query;
402  std::string offset;
403  Ptr<Location> location;
404  };
405 
407  public:
408  explicit ChosenInlineResult(const Json::Value &object);
409 
410  User from;
411  std::string resultId;
412  std::string query;
413  Ptr<Location> location;
414  Ptr<std::string> inlineMessageId;
415  };
416 
417  struct CallbackQuery {
418  public:
419  explicit CallbackQuery(const Json::Value &object);
420 
421  User from;
422  std::string id;
423  std::string chatInstance;
424  Ptr<Message> message;
425  Ptr<std::string> inlineMessageId;
426  Ptr<std::string> data;
427  Ptr<std::string> gameShortName;
428  };
429 
430  struct ShippingQuery {
431  public:
432  explicit ShippingQuery(const Json::Value &object);
433 
434  ShippingAddress shippingAddress;
435  User from;
436  std::string id;
437  std::string invoicePayload;
438  };
439 
441  public:
442  explicit PreCheckoutQuery(const Json::Value &object);
443 
444  User from;
445  std::string currency;
446  std::string invoicePayload;
447  std::string id;
448  Ptr<std::string> shippingOptionId;
449  Ptr<OrderInfo> orderInfo;
450  int totalAmount;
451  };
452 
453  struct Update {
454  public:
455  explicit Update(const Json::Value &object);
456 
457  Ptr<Message> message;
458  Ptr<Message> editedMessage;
459  Ptr<Message> channelPost;
460  Ptr<Message> editedChannelPost;
461  Ptr<InlineQuery> inlineQuery;
462  Ptr<ChosenInlineResult> chosenInlineResult;
463  Ptr<CallbackQuery> callbackQuery;
464  Ptr<ShippingQuery> shippingQuery;
465  Ptr<PreCheckoutQuery> preCheckoutQuery;
466  UpdateType updateType;
467  int updateId;
468  };
469 
471  public:
472  explicit ResponseParameters(const Json::Value &object);
473 
474  std::int64_t migrateToChatId;
475  int retryAfter;
476  };
477 
478  struct File {
479  public:
480  explicit File(const Json::Value &object);
481 
482  std::string fileId;
483  Ptr<std::string> filePath;
484  int fileSize;
485  };
486 
488  public:
489  explicit UserProfilePhotos(const Json::Value &object);
490 
491  std::vector<std::vector<PhotoSize>> photos;
492  int totalCount;
493  };
494 
495  struct KeyboardButton {
496  public:
497  std::string text;
498  bool requestContact : 1;
499  bool requestLocation : 1;
500  };
501 
502  struct WebhookInfo {
503  public:
504  explicit WebhookInfo(const Json::Value &object);
505 
506  std::string url;
507  Ptr<std::string> lastErrorMessage;
508  Ptr<std::vector<std::string>> allowedUpdates;
509  int pendingUpdateCount;
510  int lastErrorDate;
511  int maxConnections;
512  bool hasCustomCertificate : 1;
513  };
514 
520  enum class CallbackGame {
521  GAME_CALLBACK
522  };
523 
524  struct ChatMember {
525  public:
526  explicit ChatMember(const Json::Value &object);
527 
528  User user;
529  ChatMemberStatus status;
530  int untilDate;
531  bool canBeEdited : 1;
532  bool canChangeInfo : 1;
533  bool canPostMessages : 1;
534  bool canEditMessages : 1;
535  bool canDeleteMessages : 1;
536  bool canInviteUsers : 1;
537  bool canRestrictMembers : 1;
538  bool canPinMessages : 1;
539  bool canPromoteMembers : 1;
540  bool canSendMessages : 1;
541  bool canSendMediaMessages : 1;
542  bool canSendOtherMessages : 1;
543  bool canAddWebPagePreviews : 1;
544  bool isMember : 1;
545  };
546 
547  } // namespace types
548 
549 } // namespace tgbot
550 
551 #endif
Definition: types.h:502
Definition: types.h:308
Definition: types.h:98
Definition: types.h:87
Definition: types.h:204
Definition: types.h:252
Definition: types.h:194
Definition: types.h:133
Definition: types.h:395
CallbackGame
(note) according to telegram API documentation, this is only a placeholder, currently using this has ...
Definition: types.h:520
Definition: types.h:299
Definition: types.h:67
Definition: types.h:241
Main tgbot namespace.
Definition: bot.h:13
Definition: types.h:478
Definition: types.h:335
Definition: types.h:524
Definition: types.h:228
Definition: types.h:264
Definition: types.h:183
Definition: types.h:495
Definition: types.h:470
Definition: types.h:453
Definition: types.h:161
Definition: types.h:218
Definition: types.h:430
Definition: types.h:345
Definition: types.h:8
Definition: types.h:79
Definition: types.h:417
Definition: types.h:110
Definition: types.h:122
Definition: types.h:440
Definition: types.h:274
Definition: types.h:327
Definition: types.h:172
Definition: types.h:153
Definition: types.h:487
Definition: types.h:287
Definition: types.h:406
Definition: types.h:143