tgbotxx 1.1.6.9
Telegram Bot C++ Library
Loading...
Searching...
No Matches
KeyboardButton.hpp
Go to the documentation of this file.
1#pragma once
7
8namespace tgbotxx {
18 KeyboardButton() = default;
19 explicit KeyboardButton(const nl::json& json) {
20 fromJson(json);
21 }
22
24 std::string text;
25
30
35
39
43
47
52
53
56 nl::json toJson() const {
57 nl::json json = nl::json::object();
58 OBJECT_SERIALIZE_FIELD(json, "text", text);
59 OBJECT_SERIALIZE_FIELD_PTR(json, "request_user", requestUser);
60 OBJECT_SERIALIZE_FIELD_PTR(json, "request_chat", requestChat);
61 OBJECT_SERIALIZE_FIELD(json, "request_contact", requestContact);
62 OBJECT_SERIALIZE_FIELD(json, "request_location", requestLocation);
63 OBJECT_SERIALIZE_FIELD_PTR(json, "request_poll", requestPoll);
64 OBJECT_SERIALIZE_FIELD_PTR(json, "web_app", webApp);
65 return json;
66 }
67
69 void fromJson(const nl::json& json) {
70 OBJECT_DESERIALIZE_FIELD(json, "text", text, "", false);
71 OBJECT_DESERIALIZE_FIELD_PTR(json, "request_user", requestUser, true);
72 OBJECT_DESERIALIZE_FIELD_PTR(json, "request_chat", requestChat, true);
73 OBJECT_DESERIALIZE_FIELD(json, "request_contact", requestContact, false, true);
74 OBJECT_DESERIALIZE_FIELD(json, "request_location", requestLocation, false, true);
75 OBJECT_DESERIALIZE_FIELD_PTR(json, "request_poll", requestPoll, true);
76 OBJECT_DESERIALIZE_FIELD_PTR(json, "web_app", webApp, true);
77 }
78 };
79}
#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
std::shared_ptr< T > Ptr
Definition Ptr.hpp:6
This object represents one button of the reply keyboard. For simple text buttons, String can be used ...
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...
Ptr< KeyboardButtonRequestUser > requestUser
Optional. If specified, pressing the button will open a list of suitable users. Tapping on any user w...
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.