1 // 2 // Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2021 3 // 4 // Distributed under the Boost Software License, Version 1.0. (See accompanying 5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) 6 // 7 #pragma once 8 9 #include "td/telegram/td_api.h" 10 #include "td/telegram/telegram_api.h" 11 #include "td/telegram/UserId.h" 12 13 #include "td/utils/common.h" 14 #include "td/utils/Status.h" 15 #include "td/utils/StringBuilder.h" 16 17 namespace td { 18 19 struct Dependencies; 20 21 struct KeyboardButton { 22 // append only 23 enum class Type : int32 { 24 Text, 25 RequestPhoneNumber, 26 RequestLocation, 27 RequestPoll, 28 RequestPollQuiz, 29 RequestPollRegular 30 }; 31 Type type; 32 string text; 33 }; 34 35 struct InlineKeyboardButton { 36 // append only 37 enum class Type : int32 { 38 Url, 39 Callback, 40 CallbackGame, 41 SwitchInline, 42 SwitchInlineCurrentDialog, 43 Buy, 44 UrlAuth, 45 CallbackWithPassword, 46 User 47 }; 48 Type type; 49 int64 id = 0; // UrlAuth only, button_id or (2 * request_write_access - 1) * bot_user_id 50 UserId user_id; // User only 51 string text; 52 string forward_text; // UrlAuth only 53 string data; 54 }; 55 56 struct ReplyMarkup { 57 // append only 58 enum class Type : int32 { InlineKeyboard, ShowKeyboard, RemoveKeyboard, ForceReply }; 59 Type type; 60 61 bool is_personal = false; // for ShowKeyboard, RemoveKeyboard, ForceReply 62 63 bool need_resize_keyboard = false; // for ShowKeyboard 64 bool is_one_time_keyboard = false; // for ShowKeyboard 65 vector<vector<KeyboardButton>> keyboard; // for ShowKeyboard 66 string placeholder; // for ShowKeyboard, ForceReply 67 68 vector<vector<InlineKeyboardButton>> inline_keyboard; // for InlineKeyboard 69 70 StringBuilder &print(StringBuilder &string_builder) const; 71 72 tl_object_ptr<telegram_api::ReplyMarkup> get_input_reply_markup() const; 73 74 tl_object_ptr<td_api::ReplyMarkup> get_reply_markup_object() const; 75 }; 76 77 bool operator==(const ReplyMarkup &lhs, const ReplyMarkup &rhs); 78 bool operator!=(const ReplyMarkup &lhs, const ReplyMarkup &rhs); 79 80 StringBuilder &operator<<(StringBuilder &string_builder, const ReplyMarkup &reply_markup); 81 82 unique_ptr<ReplyMarkup> get_reply_markup(tl_object_ptr<telegram_api::ReplyMarkup> &&reply_markup_ptr, bool is_bot, 83 bool only_inline_keyboard, bool message_contains_mention); 84 85 Result<unique_ptr<ReplyMarkup>> get_reply_markup(tl_object_ptr<td_api::ReplyMarkup> &&reply_markup_ptr, bool is_bot, 86 bool only_inline_keyboard, bool request_buttons_allowed, 87 bool switch_inline_buttons_allowed) TD_WARN_UNUSED_RESULT; 88 89 tl_object_ptr<telegram_api::ReplyMarkup> get_input_reply_markup(const unique_ptr<ReplyMarkup> &reply_markup); 90 91 tl_object_ptr<td_api::ReplyMarkup> get_reply_markup_object(const unique_ptr<ReplyMarkup> &reply_markup); 92 93 void add_reply_markup_dependencies(Dependencies &dependencies, const ReplyMarkup *reply_markup); 94 95 } // namespace td 96