tgbotxx 1.2.9.5
Telegram Bot C++ Library
Loading...
Searching...
No Matches
InlineKeyboardButton.hpp
Go to the documentation of this file.
1#pragma once
8
9namespace tgbotxx {
15 explicit InlineKeyboardButton(const nl::json& json) {
17 }
18
20 std::string text;
21
25 std::string iconCustomEmojiId;
26
29 std::string style;
30
34 std::string url;
35
37 std::string callbackData;
38
43
47
52 std::string switchInlineQuery;
53
59
64
67
71
74 bool pay{};
75
78 nl::json toJson() const {
79 nl::json json = nl::json::object();
81 if (not iconCustomEmojiId.empty()) // @todo: this is a workaround. Seems to be the only field that makes telegram complain if its empty "" -> Bad Request: can't parse keyboard button: Field "icon_custom_emoji_id" must be a valid Number
82 OBJECT_SERIALIZE_FIELD(json, "icon_custom_emoji_id", iconCustomEmojiId);
85 OBJECT_SERIALIZE_FIELD(json, "callback_data", callbackData);
88 OBJECT_SERIALIZE_FIELD(json, "switch_inline_query", switchInlineQuery);
89 OBJECT_SERIALIZE_FIELD(json, "switch_inline_query_current_chat", switchInlineQueryCurrentChat);
90 OBJECT_SERIALIZE_FIELD_PTR(json, "switch_inline_query_chosen_chat", switchInlineQueryChosenChat);
94 return json;
95 }
96
98 void fromJson(const nl::json& json) {
99 OBJECT_DESERIALIZE_FIELD(json, "text", text, "", false);
100 OBJECT_DESERIALIZE_FIELD(json, "icon_custom_emoji_id", iconCustomEmojiId, "", true);
101 OBJECT_DESERIALIZE_FIELD(json, "style", style, "", true);
102 OBJECT_DESERIALIZE_FIELD(json, "url", url, "", true);
103 OBJECT_DESERIALIZE_FIELD(json, "callback_data", callbackData, "", true);
104 OBJECT_DESERIALIZE_FIELD_PTR(json, "web_app", webApp, true);
105 OBJECT_DESERIALIZE_FIELD_PTR(json, "login_url", loginUrl, true);
106 OBJECT_DESERIALIZE_FIELD(json, "switch_inline_query", switchInlineQuery, "", true);
107 OBJECT_DESERIALIZE_FIELD(json, "switch_inline_query_current_chat", switchInlineQueryCurrentChat, "", true);
108 OBJECT_DESERIALIZE_FIELD_PTR(json, "switch_inline_query_chosen_chat", switchInlineQueryChosenChat, true);
109 OBJECT_DESERIALIZE_FIELD_PTR(json, "copy_text", copyText, true);
110 OBJECT_DESERIALIZE_FIELD_PTR(json, "callback_game", callbackGame, true);
111 OBJECT_DESERIALIZE_FIELD(json, "pay", pay, false, true);
112 }
113 };
114
115}
#define OBJECT_SERIALIZE_FIELD_PTR(json, json_field, field)
Definition Object.hpp:32
#define OBJECT_DESERIALIZE_FIELD_PTR(json, json_field, field, optional)
Definition Object.hpp:92
#define OBJECT_SERIALIZE_FIELD(json, json_field, field)
Serialize.
Definition Object.hpp:27
#define OBJECT_DESERIALIZE_FIELD(json, json_field, field, default_value, optional)
Deserialize.
Definition Object.hpp:64
std::shared_ptr< T > Ptr
Definition Ptr.hpp:6
This object represents one button of an inline keyboard. Exactly one of the optional fields must be u...
InlineKeyboardButton(const nl::json &json)
std::string url
Optional. HTTP or tg:// URL to be opened when the button is pressed. Links tg://user?...
bool pay
Optional. Specify True, to send a Pay button. Substrings “⭐” and “XTR” in the buttons's text will be ...
void fromJson(const nl::json &json)
Deserializes this object from JSON.
Ptr< CallbackGame > callbackGame
Optional. Description of the game that will be launched when the user presses the button.
std::string callbackData
Optional. Data to be sent in a callback query to the bot when the button is pressed,...
std::string switchInlineQuery
Optional. If set, pressing the button will prompt the user to select one of their chats,...
Ptr< SwitchInlineQueryChosenChat > switchInlineQueryChosenChat
Optional. If set, pressing the button will prompt the user to select one of their chats of the specif...
Ptr< LoginUrl > loginUrl
Optional. An HTTPS URL used to automatically authorize the user. Can be used as a replacement for the...
nl::json toJson() const
Serializes this object to JSON.
std::string switchInlineQueryCurrentChat
Optional. If set, pressing the button will insert the bot's username and the specified inline query i...
std::string style
Optional. Style of the button. Must be one of “danger” (red), “success” (green) or “primary” (blue)....
Ptr< WebAppInfo > webApp
Optional. Description of the Web App that will be launched when the user presses the button....
std::string iconCustomEmojiId
Optional. Unique identifier of the custom emoji shown before the text of the button....
std::string text
Label text on the button.
Ptr< CopyTextButton > copyText
Optional. Description of the button that copies the specified text to the clipboard.