tgbotxx 1.1.9.2
Telegram Bot C++ Library
Loading...
Searching...
No Matches
MessageOrigin.hpp
Go to the documentation of this file.
1#pragma once
5
6namespace tgbotxx {
14 MessageOrigin() = default;
15 explicit MessageOrigin(const nl::json& json) {
16 _fromJson(json);
17 }
18 virtual ~MessageOrigin() = default;
19
21 std::string type;
22
24 std::time_t date{};
25
28 virtual nl::json toJson() const {
29 nl::json json = nl::json::object();
30 OBJECT_SERIALIZE_FIELD(json, "type", type);
31 OBJECT_SERIALIZE_FIELD(json, "date", date);
32 return json;
33 }
34
36 virtual void fromJson(const nl::json& json) {
37 OBJECT_DESERIALIZE_FIELD(json, "type", type, "", false);
38 OBJECT_DESERIALIZE_FIELD(json, "date", date, 0, false);
39 }
40
41 private:
42 void _fromJson(const nl::json& json) {
43 fromJson(json);
44 }
45 };
46
53 explicit MessageOriginUser(const nl::json& json) : MessageOrigin(json) {
54 MessageOrigin::type = "user";
55 }
56
59
60 nl::json toJson() const override {
61 nl::json json = MessageOrigin::toJson();
62 OBJECT_SERIALIZE_FIELD_PTR(json, "sender_user", senderUser);
63 return json;
64 }
65
66 void fromJson(const nl::json& json) override {
68 OBJECT_DESERIALIZE_FIELD_PTR(json, "sender_user", senderUser, false);
69 }
70 };
71
72
77 MessageOrigin::type = "hidden_user";
78 }
79 explicit MessageOriginHiddenUser(const nl::json& json) : MessageOrigin(json) {
80 MessageOrigin::type = "hidden_user";
81 }
82
84 std::string senderUserName;
85
86 nl::json toJson() const override {
87 nl::json json = MessageOrigin::toJson();
88 OBJECT_SERIALIZE_FIELD(json, "sender_user_name", senderUserName);
89 return json;
90 }
91
92 void fromJson(const nl::json& json) override {
94 OBJECT_DESERIALIZE_FIELD(json, "sender_user_name", senderUserName, "", false);
95 }
96 };
97
98
103 MessageOrigin::type = "chat";
104 }
105 explicit MessageOriginChat(const nl::json& json) : MessageOrigin(json) {
106 MessageOrigin::type = "chat";
107 }
108
111
113 std::string authorSignature;
114
115 nl::json toJson() const override {
116 nl::json json = MessageOrigin::toJson();
117 OBJECT_SERIALIZE_FIELD_PTR(json, "sender_chat", senderChat);
118 OBJECT_SERIALIZE_FIELD(json, "author_signature", authorSignature);
119 return json;
120 }
121
122 void fromJson(const nl::json& json) override {
124 OBJECT_DESERIALIZE_FIELD_PTR(json, "sender_chat", senderChat, false);
125 OBJECT_DESERIALIZE_FIELD(json, "author_signature", authorSignature, "", true);
126 }
127 };
128
133 MessageOrigin::type = "channel";
134 }
135 explicit MessageOriginChannel(const nl::json& json) : MessageOrigin(json) {
136 MessageOrigin::type = "channel";
137 }
138
141
143 std::int32_t messageId{};
144
146 std::string authorSignature;
147
148 nl::json toJson() const override {
149 nl::json json = MessageOrigin::toJson();
150 OBJECT_SERIALIZE_FIELD_PTR(json, "chat", chat);
151 OBJECT_SERIALIZE_FIELD(json, "message_id", messageId);
152 OBJECT_SERIALIZE_FIELD(json, "author_signature", authorSignature);
153 return json;
154 }
155
156 void fromJson(const nl::json& json) override {
158 OBJECT_DESERIALIZE_FIELD_PTR(json, "chat", chat, false);
159 OBJECT_DESERIALIZE_FIELD(json, "message_id", messageId, 0, false);
160 OBJECT_DESERIALIZE_FIELD(json, "author_signature", authorSignature, "", true);
161 }
162 };
163}
#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:72
#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:46
std::shared_ptr< T > Ptr
Definition Ptr.hpp:6
The message was originally sent to a channel chat. https://core.telegram.org/bots/api#messageoriginch...
Ptr< Chat > chat
Channel chat to which the message was originally sent.
void fromJson(const nl::json &json) override
Deserializes this object from JSON.
std::string authorSignature
Optional. Signature of the original post author.
std::int32_t messageId
Unique message identifier inside the chat.
nl::json toJson() const override
Serializes this object to JSON.
MessageOriginChannel(const nl::json &json)
The message was originally sent on behalf of a chat to a group chat. https://core....
Ptr< Chat > senderChat
Chat that sent the message originally.
MessageOriginChat(const nl::json &json)
nl::json toJson() const override
Serializes this object to JSON.
void fromJson(const nl::json &json) override
Deserializes this object from JSON.
std::string authorSignature
Optional. For messages originally sent by an anonymous chat administrator, original message author si...
The message was originally sent by an unknown user. https://core.telegram.org/bots/api#messageoriginh...
nl::json toJson() const override
Serializes this object to JSON.
MessageOriginHiddenUser(const nl::json &json)
void fromJson(const nl::json &json) override
Deserializes this object from JSON.
std::string senderUserName
Name of the user that sent the message originally.
This object describes the origin of a message. It can be one of:
std::string type
Type of the message origin, one of "user", "hidden_user", "chat" or "channel".
std::time_t date
Date the message was sent originally in Unix time.
virtual ~MessageOrigin()=default
virtual void fromJson(const nl::json &json)
Deserializes this object from JSON.
virtual nl::json toJson() const
Serializes this object to JSON.
MessageOrigin(const nl::json &json)
The message was originally sent by a known user. https://core.telegram.org/bots/api#messageoriginuser...
nl::json toJson() const override
Serializes this object to JSON.
Ptr< User > senderUser
User that sent the message originally.
MessageOriginUser(const nl::json &json)
void fromJson(const nl::json &json) override
Deserializes this object from JSON.