tgbotxx 1.1.9.2
Telegram Bot C++ Library
Loading...
Searching...
No Matches
Poll.hpp
Go to the documentation of this file.
1#pragma once
6
7namespace tgbotxx {
10 struct Poll {
11 Poll() = default;
12 explicit Poll(const nl::json& json) {
13 fromJson(json);
14 }
15
17 std::string id;
18
20 std::string question;
21
23 std::vector<Ptr<MessageEntity>> questionEntities;
24
26 std::vector<Ptr<PollOption>> options;
27
29 std::int32_t totalVoterCount{};
30
32 bool isClosed{};
33
36
38 std::string type;
39
42
45 std::int32_t correctOptionId{};
46
48 std::string explanation;
49
51 std::vector<Ptr<MessageEntity>> explanationEntities;
52
54 std::int32_t openPeriod{};
55
57 std::time_t closeDate{};
58
61 nl::json toJson() const {
62 nl::json json = nl::json::object();
63 OBJECT_SERIALIZE_FIELD(json, "id", id);
64 OBJECT_SERIALIZE_FIELD(json, "question", question);
65 OBJECT_SERIALIZE_FIELD_PTR_ARRAY(json, "question_entities", questionEntities);
67 OBJECT_SERIALIZE_FIELD(json, "total_voter_count", totalVoterCount);
68 OBJECT_SERIALIZE_FIELD(json, "is_closed", isClosed);
69 OBJECT_SERIALIZE_FIELD(json, "is_anonymous", isAnonymous);
70 OBJECT_SERIALIZE_FIELD(json, "type", type);
71 OBJECT_SERIALIZE_FIELD(json, "allows_multiple_answers", allowsMultipleAnswers);
72 OBJECT_SERIALIZE_FIELD(json, "correct_option_id", correctOptionId);
73 OBJECT_SERIALIZE_FIELD(json, "explanation", explanation);
74 OBJECT_SERIALIZE_FIELD_PTR_ARRAY(json, "explanation_entities", explanationEntities);
75 OBJECT_SERIALIZE_FIELD(json, "open_period", openPeriod);
76 OBJECT_SERIALIZE_FIELD(json, "close_date", closeDate);
77 return json;
78 }
79
81 void fromJson(const nl::json& json) {
82 OBJECT_DESERIALIZE_FIELD(json, "id", id, "", false);
83 OBJECT_DESERIALIZE_FIELD(json, "question", question, "", false);
84 OBJECT_DESERIALIZE_FIELD_PTR_ARRAY(json, "question_entities", questionEntities, true);
85 OBJECT_DESERIALIZE_FIELD_PTR_ARRAY(json, "options", options, false);
86 OBJECT_DESERIALIZE_FIELD(json, "total_voter_count", totalVoterCount, 0, false);
87 OBJECT_DESERIALIZE_FIELD(json, "is_closed", isClosed, false, false);
88 OBJECT_DESERIALIZE_FIELD(json, "is_anonymous", isAnonymous, false, false);
89 OBJECT_DESERIALIZE_FIELD(json, "type", type, "", false);
90 OBJECT_DESERIALIZE_FIELD(json, "allows_multiple_answers", allowsMultipleAnswers, false, false);
91 OBJECT_DESERIALIZE_FIELD(json, "correct_option_id", correctOptionId, 0, true);
92 OBJECT_DESERIALIZE_FIELD(json, "explanation", explanation, "", true);
93 OBJECT_DESERIALIZE_FIELD_PTR_ARRAY(json, "explanation_entities", explanationEntities, true);
94 OBJECT_DESERIALIZE_FIELD(json, "open_period", openPeriod, 0, true);
95 OBJECT_DESERIALIZE_FIELD(json, "close_date", closeDate, 0, true);
96 }
97 };
98}
#define OBJECT_SERIALIZE_FIELD_PTR_ARRAY(json, json_field, array_field)
Definition Object.hpp:27
#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
#define OBJECT_DESERIALIZE_FIELD_PTR_ARRAY(json, json_field, array_field, optional)
Definition Object.hpp:89
This object contains information about a poll. https://core.telegram.org/bots/api#poll.
Definition Poll.hpp:10
std::vector< Ptr< MessageEntity > > questionEntities
Optional. Special entities that appear in the question. Currently, only custom emoji entities are all...
Definition Poll.hpp:23
std::string id
Unique poll identifier.
Definition Poll.hpp:17
std::time_t closeDate
Optional. Point in time (Unix timestamp) when the poll will be automatically closed.
Definition Poll.hpp:57
std::vector< Ptr< PollOption > > options
List of poll options.
Definition Poll.hpp:26
Poll(const nl::json &json)
Definition Poll.hpp:12
std::int32_t openPeriod
Optional. Amount of time in seconds the poll will be active after creation.
Definition Poll.hpp:54
void fromJson(const nl::json &json)
Deserializes this object from JSON.
Definition Poll.hpp:81
std::int32_t correctOptionId
Optional. 0-based identifier of the correct answer option. Available only for polls in the quiz mode,...
Definition Poll.hpp:45
std::string type
Poll type, currently can be “regular” or “quiz”
Definition Poll.hpp:38
Poll()=default
std::vector< Ptr< MessageEntity > > explanationEntities
Optional. Special entities like usernames, URLs, bot commands, etc. that appear in the explanation.
Definition Poll.hpp:51
nl::json toJson() const
Serializes this object to JSON.
Definition Poll.hpp:61
bool isAnonymous
True, if the poll is anonymous.
Definition Poll.hpp:35
std::string explanation
Optional. Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a qu...
Definition Poll.hpp:48
std::int32_t totalVoterCount
Total number of users that voted in the poll.
Definition Poll.hpp:29
bool isClosed
True, if the poll is closed.
Definition Poll.hpp:32
std::string question
Poll question, 1-300 characters.
Definition Poll.hpp:20
bool allowsMultipleAnswers
True, if the poll allows multiple answers.
Definition Poll.hpp:41