Move SendCustomRequestQuery to BotQueries.cpp.
This commit is contained in:
parent
d8f2c204c7
commit
7182ccfa67
@ -338,6 +338,7 @@ set(TDLIB_SOURCE_PART1
|
||||
td/telegram/BotCommandScope.cpp
|
||||
td/telegram/BotInfoManager.cpp
|
||||
td/telegram/BotMenuButton.cpp
|
||||
td/telegram/BotQueries.cpp
|
||||
td/telegram/BusinessAwayMessage.cpp
|
||||
td/telegram/BusinessAwayMessageSchedule.cpp
|
||||
td/telegram/BusinessBotManageBar.cpp
|
||||
@ -628,6 +629,7 @@ set(TDLIB_SOURCE_PART2
|
||||
td/telegram/BotCommandScope.h
|
||||
td/telegram/BotInfoManager.h
|
||||
td/telegram/BotMenuButton.h
|
||||
td/telegram/BotQueries.h
|
||||
td/telegram/BusinessAwayMessage.h
|
||||
td/telegram/BusinessAwayMessageSchedule.h
|
||||
td/telegram/BusinessBotManageBar.h
|
||||
|
51
td/telegram/BotQueries.cpp
Normal file
51
td/telegram/BotQueries.cpp
Normal file
@ -0,0 +1,51 @@
|
||||
//
|
||||
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
#include "td/telegram/BotQueries.h"
|
||||
|
||||
#include "td/telegram/Global.h"
|
||||
#include "td/telegram/Td.h"
|
||||
#include "td/telegram/telegram_api.h"
|
||||
|
||||
#include "td/utils/buffer.h"
|
||||
#include "td/utils/logging.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
class SendCustomRequestQuery final : public Td::ResultHandler {
|
||||
Promise<td_api::object_ptr<td_api::customRequestResult>> promise_;
|
||||
|
||||
public:
|
||||
explicit SendCustomRequestQuery(Promise<td_api::object_ptr<td_api::customRequestResult>> &&promise)
|
||||
: promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(const string &method, const string ¶meters) {
|
||||
send_query(G()->net_query_creator().create(
|
||||
telegram_api::bots_sendCustomRequest(method, telegram_api::make_object<telegram_api::dataJSON>(parameters))));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::bots_sendCustomRequest>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto result = result_ptr.move_as_ok();
|
||||
promise_.set_value(td_api::make_object<td_api::customRequestResult>(result->data_));
|
||||
}
|
||||
|
||||
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<td_api::object_ptr<td_api::customRequestResult>> &&promise) {
|
||||
td->create_handler<SendCustomRequestQuery>(std::move(promise))->send(method, parameters);
|
||||
}
|
||||
|
||||
} // namespace td
|
21
td/telegram/BotQueries.h
Normal file
21
td/telegram/BotQueries.h
Normal file
@ -0,0 +1,21 @@
|
||||
//
|
||||
// Copyright Aliaksei Levin (levlam@telegram.org), Arseny Smirnov (arseny30@gmail.com) 2014-2024
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
#pragma once
|
||||
|
||||
#include "td/telegram/td_api.h"
|
||||
|
||||
#include "td/utils/common.h"
|
||||
#include "td/utils/Promise.h"
|
||||
|
||||
namespace td {
|
||||
|
||||
class Td;
|
||||
|
||||
void send_bot_custom_query(Td *td, const string &method, const string ¶meters,
|
||||
Promise<td_api::object_ptr<td_api::customRequestResult>> &&promise);
|
||||
|
||||
} // namespace td
|
@ -24,6 +24,7 @@
|
||||
#include "td/telegram/BotCommand.h"
|
||||
#include "td/telegram/BotInfoManager.h"
|
||||
#include "td/telegram/BotMenuButton.h"
|
||||
#include "td/telegram/BotQueries.h"
|
||||
#include "td/telegram/BusinessAwayMessage.h"
|
||||
#include "td/telegram/BusinessConnectionId.h"
|
||||
#include "td/telegram/BusinessConnectionManager.h"
|
||||
@ -275,34 +276,6 @@ class GetRecentMeUrlsQuery final : public Td::ResultHandler {
|
||||
}
|
||||
};
|
||||
|
||||
class SendCustomRequestQuery final : public Td::ResultHandler {
|
||||
Promise<td_api::object_ptr<td_api::customRequestResult>> promise_;
|
||||
|
||||
public:
|
||||
explicit SendCustomRequestQuery(Promise<td_api::object_ptr<td_api::customRequestResult>> &&promise)
|
||||
: promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(const string &method, const string ¶meters) {
|
||||
send_query(G()->net_query_creator().create(
|
||||
telegram_api::bots_sendCustomRequest(method, telegram_api::make_object<telegram_api::dataJSON>(parameters))));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::bots_sendCustomRequest>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
auto result = result_ptr.move_as_ok();
|
||||
promise_.set_value(td_api::make_object<td_api::customRequestResult>(result->data_));
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class AnswerCustomQueryQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
|
||||
@ -7694,7 +7667,7 @@ void Requests::on_request(uint64 id, td_api::sendCustomRequest &request) {
|
||||
CLEAN_INPUT_STRING(request.method_);
|
||||
CLEAN_INPUT_STRING(request.parameters_);
|
||||
CREATE_REQUEST_PROMISE();
|
||||
td_->create_handler<SendCustomRequestQuery>(std::move(promise))->send(request.method_, request.parameters_);
|
||||
send_bot_custom_query(td_, request.method_, request.parameters_, std::move(promise));
|
||||
}
|
||||
|
||||
void Requests::on_request(uint64 id, td_api::answerCustomQuery &request) {
|
||||
|
Loading…
Reference in New Issue
Block a user