tgbotxx  1.1.6.9
Telegram Bot C++ Library
Update.hpp
Go to the documentation of this file.
1 #pragma once
17 
18 namespace tgbotxx {
22  struct Update {
23  Update() = default;
24  explicit Update(const nl::json& json) {
25  fromJson(json);
26  }
27 
33  std::int32_t updateId{};
34 
37 
40 
43 
46 
51 
56 
59 
63 
66 
69 
72 
75 
78 
81 
84 
87 
90 
93 
96  nl::json toJson() const {
97  nl::json json = nl::json::object();
98  OBJECT_SERIALIZE_FIELD(json, "update_id", updateId);
99  OBJECT_SERIALIZE_FIELD_PTR(json, "message", message);
100  OBJECT_SERIALIZE_FIELD_PTR(json, "edited_message", editedMessage);
101  OBJECT_SERIALIZE_FIELD_PTR(json, "channel_post", channelPost);
102  OBJECT_SERIALIZE_FIELD_PTR(json, "edited_channel_post", editedChannelPost);
103  OBJECT_SERIALIZE_FIELD_PTR(json, "message_reaction", messageReaction);
104  OBJECT_SERIALIZE_FIELD_PTR(json, "message_reaction_count", messageReactionCount);
105  OBJECT_SERIALIZE_FIELD_PTR(json, "inline_query", inlineQuery);
106  OBJECT_SERIALIZE_FIELD_PTR(json, "chosen_inline_result", chosenInlineResult);
107  OBJECT_SERIALIZE_FIELD_PTR(json, "callback_query", callbackQuery);
108  OBJECT_SERIALIZE_FIELD_PTR(json, "shipping_query", shippingQuery);
109  OBJECT_SERIALIZE_FIELD_PTR(json, "pre_checkout_query", preCheckoutQuery);
110  OBJECT_SERIALIZE_FIELD_PTR(json, "poll", poll);
111  OBJECT_SERIALIZE_FIELD_PTR(json, "poll_answer", pollAnswer);
112  OBJECT_SERIALIZE_FIELD_PTR(json, "my_chat_member", myChatMember);
113  OBJECT_SERIALIZE_FIELD_PTR(json, "chat_member", chatMember);
114  OBJECT_SERIALIZE_FIELD_PTR(json, "chat_join_request", chatJoinRequest);
115  OBJECT_SERIALIZE_FIELD_PTR(json, "chat_boost", chatBoost);
116  OBJECT_SERIALIZE_FIELD_PTR(json, "removed_chat_boost", removedChatBoost);
117  return json;
118  }
119 
121  void fromJson(const nl::json& json) {
122  OBJECT_DESERIALIZE_FIELD(json, "update_id", updateId, 0, false);
123  OBJECT_DESERIALIZE_FIELD_PTR(json, "message", message, true);
124  OBJECT_DESERIALIZE_FIELD_PTR(json, "edited_message", editedMessage, true);
125  OBJECT_DESERIALIZE_FIELD_PTR(json, "channel_post", channelPost, true);
126  OBJECT_DESERIALIZE_FIELD_PTR(json, "edited_channel_post", editedChannelPost, true);
127  OBJECT_DESERIALIZE_FIELD_PTR(json, "message_reaction", messageReaction, true);
128  OBJECT_DESERIALIZE_FIELD_PTR(json, "inline_query", inlineQuery, true);
129  OBJECT_DESERIALIZE_FIELD_PTR(json, "chosen_inline_result", chosenInlineResult, true);
130  OBJECT_DESERIALIZE_FIELD_PTR(json, "callback_query", callbackQuery, true);
131  OBJECT_DESERIALIZE_FIELD_PTR(json, "shipping_query", shippingQuery, true);
132  OBJECT_DESERIALIZE_FIELD_PTR(json, "pre_checkout_query", preCheckoutQuery, true);
133  OBJECT_DESERIALIZE_FIELD_PTR(json, "poll", poll, true);
134  OBJECT_DESERIALIZE_FIELD_PTR(json, "poll_answer", pollAnswer, true);
135  OBJECT_DESERIALIZE_FIELD_PTR(json, "my_chat_member", myChatMember, true);
136  OBJECT_DESERIALIZE_FIELD_PTR(json, "chat_member", chatMember, true);
137  OBJECT_DESERIALIZE_FIELD_PTR(json, "chat_join_request", chatJoinRequest, true);
138  OBJECT_DESERIALIZE_FIELD_PTR(json, "chat_boost", chatBoost, true);
139  OBJECT_DESERIALIZE_FIELD_PTR(json, "removed_chat_boost", removedChatBoost, true);
140  }
141  };
142 }
#define OBJECT_SERIALIZE_FIELD_PTR(json, json_field, field)
Definition: Object.hpp:22
#define OBJECT_DESERIALIZE_FIELD_PTR(json, json_field, field, optional)
Definition: Object.hpp:70
#define OBJECT_SERIALIZE_FIELD(json, json_field, field)
Available objects: https://core.telegram.org/bots/api#available-types.
Definition: Object.hpp:19
#define OBJECT_DESERIALIZE_FIELD(json, json_field, field, default_value, optional)
Deserialize.
Definition: Object.hpp:44
Definition: Api.hpp:14
std::shared_ptr< T > Ptr
Definition: Ptr.hpp:6
This object represents an incoming update. At most one of the optional parameters can be present in a...
Definition: Update.hpp:22
Ptr< Message > message
Optional. New incoming message of any kind — text, photo, sticker, etc.
Definition: Update.hpp:36
Ptr< ChatMemberUpdated > myChatMember
Optional. The bot's chat member status was updated in a chat. For private chats, this update is recei...
Definition: Update.hpp:80
Update()=default
Ptr< Message > channelPost
Optional. New incoming channel post of any kind — text, photo, sticker, etc.
Definition: Update.hpp:42
Ptr< MessageReactionCountUpdated > messageReactionCount
Optional. Reactions to a message with anonymous reactions were changed. The bot must be an administra...
Definition: Update.hpp:55
nl::json toJson() const
Serializes this object to JSON.
Definition: Update.hpp:96
Ptr< ChatJoinRequest > chatJoinRequest
Optional. A request to join the chat has been sent. The bot must have the can_invite_users administra...
Definition: Update.hpp:86
Ptr< ShippingQuery > shippingQuery
Optional. New incoming shipping query. Only for invoices with flexible price.
Definition: Update.hpp:68
Ptr< PollAnswer > pollAnswer
Optional. A user changed their answer in a non-anonymous poll. Bots receive new votes only in polls t...
Definition: Update.hpp:77
Ptr< ChatMemberUpdated > chatMember
Optional. A chat member's status was updated in a chat. The bot must be an administrator in the chat ...
Definition: Update.hpp:83
Ptr< Message > editedChannelPost
Optional. New version of a channel post that is known to the bot and was edited.
Definition: Update.hpp:45
Ptr< ChatBoostRemoved > removedChatBoost
Optional. A boost was removed from a chat. The bot must be an administrator in the chat to receive th...
Definition: Update.hpp:92
void fromJson(const nl::json &json)
Deserializes this object from JSON.
Definition: Update.hpp:121
Ptr< Message > editedMessage
Optional. New version of a message that is known to the bot and was edited.
Definition: Update.hpp:39
Ptr< MessageReactionUpdated > messageReaction
Optional. A reaction to a message was changed by a user. The bot must be an administrator in the chat...
Definition: Update.hpp:50
Ptr< InlineQuery > inlineQuery
Optional. New incoming inline query.
Definition: Update.hpp:58
Ptr< PreCheckoutQuery > preCheckoutQuery
Optional. New incoming pre-checkout query. Contains full information about checkout.
Definition: Update.hpp:71
Ptr< ChatBoostUpdated > chatBoost
Optional. A chat boost was added or changed. The bot must be an administrator in the chat to receive ...
Definition: Update.hpp:89
Update(const nl::json &json)
Definition: Update.hpp:24
Ptr< CallbackQuery > callbackQuery
Optional. New incoming callback query.
Definition: Update.hpp:65
Ptr< Poll > poll
Optional. New poll state. Bots receive only updates about stopped polls and polls,...
Definition: Update.hpp:74
Ptr< ChosenInlineResult > chosenInlineResult
Optional. The result of an inline query that was chosen by a user and sent to their chat partner....
Definition: Update.hpp:62
std::int32_t updateId
The update's unique identifier. Update identifiers start from a certain positive number and increase ...
Definition: Update.hpp:33