From 9bf5786bde99b4b2a18fc60d6316fdeaaf7ae6a3 Mon Sep 17 00:00:00 2001 From: levlam Date: Sun, 12 Mar 2023 22:39:48 +0300 Subject: [PATCH 01/15] Statically link libstdc++ and libgcc when memprof is enabled. --- CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2a1928a..bb69849 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,6 +73,9 @@ if (CLANG OR GCC) elseif (APPLE) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-no_pie") endif() + include(AddCXXCompilerFlag) + add_cxx_compiler_flag("-static-libstdc++") + add_cxx_compiler_flag("-static-libgcc") endif() endif() From 03bc114f939f9ab958877427fb7c8eda4bcccd96 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 13 Mar 2023 17:28:01 +0300 Subject: [PATCH 02/15] Update TDLib to 1.8.13. --- td | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/td b/td index 6c53a61..eb664b4 160000 --- a/td +++ b/td @@ -1 +1 @@ -Subproject commit 6c53a61162e6ea4a753869ee248b8a9e926ffd5d +Subproject commit eb664b4e9f71945ef3faa802af779e1630fedb8f From 26854a6a3dfd677bbbd3a4f0462519fb79829b2a Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 13 Mar 2023 17:40:07 +0300 Subject: [PATCH 03/15] Completely disable network statistics. --- telegram-bot-api/Client.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 75dd162..ea9d03c 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -4891,9 +4891,9 @@ void Client::on_update_authorization_state() { send_request(make_object("reuse_uploaded_photos_by_hash", make_object(true)), td::make_unique()); - send_request(make_object("disable_persistent_network_statistics", - make_object(true)), - td::make_unique()); + send_request( + make_object("disable_network_statistics", make_object(true)), + td::make_unique()); send_request(make_object("disable_time_adjustment_protection", make_object(true)), td::make_unique()); From e9d32ad23d8b1bf65b468045f5ed3252596ae54e Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 13 Mar 2023 18:42:35 +0300 Subject: [PATCH 04/15] Add Query::get_peer_ip_address. --- telegram-bot-api/Client.cpp | 7 ++++--- telegram-bot-api/ClientManager.cpp | 10 ++-------- telegram-bot-api/Query.cpp | 13 +++++++++++-- telegram-bot-api/Query.h | 8 +++----- 4 files changed, 20 insertions(+), 18 deletions(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index ea9d03c..4462120 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -41,7 +41,7 @@ using td_api::move_object_as; int Client::get_retry_after_time(td::Slice error_message) { td::Slice prefix = "Too Many Requests: retry after "; - if (begins_with(error_message, prefix)) { + if (td::begins_with(error_message, prefix)) { auto r_retry_after = td::to_integer_safe(error_message.substr(prefix.size())); if (r_retry_after.is_ok() && r_retry_after.ok() > 0) { return r_retry_after.ok(); @@ -154,7 +154,7 @@ void Client::fail_query_with_error(PromisedQueryPtr query, int32 error_code, td: return fail_query(400, PSLICE() << "Bad Request: " << error_message, std::move(query)); } - if (begins_with(error_message, prefix)) { + if (td::begins_with(error_message, prefix)) { return fail_query(error_code, error_message, std::move(query)); } else { td::string error_str = prefix.str(); @@ -10168,7 +10168,8 @@ void Client::do_get_updates(int32 offset, int32 limit, int32 timeout, PromisedQu if (need_warning && previous_get_updates_finish_time_ > 0) { LOG(WARNING) << "Found " << updates.size() << " updates out of " << (total_size + updates.size()) << " after last getUpdates call " << (query->start_timestamp() - previous_get_updates_finish_time_) - << " seconds ago in " << (td::Time::now() - query->start_timestamp()) << " seconds"; + << " seconds ago in " << (td::Time::now() - query->start_timestamp()) << " seconds from " + << query->get_peer_ip_address(); } else { LOG(DEBUG) << "Found " << updates.size() << " updates out of " << total_size << " from " << from; } diff --git a/telegram-bot-api/ClientManager.cpp b/telegram-bot-api/ClientManager.cpp index da4d637..210d215 100644 --- a/telegram-bot-api/ClientManager.cpp +++ b/telegram-bot-api/ClientManager.cpp @@ -90,13 +90,7 @@ void ClientManager::send(PromisedQueryPtr query) { auto id_it = token_to_id_.find(token); if (id_it == token_to_id_.end()) { - td::string ip_address; - if (query->peer_address().is_valid() && !query->peer_address().is_reserved()) { // external connection - ip_address = query->peer_address().get_ip_str().str(); - } else { - // invalid peer address or connection from the local network - ip_address = query->get_header("x-real-ip").str(); - } + td::string ip_address = query->get_peer_ip_address(); if (!ip_address.empty()) { td::IPAddress tmp; tmp.init_host_port(ip_address, 0).ignore(); @@ -105,7 +99,7 @@ void ClientManager::send(PromisedQueryPtr query) { ip_address = tmp.get_ip_str().str(); } } - LOG(DEBUG) << "Receive incoming query for new bot " << token << " from " << query->peer_address(); + LOG(DEBUG) << "Receive incoming query for new bot " << token << " from " << ip_address; if (!ip_address.empty()) { LOG(DEBUG) << "Check Client creation flood control for IP address " << ip_address; auto res = flood_controls_.emplace(std::move(ip_address), td::FloodControlFast()); diff --git a/telegram-bot-api/Query.cpp b/telegram-bot-api/Query.cpp index 3478e04..4162f8a 100644 --- a/telegram-bot-api/Query.cpp +++ b/telegram-bot-api/Query.cpp @@ -26,10 +26,10 @@ td::FlatHashMap> empty_paramet Query::Query(td::vector &&container, td::Slice token, bool is_test_dc, td::MutableSlice method, td::vector> &&args, td::vector> &&headers, td::vector &&files, - std::shared_ptr shared_data, const td::IPAddress &peer_address, bool is_internal) + std::shared_ptr shared_data, const td::IPAddress &peer_ip_address, bool is_internal) : state_(State::Query) , shared_data_(shared_data) - , peer_address_(peer_address) + , peer_ip_address_(peer_ip_address) , container_(std::move(container)) , token_(token) , is_test_dc_(is_test_dc) @@ -53,6 +53,15 @@ Query::Query(td::vector &&container, td::Slice token, bool is_t } } +td::string Query::get_peer_ip_address() const { + if (peer_ip_address_.is_valid() && !peer_ip_address_.is_reserved()) { // external connection + return peer_ip_address_.get_ip_str().str(); + } else { + // invalid peer IP address or connection from the local network + return get_header("x-real-ip").str(); + } +} + td::int64 Query::query_size() const { return std::accumulate( container_.begin(), container_.end(), td::int64{0}, diff --git a/telegram-bot-api/Query.h b/telegram-bot-api/Query.h index 66c8e55..0b7b51e 100644 --- a/telegram-bot-api/Query.h +++ b/telegram-bot-api/Query.h @@ -70,9 +70,7 @@ class Query final : public td::ListNode { return files_; } - const td::IPAddress &peer_address() const { - return peer_address_; - } + td::string get_peer_ip_address() const; td::BufferSlice &answer() { return answer_; @@ -103,7 +101,7 @@ class Query final : public td::ListNode { Query(td::vector &&container, td::Slice token, bool is_test_dc, td::MutableSlice method, td::vector> &&args, td::vector> &&headers, td::vector &&files, - std::shared_ptr shared_data, const td::IPAddress &peer_address, bool is_internal); + std::shared_ptr shared_data, const td::IPAddress &peer_ip_address, bool is_internal); Query(const Query &) = delete; Query &operator=(const Query &) = delete; Query(Query &&) = delete; @@ -129,7 +127,7 @@ class Query final : public td::ListNode { State state_; std::shared_ptr shared_data_; double start_timestamp_; - td::IPAddress peer_address_; + td::IPAddress peer_ip_address_; td::ActorId stat_actor_; // request From 10c52724975d9fa8f6955463b5456e4e14f415b9 Mon Sep 17 00:00:00 2001 From: levlam Date: Thu, 23 Mar 2023 20:18:32 +0300 Subject: [PATCH 05/15] Fix warning. --- telegram-bot-api/WebhookActor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telegram-bot-api/WebhookActor.cpp b/telegram-bot-api/WebhookActor.cpp index 9c67bb3..2033a68 100644 --- a/telegram-bot-api/WebhookActor.cpp +++ b/telegram-bot-api/WebhookActor.cpp @@ -207,7 +207,7 @@ td::Status WebhookActor::create_webhook_error(td::Slice error_message, td::Statu on_webhook_error(error_message); } on_error(std::move(result)); - return std::move(error); + return error; } td::Result WebhookActor::create_ssl_stream() { From 8e00a8d41d531866fa30f98064d81299fe639751 Mon Sep 17 00:00:00 2001 From: levlam Date: Sat, 25 Mar 2023 09:27:17 +0300 Subject: [PATCH 06/15] Update version to 6.6.1. --- CMakeLists.txt | 2 +- telegram-bot-api/telegram-bot-api.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bb69849..545659f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ if (POLICY CMP0065) cmake_policy(SET CMP0065 NEW) endif() -project(TelegramBotApi VERSION 6.6 LANGUAGES CXX) +project(TelegramBotApi VERSION 6.6.1 LANGUAGES CXX) if (POLICY CMP0069) option(TELEGRAM_BOT_API_ENABLE_LTO "Use \"ON\" to enable Link Time Optimization.") diff --git a/telegram-bot-api/telegram-bot-api.cpp b/telegram-bot-api/telegram-bot-api.cpp index c91c6aa..60dd428 100644 --- a/telegram-bot-api/telegram-bot-api.cpp +++ b/telegram-bot-api/telegram-bot-api.cpp @@ -165,7 +165,7 @@ int main(int argc, char *argv[]) { auto start_time = td::Time::now(); auto shared_data = std::make_shared(); auto parameters = std::make_unique(); - parameters->version_ = "6.6"; + parameters->version_ = "6.6.1"; parameters->shared_data_ = shared_data; parameters->start_time_ = start_time; auto net_query_stats = td::create_net_query_stats(); From df53cfeb85152b88ce4317b6478fcd59c8813c65 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 27 Mar 2023 12:08:49 +0300 Subject: [PATCH 07/15] Update TDLib and version to 6.6.2. --- CMakeLists.txt | 2 +- td | 2 +- telegram-bot-api/telegram-bot-api.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 545659f..5b75633 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ if (POLICY CMP0065) cmake_policy(SET CMP0065 NEW) endif() -project(TelegramBotApi VERSION 6.6.1 LANGUAGES CXX) +project(TelegramBotApi VERSION 6.6.2 LANGUAGES CXX) if (POLICY CMP0069) option(TELEGRAM_BOT_API_ENABLE_LTO "Use \"ON\" to enable Link Time Optimization.") diff --git a/td b/td index eb664b4..c95598e 160000 --- a/td +++ b/td @@ -1 +1 @@ -Subproject commit eb664b4e9f71945ef3faa802af779e1630fedb8f +Subproject commit c95598e5e1493881d31211c1329bdbe4630f6136 diff --git a/telegram-bot-api/telegram-bot-api.cpp b/telegram-bot-api/telegram-bot-api.cpp index 60dd428..4c478c8 100644 --- a/telegram-bot-api/telegram-bot-api.cpp +++ b/telegram-bot-api/telegram-bot-api.cpp @@ -165,7 +165,7 @@ int main(int argc, char *argv[]) { auto start_time = td::Time::now(); auto shared_data = std::make_shared(); auto parameters = std::make_unique(); - parameters->version_ = "6.6.1"; + parameters->version_ = "6.6.2"; parameters->shared_data_ = shared_data; parameters->start_time_ = start_time; auto net_query_stats = td::create_net_query_stats(); From 0e5673f2dce75805d96d3cb225414e7aef1b7d63 Mon Sep 17 00:00:00 2001 From: levlam Date: Mon, 27 Mar 2023 19:05:23 +0300 Subject: [PATCH 08/15] Don't dump trace on Watchdog timeouts if log is disabled. --- telegram-bot-api/Watchdog.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/telegram-bot-api/Watchdog.cpp b/telegram-bot-api/Watchdog.cpp index 1bb15e6..9b5c88d 100644 --- a/telegram-bot-api/Watchdog.cpp +++ b/telegram-bot-api/Watchdog.cpp @@ -13,7 +13,7 @@ namespace telegram_bot_api { void Watchdog::kick() { auto now = td::Time::now(); - if (now >= last_kick_time_ + timeout_ && last_kick_time_ > 0) { + if (now >= last_kick_time_ + timeout_ && last_kick_time_ > 0 && GET_VERBOSITY_LEVEL() >= VERBOSITY_NAME(ERROR)) { LOG(ERROR) << get_name() << " timeout expired after " << now - last_kick_time_ << " seconds"; td::thread::send_real_time_signal(main_thread_id_, 2); } From 6561063f52a073355bb2577547d1fa4b8d34e23c Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 7 Apr 2023 14:36:27 +0300 Subject: [PATCH 09/15] Update TDLib to 1.8.14. --- td | 2 +- telegram-bot-api/Client.cpp | 34 +++++++++++++++++++++++----------- 2 files changed, 24 insertions(+), 12 deletions(-) diff --git a/td b/td index c95598e..8517026 160000 --- a/td +++ b/td @@ -1 +1 @@ -Subproject commit c95598e5e1493881d31211c1329bdbe4630f6136 +Subproject commit 8517026415e75a8eec567774072cbbbbb52376c1 diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 4462120..a6fd85a 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -1826,10 +1826,15 @@ class Client::JsonInlineKeyboardButton final : public td::Jsonable { break; case td_api::inlineKeyboardButtonTypeSwitchInline::ID: { auto type = static_cast(button_->type_.get()); - if (type->in_current_chat_) { - object("switch_inline_query_current_chat", type->query_); - } else { - object("switch_inline_query", type->query_); + switch (type->target_chat_->get_id()) { + case td_api::targetChatCurrent::ID: + object("switch_inline_query_current_chat", type->query_); + break; + case td_api::targetChatChosen::ID: + object("switch_inline_query", type->query_); + break; + default: + UNREACHABLE(); } break; } @@ -2266,6 +2271,8 @@ void Client::JsonMessage::store(td::JsonValueScope *scope) const { object("chat_shared", JsonChatShared(content)); break; } + case td_api::messageChatSetBackground::ID: + break; default: UNREACHABLE(); } @@ -5564,13 +5571,15 @@ td::Result> Client::get_inline_ if (has_json_object_field(object, "switch_inline_query")) { TRY_RESULT(switch_inline_query, get_json_object_string_field(object, "switch_inline_query", false)); return make_object( - text, make_object(switch_inline_query, false)); + text, make_object( + switch_inline_query, td_api::make_object(true, true, true, true))); } if (has_json_object_field(object, "switch_inline_query_current_chat")) { TRY_RESULT(switch_inline_query, get_json_object_string_field(object, "switch_inline_query_current_chat", false)); return make_object( - text, make_object(switch_inline_query, true)); + text, make_object( + switch_inline_query, td_api::make_object())); } if (has_json_object_field(object, "login_url")) { @@ -7864,7 +7873,7 @@ td::Status Client::process_set_my_default_administrator_rights_query(PromisedQue td::Status Client::process_get_my_description_query(PromisedQueryPtr &query) { auto language_code = query->arg("language_code"); - send_request(make_object(language_code.str()), + send_request(make_object(my_id_, language_code.str()), td::make_unique(std::move(query))); return td::Status::OK(); } @@ -7872,14 +7881,14 @@ td::Status Client::process_get_my_description_query(PromisedQueryPtr &query) { td::Status Client::process_set_my_description_query(PromisedQueryPtr &query) { auto language_code = query->arg("language_code"); auto description = query->arg("description"); - send_request(make_object(language_code.str(), description.str()), + send_request(make_object(my_id_, language_code.str(), description.str()), td::make_unique(std::move(query))); return td::Status::OK(); } td::Status Client::process_get_my_short_description_query(PromisedQueryPtr &query) { auto language_code = query->arg("language_code"); - send_request(make_object(language_code.str()), + send_request(make_object(my_id_, language_code.str()), td::make_unique(std::move(query))); return td::Status::OK(); } @@ -7887,7 +7896,7 @@ td::Status Client::process_get_my_short_description_query(PromisedQueryPtr &quer td::Status Client::process_set_my_short_description_query(PromisedQueryPtr &query) { auto language_code = query->arg("language_code"); auto short_description = query->arg("short_description"); - send_request(make_object(language_code.str(), short_description.str()), + send_request(make_object(my_id_, language_code.str(), short_description.str()), td::make_unique(std::move(query))); return td::Status::OK(); } @@ -11047,6 +11056,8 @@ bool Client::need_skip_update_message(int64 chat_id, const object_ptr(lhs->type_.get()); auto rhs_type = static_cast(rhs->type_.get()); - return lhs_type->query_ == rhs_type->query_ && lhs_type->in_current_chat_ == rhs_type->in_current_chat_; + return lhs_type->query_ == rhs_type->query_ && + to_string(lhs_type->target_chat_) == to_string(rhs_type->target_chat_); } case td_api::inlineKeyboardButtonTypeBuy::ID: return true; From a894cace6b34b33eb486dc44ac75755de514380d Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 7 Apr 2023 14:48:34 +0300 Subject: [PATCH 10/15] Add getMyName. --- telegram-bot-api/Client.cpp | 40 +++++++++++++++++++++++++++++++++++++ telegram-bot-api/Client.h | 3 +++ 2 files changed, 43 insertions(+) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index a6fd85a..25fff05 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -205,6 +205,7 @@ bool Client::init_methods() { methods_.emplace("deletemycommands", &Client::process_delete_my_commands_query); methods_.emplace("getmydefaultadministratorrights", &Client::process_get_my_default_administrator_rights_query); methods_.emplace("setmydefaultadministratorrights", &Client::process_set_my_default_administrator_rights_query); + methods_.emplace("getmyname", &Client::process_get_my_name_query); methods_.emplace("getmydescription", &Client::process_get_my_description_query); methods_.emplace("setmydescription", &Client::process_set_my_description_query); methods_.emplace("getmyshortdescription", &Client::process_get_my_short_description_query); @@ -2591,6 +2592,19 @@ class Client::JsonBotMenuButton final : public td::Jsonable { const td_api::botMenuButton *menu_button_; }; +class Client::JsonBotName final : public td::Jsonable { + public: + explicit JsonBotName(const td_api::text *text) : text_(text) { + } + void store(td::JsonValueScope *scope) const { + auto object = scope->enter_object(); + object("name", text_->text_); + } + + private: + const td_api::text *text_; +}; + class Client::JsonBotInfoDescription final : public td::Jsonable { public: explicit JsonBotInfoDescription(const td_api::text *text) : text_(text) { @@ -3757,6 +3771,25 @@ class Client::TdOnGetMyDefaultAdministratorRightsCallback final : public TdQuery PromisedQueryPtr query_; }; +class Client::TdOnGetMyNameCallback final : public TdQueryCallback { + public: + explicit TdOnGetMyNameCallback(PromisedQueryPtr query) : query_(std::move(query)) { + } + + void on_result(object_ptr result) final { + if (result->get_id() == td_api::error::ID) { + return fail_query_with_error(std::move(query_), move_object_as(result)); + } + + CHECK(result->get_id() == td_api::text::ID); + auto text = move_object_as(result); + answer_query(JsonBotName(text.get()), std::move(query_)); + } + + private: + PromisedQueryPtr query_; +}; + class Client::TdOnGetMyDescriptionCallback final : public TdQueryCallback { public: explicit TdOnGetMyDescriptionCallback(PromisedQueryPtr query) : query_(std::move(query)) { @@ -7871,6 +7904,13 @@ td::Status Client::process_set_my_default_administrator_rights_query(PromisedQue return td::Status::OK(); } +td::Status Client::process_get_my_name_query(PromisedQueryPtr &query) { + auto language_code = query->arg("language_code"); + send_request(make_object(my_id_, language_code.str()), + td::make_unique(std::move(query))); + return td::Status::OK(); +} + td::Status Client::process_get_my_description_query(PromisedQueryPtr &query) { auto language_code = query->arg("language_code"); send_request(make_object(my_id_, language_code.str()), diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index 3beb6db..f7ba078 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -137,6 +137,7 @@ class Client final : public WebhookActor::Callback { class JsonPreCheckoutQuery; class JsonBotCommand; class JsonBotMenuButton; + class JsonBotName; class JsonBotInfoDescription; class JsonBotInfoShortDescription; class JsonChatAdministratorRights; @@ -189,6 +190,7 @@ class Client final : public WebhookActor::Callback { class TdOnGetMenuButtonCallback; class TdOnGetMyCommandsCallback; class TdOnGetMyDefaultAdministratorRightsCallback; + class TdOnGetMyNameCallback; class TdOnGetMyDescriptionCallback; class TdOnGetMyShortDescriptionCallback; class TdOnGetChatFullInfoCallback; @@ -509,6 +511,7 @@ class Client final : public WebhookActor::Callback { td::Status process_delete_my_commands_query(PromisedQueryPtr &query); td::Status process_get_my_default_administrator_rights_query(PromisedQueryPtr &query); td::Status process_set_my_default_administrator_rights_query(PromisedQueryPtr &query); + td::Status process_get_my_name_query(PromisedQueryPtr &query); td::Status process_get_my_description_query(PromisedQueryPtr &query); td::Status process_set_my_description_query(PromisedQueryPtr &query); td::Status process_get_my_short_description_query(PromisedQueryPtr &query); From 38a11d1e1f4b8931b3569b6c45e759128d7300e4 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 7 Apr 2023 14:52:10 +0300 Subject: [PATCH 11/15] Add setMyName. --- telegram-bot-api/Client.cpp | 9 +++++++++ telegram-bot-api/Client.h | 1 + 2 files changed, 10 insertions(+) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index 25fff05..b55ca6b 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -206,6 +206,7 @@ bool Client::init_methods() { methods_.emplace("getmydefaultadministratorrights", &Client::process_get_my_default_administrator_rights_query); methods_.emplace("setmydefaultadministratorrights", &Client::process_set_my_default_administrator_rights_query); methods_.emplace("getmyname", &Client::process_get_my_name_query); + methods_.emplace("setmyname", &Client::process_set_my_name_query); methods_.emplace("getmydescription", &Client::process_get_my_description_query); methods_.emplace("setmydescription", &Client::process_set_my_description_query); methods_.emplace("getmyshortdescription", &Client::process_get_my_short_description_query); @@ -7911,6 +7912,14 @@ td::Status Client::process_get_my_name_query(PromisedQueryPtr &query) { return td::Status::OK(); } +td::Status Client::process_set_my_name_query(PromisedQueryPtr &query) { + auto language_code = query->arg("language_code"); + auto name = query->arg("name"); + send_request(make_object(my_id_, language_code.str(), name.str()), + td::make_unique(std::move(query))); + return td::Status::OK(); +} + td::Status Client::process_get_my_description_query(PromisedQueryPtr &query) { auto language_code = query->arg("language_code"); send_request(make_object(my_id_, language_code.str()), diff --git a/telegram-bot-api/Client.h b/telegram-bot-api/Client.h index f7ba078..d0abc78 100644 --- a/telegram-bot-api/Client.h +++ b/telegram-bot-api/Client.h @@ -512,6 +512,7 @@ class Client final : public WebhookActor::Callback { td::Status process_get_my_default_administrator_rights_query(PromisedQueryPtr &query); td::Status process_set_my_default_administrator_rights_query(PromisedQueryPtr &query); td::Status process_get_my_name_query(PromisedQueryPtr &query); + td::Status process_set_my_name_query(PromisedQueryPtr &query); td::Status process_get_my_description_query(PromisedQueryPtr &query); td::Status process_set_my_description_query(PromisedQueryPtr &query); td::Status process_get_my_short_description_query(PromisedQueryPtr &query); From 9e87ac2bf946ccf246fd2bb444c37284e07e2b8d Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 7 Apr 2023 14:55:58 +0300 Subject: [PATCH 12/15] Add ChatMemberUpdated.via_chat_folder_invite_link. --- telegram-bot-api/Client.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index b55ca6b..b0dc3df 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -2787,6 +2787,9 @@ class Client::JsonChatMemberUpdated final : public td::Jsonable { if (update_->invite_link_ != nullptr) { object("invite_link", JsonChatInviteLink(update_->invite_link_.get(), client_)); } + if (update_->via_chat_folder_invite_link_) { + object("via_chat_folder_invite_link", td::JsonTrue()); + } } private: From e7a61ce8f8661326792658e42ca16a1517072e73 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 7 Apr 2023 15:29:16 +0300 Subject: [PATCH 13/15] Add "switch_inline_query_chosen_chat" inline keyboard buttons. --- telegram-bot-api/Client.cpp | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/telegram-bot-api/Client.cpp b/telegram-bot-api/Client.cpp index b0dc3df..eb66463 100644 --- a/telegram-bot-api/Client.cpp +++ b/telegram-bot-api/Client.cpp @@ -1832,9 +1832,22 @@ class Client::JsonInlineKeyboardButton final : public td::Jsonable { case td_api::targetChatCurrent::ID: object("switch_inline_query_current_chat", type->query_); break; - case td_api::targetChatChosen::ID: - object("switch_inline_query", type->query_); + case td_api::targetChatChosen::ID: { + auto target_chat = static_cast(type->target_chat_.get()); + if (target_chat->allow_user_chats_ && target_chat->allow_bot_chats_ && target_chat->allow_group_chats_ && + target_chat->allow_channel_chats_) { + object("switch_inline_query", type->query_); + } else { + object("switch_inline_query_chosen_chat", td::json_object([&](auto &o) { + o("query", type->query_); + o("allow_user_chats", td::JsonBool(target_chat->allow_user_chats_)); + o("allow_bot_chats", td::JsonBool(target_chat->allow_bot_chats_)); + o("allow_group_chats", td::JsonBool(target_chat->allow_group_chats_)); + o("allow_channel_chats", td::JsonBool(target_chat->allow_channel_chats_)); + })); + } break; + } default: UNREACHABLE(); } @@ -5612,6 +5625,22 @@ td::Result> Client::get_inline_ switch_inline_query, td_api::make_object(true, true, true, true))); } + if (has_json_object_field(object, "switch_inline_query_chosen_chat")) { + TRY_RESULT(switch_inline_query, + get_json_object_field(object, "switch_inline_query_chosen_chat", td::JsonValue::Type::Object, false)); + CHECK(switch_inline_query.type() == td::JsonValue::Type::Object); + auto &switch_inline_query_object = switch_inline_query.get_object(); + TRY_RESULT(query, get_json_object_string_field(switch_inline_query_object, "query")); + TRY_RESULT(allow_user_chats, get_json_object_bool_field(switch_inline_query_object, "allow_user_chats")); + TRY_RESULT(allow_bot_chats, get_json_object_bool_field(switch_inline_query_object, "allow_bot_chats")); + TRY_RESULT(allow_group_chats, get_json_object_bool_field(switch_inline_query_object, "allow_group_chats")); + TRY_RESULT(allow_channel_chats, get_json_object_bool_field(switch_inline_query_object, "allow_channel_chats")); + return make_object( + text, make_object( + query, td_api::make_object(allow_user_chats, allow_bot_chats, + allow_group_chats, allow_channel_chats))); + } + if (has_json_object_field(object, "switch_inline_query_current_chat")) { TRY_RESULT(switch_inline_query, get_json_object_string_field(object, "switch_inline_query_current_chat", false)); return make_object( From c7253129b5091ced5c32175b5711b9368aa74892 Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 21 Apr 2023 13:21:58 +0300 Subject: [PATCH 14/15] Update version to 6.7. --- CMakeLists.txt | 2 +- telegram-bot-api/telegram-bot-api.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5b75633..6a5c4c4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ if (POLICY CMP0065) cmake_policy(SET CMP0065 NEW) endif() -project(TelegramBotApi VERSION 6.6.2 LANGUAGES CXX) +project(TelegramBotApi VERSION 6.7 LANGUAGES CXX) if (POLICY CMP0069) option(TELEGRAM_BOT_API_ENABLE_LTO "Use \"ON\" to enable Link Time Optimization.") diff --git a/telegram-bot-api/telegram-bot-api.cpp b/telegram-bot-api/telegram-bot-api.cpp index 4c478c8..9cfe01f 100644 --- a/telegram-bot-api/telegram-bot-api.cpp +++ b/telegram-bot-api/telegram-bot-api.cpp @@ -165,7 +165,7 @@ int main(int argc, char *argv[]) { auto start_time = td::Time::now(); auto shared_data = std::make_shared(); auto parameters = std::make_unique(); - parameters->version_ = "6.6.2"; + parameters->version_ = "6.7"; parameters->shared_data_ = shared_data; parameters->start_time_ = start_time; auto net_query_stats = td::create_net_query_stats(); From 251589221708a8280ffcad32fcdc5348d014a6ae Mon Sep 17 00:00:00 2001 From: levlam Date: Fri, 21 Apr 2023 16:08:20 +0300 Subject: [PATCH 15/15] Update TDLib and version to 6.7.1. --- CMakeLists.txt | 2 +- td | 2 +- telegram-bot-api/telegram-bot-api.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a5c4c4..fadd00d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ if (POLICY CMP0065) cmake_policy(SET CMP0065 NEW) endif() -project(TelegramBotApi VERSION 6.7 LANGUAGES CXX) +project(TelegramBotApi VERSION 6.7.1 LANGUAGES CXX) if (POLICY CMP0069) option(TELEGRAM_BOT_API_ENABLE_LTO "Use \"ON\" to enable Link Time Optimization.") diff --git a/td b/td index 8517026..328b864 160000 --- a/td +++ b/td @@ -1 +1 @@ -Subproject commit 8517026415e75a8eec567774072cbbbbb52376c1 +Subproject commit 328b8649d859c5ed4088a875cbb059db6029dc0d diff --git a/telegram-bot-api/telegram-bot-api.cpp b/telegram-bot-api/telegram-bot-api.cpp index 9cfe01f..36bde52 100644 --- a/telegram-bot-api/telegram-bot-api.cpp +++ b/telegram-bot-api/telegram-bot-api.cpp @@ -165,7 +165,7 @@ int main(int argc, char *argv[]) { auto start_time = td::Time::now(); auto shared_data = std::make_shared(); auto parameters = std::make_unique(); - parameters->version_ = "6.7"; + parameters->version_ = "6.7.1"; parameters->shared_data_ = shared_data; parameters->start_time_ = start_time; auto net_query_stats = td::create_net_query_stats();