diff --git a/td/telegram/BotQueries.cpp b/td/telegram/BotQueries.cpp index 37e7e4539..a992cd2b4 100644 --- a/td/telegram/BotQueries.cpp +++ b/td/telegram/BotQueries.cpp @@ -43,9 +43,43 @@ class SendCustomRequestQuery final : public Td::ResultHandler { } }; +class AnswerCustomQueryQuery final : public Td::ResultHandler { + Promise promise_; + + public: + explicit AnswerCustomQueryQuery(Promise &&promise) : promise_(std::move(promise)) { + } + + void send(int64 custom_query_id, const string &data) { + send_query(G()->net_query_creator().create(telegram_api::bots_answerWebhookJSONQuery( + custom_query_id, telegram_api::make_object(data)))); + } + + void on_result(BufferSlice packet) final { + auto result_ptr = fetch_result(packet); + if (result_ptr.is_error()) { + return on_error(result_ptr.move_as_error()); + } + + bool result = result_ptr.ok(); + if (!result) { + LOG(INFO) << "Sending answer to a custom query has failed"; + } + promise_.set_value(Unit()); + } + + void on_error(Status status) final { + promise_.set_error(std::move(status)); + } +}; + void send_bot_custom_query(Td *td, const string &method, const string ¶meters, Promise> &&promise) { td->create_handler(std::move(promise))->send(method, parameters); } +void answer_bot_custom_query(Td *td, int64 custom_query_id, const string &data, Promise &&promise) { + td->create_handler(std::move(promise))->send(custom_query_id, data); +} + } // namespace td diff --git a/td/telegram/BotQueries.h b/td/telegram/BotQueries.h index 3cf45bdb9..844e8ccf5 100644 --- a/td/telegram/BotQueries.h +++ b/td/telegram/BotQueries.h @@ -18,4 +18,6 @@ class Td; void send_bot_custom_query(Td *td, const string &method, const string ¶meters, Promise> &&promise); +void answer_bot_custom_query(Td *td, int64 custom_query_id, const string &data, Promise &&promise); + } // namespace td diff --git a/td/telegram/Requests.cpp b/td/telegram/Requests.cpp index 3bb3e3532..3501b9dab 100644 --- a/td/telegram/Requests.cpp +++ b/td/telegram/Requests.cpp @@ -276,36 +276,6 @@ class GetRecentMeUrlsQuery final : public Td::ResultHandler { } }; -class AnswerCustomQueryQuery final : public Td::ResultHandler { - Promise promise_; - - public: - explicit AnswerCustomQueryQuery(Promise &&promise) : promise_(std::move(promise)) { - } - - void send(int64 custom_query_id, const string &data) { - send_query(G()->net_query_creator().create(telegram_api::bots_answerWebhookJSONQuery( - custom_query_id, telegram_api::make_object(data)))); - } - - void on_result(BufferSlice packet) final { - auto result_ptr = fetch_result(packet); - if (result_ptr.is_error()) { - return on_error(result_ptr.move_as_error()); - } - - bool result = result_ptr.ok(); - if (!result) { - LOG(INFO) << "Sending answer to a custom query has failed"; - } - promise_.set_value(Unit()); - } - - void on_error(Status status) final { - promise_.set_error(std::move(status)); - } -}; - class SetBotUpdatesStatusQuery final : public Td::ResultHandler { public: void send(int32 pending_update_count, const string &error_message) { @@ -7674,7 +7644,7 @@ void Requests::on_request(uint64 id, td_api::answerCustomQuery &request) { CHECK_IS_BOT(); CLEAN_INPUT_STRING(request.data_); CREATE_OK_REQUEST_PROMISE(); - td_->create_handler(std::move(promise))->send(request.custom_query_id_, request.data_); + answer_bot_custom_query(td_, request.custom_query_id_, request.data_, std::move(promise)); } void Requests::on_request(uint64 id, const td_api::setAlarm &request) {