tgbotxx  1.1.6.9
Telegram Bot C++ Library
Poll.hpp
Go to the documentation of this file.
1 #pragma once
5 
6 namespace tgbotxx {
9  struct Poll {
10  Poll() = default;
11  explicit Poll(const nl::json& json) {
12  fromJson(json);
13  }
14 
16  std::string id;
17 
19  std::string question;
20 
22  std::vector<Ptr<PollOption>> options;
23 
25  std::int32_t totalVoterCount{};
26 
28  bool isClosed{};
29 
31  bool isAnonymous{};
32 
34  std::string type;
35 
38 
41  std::int32_t correctOptionId{};
42 
44  std::string explanation;
45 
47  std::vector<Ptr<MessageEntity>> explanationEntities;
48 
50  std::int32_t openPeriod{};
51 
53  std::time_t closeDate{};
54 
57  nl::json toJson() const {
58  nl::json json = nl::json::object();
59  OBJECT_SERIALIZE_FIELD(json, "id", id);
60  OBJECT_SERIALIZE_FIELD(json, "question", question);
61  OBJECT_SERIALIZE_FIELD_PTR_ARRAY(json, "options", options);
62  OBJECT_SERIALIZE_FIELD(json, "total_voter_count", totalVoterCount);
63  OBJECT_SERIALIZE_FIELD(json, "is_closed", isClosed);
64  OBJECT_SERIALIZE_FIELD(json, "is_anonymous", isAnonymous);
65  OBJECT_SERIALIZE_FIELD(json, "type", type);
66  OBJECT_SERIALIZE_FIELD(json, "allows_multiple_answers", allowsMultipleAnswers);
67  OBJECT_SERIALIZE_FIELD(json, "correct_option_id", correctOptionId);
68  OBJECT_SERIALIZE_FIELD(json, "explanation", explanation);
69  OBJECT_SERIALIZE_FIELD_PTR_ARRAY(json, "explanation_entities", explanationEntities);
70  OBJECT_SERIALIZE_FIELD(json, "open_period", openPeriod);
71  OBJECT_SERIALIZE_FIELD(json, "close_date", closeDate);
72  return json;
73  }
74 
76  void fromJson(const nl::json& json) {
77  OBJECT_DESERIALIZE_FIELD(json, "id", id, "", false);
78  OBJECT_DESERIALIZE_FIELD(json, "question", question, "", false);
79  OBJECT_DESERIALIZE_FIELD_PTR_ARRAY(json, "options", options, false);
80  OBJECT_DESERIALIZE_FIELD_PTR_ARRAY(json, "options", options, false);
81  OBJECT_DESERIALIZE_FIELD(json, "total_voter_count", totalVoterCount, 0, false);
82  OBJECT_DESERIALIZE_FIELD(json, "is_closed", isClosed, false, false);
83  OBJECT_DESERIALIZE_FIELD(json, "is_anonymous", isAnonymous, false, false);
84  OBJECT_DESERIALIZE_FIELD(json, "type", type, "", false);
85  OBJECT_DESERIALIZE_FIELD(json, "allows_multiple_answers", allowsMultipleAnswers, false, false);
86  OBJECT_DESERIALIZE_FIELD(json, "correct_option_id", correctOptionId, 0, true);
87  OBJECT_DESERIALIZE_FIELD(json, "explanation", explanation, "", true);
88  OBJECT_DESERIALIZE_FIELD_PTR_ARRAY(json, "explanation_entities", explanationEntities, true);
89  OBJECT_DESERIALIZE_FIELD(json, "open_period", openPeriod, 0, true);
90  OBJECT_DESERIALIZE_FIELD(json, "close_date", closeDate, 0, true);
91  }
92  };
93 }
#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:44
#define OBJECT_DESERIALIZE_FIELD_PTR_ARRAY(json, json_field, array_field, optional)
Definition: Object.hpp:87
Definition: Api.hpp:14
This object contains information about a poll. https://core.telegram.org/bots/api#poll.
Definition: Poll.hpp:9
std::string id
Unique poll identifier.
Definition: Poll.hpp:16
std::time_t closeDate
Optional. Point in time (Unix timestamp) when the poll will be automatically closed.
Definition: Poll.hpp:53
std::vector< Ptr< PollOption > > options
List of poll options.
Definition: Poll.hpp:22
Poll(const nl::json &json)
Definition: Poll.hpp:11
std::int32_t openPeriod
Optional. Amount of time in seconds the poll will be active after creation.
Definition: Poll.hpp:50
void fromJson(const nl::json &json)
Deserializes this object from JSON.
Definition: Poll.hpp:76
std::int32_t correctOptionId
Optional. 0-based identifier of the correct answer option. Available only for polls in the quiz mode,...
Definition: Poll.hpp:41
std::string type
Poll type, currently can be “regular” or “quiz”
Definition: Poll.hpp:34
Poll()=default
std::vector< Ptr< MessageEntity > > explanationEntities
Optional. Special entities like usernames, URLs, bot commands, etc. that appear in the explanation.
Definition: Poll.hpp:47
nl::json toJson() const
Serializes this object to JSON.
Definition: Poll.hpp:57
bool isAnonymous
True, if the poll is anonymous.
Definition: Poll.hpp:31
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:44
std::int32_t totalVoterCount
Total number of users that voted in the poll.
Definition: Poll.hpp:25
bool isClosed
True, if the poll is closed.
Definition: Poll.hpp:28
std::string question
Poll question, 1-300 characters.
Definition: Poll.hpp:19
bool allowsMultipleAnswers
True, if the poll allows multiple answers.
Definition: Poll.hpp:37