tgbotxx 1.1.9.2
Telegram Bot C++ Library
Loading...
Searching...
No Matches
SuggestedPostInfo.hpp
Go to the documentation of this file.
1#pragma once
4
5namespace tgbotxx {
9 SuggestedPostInfo() = default;
10 explicit SuggestedPostInfo(const nl::json& json) {
11 fromJson(json);
12 }
13
15 enum class State : std::uint8_t {
16 Pending = 0,
19 };
21 static std::optional<std::string> StateToString(const State type) noexcept {
22 if (type == State::Pending) return "pending";
23 if (type == State::Approved) return "approved";
24 if (type == State::Declined) return "declined";
25 return std::nullopt;
26 }
28 static std::optional<State> StringToState(const std::string& str) noexcept {
29 if (str == "pending") return State::Pending;
30 if (str == "approved") return State::Approved;
31 if (str == "declined") return State::Declined;
32 return std::nullopt;
33 }
36
39
43 std::time_t sendDate{};
44
45
48 nl::json toJson() const {
49 nl::json json = nl::json::object();
51 OBJECT_SERIALIZE_FIELD_PTR(json, "price", price);
52 OBJECT_SERIALIZE_FIELD(json, "send_date", sendDate);
53 return json;
54 }
55
57 void fromJson(const nl::json& json) {
58 OBJECT_DESERIALIZE_FIELD_ENUM(json, State, "state", state, 0, false);
59 OBJECT_DESERIALIZE_FIELD_PTR(json, "price", price, true);
60 OBJECT_DESERIALIZE_FIELD(json, "send_date", sendDate, 0, true);
61 }
62 };
63}
#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_ENUM(json, enum_name, json_field, field, default_value, optional)
Definition Object.hpp:137
#define OBJECT_DESERIALIZE_FIELD(json, json_field, field, default_value, optional)
Deserialize.
Definition Object.hpp:46
#define OBJECT_SERIALIZE_FIELD_ENUM(json, enum_name, json_field, field)
Definition Object.hpp:42
std::shared_ptr< T > Ptr
Definition Ptr.hpp:6
Contains information about a suggested post. https://core.telegram.org/bots/api#suggestedpostinfo.
State state
State of the suggested post. Currently, it can be one of “pending”, “approved”, “declined”.
Ptr< SuggestedPostPrice > price
Optional. Proposed price of the post. If the field is omitted, then the post is unpaid.
static std::optional< State > StringToState(const std::string &str) noexcept
Converts string to an enum State.
nl::json toJson() const
Serializes this object to JSON.
SuggestedPostInfo(const nl::json &json)
State
Enum of possible types of State.
@ Pending
@ Declined
@ Approved
static std::optional< std::string > StateToString(const State type) noexcept
Converts enum State to a string.
void fromJson(const nl::json &json)
Deserializes this object from JSON.
SuggestedPostInfo()=default
std::time_t sendDate
Optional. Proposed send date of the post. If the field is omitted, then the post can be published at ...