tgbotxx 1.1.6.9
Telegram Bot C++ Library
Loading...
Searching...
No Matches
MenuButton.hpp
Go to the documentation of this file.
1#pragma once
4
5namespace tgbotxx {
14 struct MenuButton {
15 MenuButton() = default;
16 explicit MenuButton(const nl::json& json) {
17 _fromJson(json);
18 }
19 virtual ~MenuButton() = default;
20
22 std::string type;
23
26 virtual nl::json toJson() const {
27 nl::json json = nl::json::object();
28 OBJECT_SERIALIZE_FIELD(json, "type", type);
29 return json;
30 }
31
33 virtual void fromJson(const nl::json& json) {
34 OBJECT_DESERIALIZE_FIELD(json, "type", type, "", false);
35 }
36
37 private:
38 void _fromJson(const nl::json& json) {
39 fromJson(json);
40 }
41 };
42
47 MenuButton::type = "default";
48 }
49 explicit MenuButtonDefault(const nl::json& json) : MenuButton(json) {
50 MenuButton::type = "default";
51 }
52 };
53
58 MenuButton::type = "web_app";
59 }
60 explicit MenuButtonWebApp(const nl::json& json) : MenuButton(json) {
61 MenuButton::type = "web_app";
62 }
63
65 std::string text;
66
70
71 nl::json toJson() const override {
72 nl::json json = MenuButton::toJson();
73 OBJECT_SERIALIZE_FIELD(json, "text", text);
74 OBJECT_SERIALIZE_FIELD_PTR(json, "web_app", webApp);
75 return json;
76 }
77
78 void fromJson(const nl::json& json) override {
80 OBJECT_DESERIALIZE_FIELD(json, "text", text, "", false);
81 OBJECT_DESERIALIZE_FIELD_PTR(json, "web_app", webApp, false);
82 }
83 };
84
89 MenuButton::type = "commands";
90 }
91 explicit MenuButtonCommands(const nl::json& json) : MenuButton(json) {
92 MenuButton::type = "commands";
93 }
94 };
95
96}
#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
Represents a menu button, which opens the bot's list of commands. https://core.telegram....
MenuButtonCommands(const nl::json &json)
Describes that no specific value for the menu button was set. https://core.telegram....
MenuButtonDefault(const nl::json &json)
This object describes the bot's menu button in a private chat. It should be one of:
virtual nl::json toJson() const
Serializes this object to JSON.
virtual void fromJson(const nl::json &json)
Deserializes this object from JSON.
std::string type
Type of the button.
MenuButton(const nl::json &json)
virtual ~MenuButton()=default
Represents a menu button, which launches a Web App. https://core.telegram.org/bots/webapps https://co...
std::string text
Text on the button.
Ptr< WebAppInfo > webApp
Description of the Web App that will be launched when the user presses the button....
MenuButtonWebApp(const nl::json &json)
void fromJson(const nl::json &json) override
Deserializes this object from JSON.
nl::json toJson() const override
Serializes this object to JSON.