tgbotxx 1.1.6.9
Telegram Bot C++ Library
Loading...
Searching...
No Matches
WebAppData.hpp
Go to the documentation of this file.
1#pragma once
3
4namespace tgbotxx {
7 struct WebAppData {
8 WebAppData() = default;
9 explicit WebAppData(const nl::json& json) {
10 fromJson(json);
11 }
12
14 std::string data;
15
18 std::string buttonText;
19
22 nl::json toJson() const {
23 nl::json json = nl::json::object();
24 OBJECT_SERIALIZE_FIELD(json, "data", data);
25 OBJECT_SERIALIZE_FIELD(json, "button_text", buttonText);
26 return json;
27 }
28
30 void fromJson(const nl::json& json) {
31 OBJECT_DESERIALIZE_FIELD(json, "data", data, "", false);
32 OBJECT_DESERIALIZE_FIELD(json, "button_text", buttonText, "", false);
33 }
34 };
35}
#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
Describes data sent from a Web App to the bot. https://core.telegram.org/bots/api#webappdata.
Definition WebAppData.hpp:7
void fromJson(const nl::json &json)
Deserializes this object from JSON.
std::string buttonText
Text of the web_app keyboard button from which the Web App was opened.
nl::json toJson() const
Serializes this object to JSON.
WebAppData(const nl::json &json)
Definition WebAppData.hpp:9
std::string data
The data. Be aware that a bad client can send arbitrary data in this field.