tgbotxx  1.1.6.9
Telegram Bot C++ Library
PollAnswer.hpp
Go to the documentation of this file.
1 #pragma once
5 
6 namespace tgbotxx {
9  struct PollAnswer {
10  PollAnswer() = default;
11  explicit PollAnswer(const nl::json& json) {
12  fromJson(json);
13  }
14 
16  std::string pollId;
17 
20 
23 
25  std::vector<std::int32_t> optionIds;
26 
27 
30  nl::json toJson() const {
31  nl::json json = nl::json::object();
32  OBJECT_SERIALIZE_FIELD(json, "poll_id", pollId);
33  OBJECT_SERIALIZE_FIELD_PTR(json, "voter_chat", voterChat);
34  OBJECT_SERIALIZE_FIELD_PTR(json, "user", user);
35  OBJECT_SERIALIZE_FIELD(json, "option_ids", optionIds);
36  return json;
37  }
38 
40  void fromJson(const nl::json& json) {
41  OBJECT_DESERIALIZE_FIELD(json, "poll_id", pollId, "", false);
42  OBJECT_DESERIALIZE_FIELD_PTR(json, "voter_chat", voterChat, true);
43  OBJECT_DESERIALIZE_FIELD_PTR(json, "user", user, true);
44  OBJECT_DESERIALIZE_FIELD(json, "option_ids", optionIds, std::vector<std::int32_t>(), false);
45  }
46  };
47 }
#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 answer of a user in a non-anonymous poll. https://core.telegram....
Definition: PollAnswer.hpp:9
nl::json toJson() const
Serializes this object to JSON.
Definition: PollAnswer.hpp:30
std::vector< std::int32_t > optionIds
0-based identifiers of chosen answer options. May be empty if the vote was retracted.
Definition: PollAnswer.hpp:25
Ptr< User > user
Optional. The user that changed the answer to the poll, if the voter isn't anonymous.
Definition: PollAnswer.hpp:22
PollAnswer(const nl::json &json)
Definition: PollAnswer.hpp:11
void fromJson(const nl::json &json)
Deserializes this object from JSON.
Definition: PollAnswer.hpp:40
Ptr< Chat > voterChat
Optional. The chat that changed the answer to the poll, if the voter is anonymous.
Definition: PollAnswer.hpp:19
std::string pollId
Unique poll identifier.
Definition: PollAnswer.hpp:16