tgbotxx 1.1.9.2
Telegram Bot C++ Library
Loading...
Searching...
No Matches
KeyboardButton.hpp
Go to the documentation of this file.
1#pragma once
7
8namespace tgbotxx {
14 KeyboardButton() = default;
15 explicit KeyboardButton(const nl::json& json) {
16 fromJson(json);
17 }
18
20 std::string text;
21
26
31
35
39
43
48
49
52 nl::json toJson() const {
53 nl::json json = nl::json::object();
54 OBJECT_SERIALIZE_FIELD(json, "text", text);
55 OBJECT_SERIALIZE_FIELD_PTR(json, "request_users", requestUsers);
56 OBJECT_SERIALIZE_FIELD_PTR(json, "request_chat", requestChat);
57 OBJECT_SERIALIZE_FIELD(json, "request_contact", requestContact);
58 OBJECT_SERIALIZE_FIELD(json, "request_location", requestLocation);
59 OBJECT_SERIALIZE_FIELD_PTR(json, "request_poll", requestPoll);
60 OBJECT_SERIALIZE_FIELD_PTR(json, "web_app", webApp);
61 return json;
62 }
63
65 void fromJson(const nl::json& json) {
66 OBJECT_DESERIALIZE_FIELD(json, "text", text, "", false);
67 OBJECT_DESERIALIZE_FIELD_PTR(json, "request_users", requestUsers, true);
68 OBJECT_DESERIALIZE_FIELD_PTR(json, "request_chat", requestChat, true);
69 OBJECT_DESERIALIZE_FIELD(json, "request_contact", requestContact, false, true);
70 OBJECT_DESERIALIZE_FIELD(json, "request_location", requestLocation, false, true);
71 OBJECT_DESERIALIZE_FIELD_PTR(json, "request_poll", requestPoll, true);
72 OBJECT_DESERIALIZE_FIELD_PTR(json, "web_app", webApp, true);
73 }
74 };
75}
#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(json, json_field, field, default_value, optional)
Deserialize.
Definition Object.hpp:46
std::shared_ptr< T > Ptr
Definition Ptr.hpp:6
This object represents one button of the reply keyboard. At most one of the optional fields must be u...
Ptr< KeyboardButtonPollType > requestPoll
Optional. If specified, the user will be asked to create a poll and send it to the bot when the butto...
std::string text
Text of the button. If none of the optional fields are used, it will be sent as a message when the bu...
bool requestContact
Optional. If True, the user's phone number will be sent as a contact when the button is pressed.
KeyboardButton(const nl::json &json)
bool requestLocation
Optional. If True, the user's current location will be sent when the button is pressed.
Ptr< WebAppInfo > webApp
Optional. If specified, the described Web App will be launched when the button is pressed....
void fromJson(const nl::json &json)
Deserializes this object from JSON.
Ptr< KeyboardButtonRequestChat > requestChat
Optional. If specified, pressing the button will open a list of suitable chats. Tapping on a chat wil...
nl::json toJson() const
Serializes this object to JSON.
Ptr< KeyboardButtonRequestUsers > requestUsers
Optional. If specified, pressing the button will open a list of suitable users. Tapping on any user w...