From a9a3e7ba21c59e1a5669c3aaa046f96e68db1aab Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 21 Oct 2024 23:25:57 +0300 Subject: [PATCH] Support CopyText inline buttons. --- telegram-bot-api/Client.cpp | 26 +++++++++++++++++++++++++- telegram-bot-api/Client.h | 1 + 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 0070e5f..3a7e00d 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -2593,6 +2593,19 @@ class Client::JsonWebAppInfo final : public td::Jsonable { const td::string &url_; }; +class Client::JsonCopyTextButton final : public td::Jsonable { + public: + explicit JsonCopyTextButton(const td::string &text) : text_(text) { + } + void store(td::JsonValueScope *scope) const { + auto object = scope->enter_object(); + object("text", text_); + } + + private: + const td::string &text_; +}; + class Client::JsonInlineKeyboardButton final : public td::Jsonable { public: explicit JsonInlineKeyboardButton(const td_api::inlineKeyboardButton *button) : button_(button) { @@ -2664,8 +2677,11 @@ class Client::JsonInlineKeyboardButton final : public td::Jsonable { object("web_app", JsonWebAppInfo(type->url_)); break; } - case td_api::inlineKeyboardButtonTypeCopyText::ID: + case td_api::inlineKeyboardButtonTypeCopyText::ID: { + auto type = static_cast(button_->type_.get()); + object("copy_text", JsonCopyTextButton(type->text_)); break; + } default: UNREACHABLE(); break; @@ -7747,6 +7763,14 @@ td::Result> Client::get_inline_ return make_object(text, make_object(url)); } + if (object.has_field("copy_text")) { + TRY_RESULT(copy_text, object.extract_required_field("copy_text", td::JsonValue::Type::Object)); + auto ©_text_object = copy_text.get_object(); + TRY_RESULT(copied_text, copy_text_object.get_required_string_field("text")); + return make_object( + text, make_object(copied_text)); + } + return td::Status::Error(400, "Text buttons are unallowed in the inline keyboard"); } diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index 24176c4..59f7a78 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -135,6 +135,7 @@ class Client final : public WebhookActor::Callback { class JsonEntity; class JsonVectorEntities; class JsonWebAppInfo; + class JsonCopyTextButton; class JsonInlineKeyboardButton; class JsonInlineKeyboard; class JsonReplyMarkup;