Add td_api::answerWebViewQuery.
This commit is contained in:
parent
afa00d8b00
commit
9d481df04d
@ -4813,6 +4813,12 @@ getInlineQueryResults bot_user_id:int53 chat_id:int53 user_location:location que
|
||||
answerInlineQuery inline_query_id:int64 is_personal:Bool results:vector<InputInlineQueryResult> cache_time:int32 next_offset:string switch_pm_text:string switch_pm_parameter:string = Ok;
|
||||
|
||||
|
||||
//@description Sets the result of interaction with web view and sends corresponding message on behalf of the user to the chat from which the query originated; for bots only
|
||||
//@web_view_query_id Identifier of the web view query
|
||||
//@result The result of the query
|
||||
answerWebViewQuery web_view_query_id:string result:InputInlineQueryResult = Ok;
|
||||
|
||||
|
||||
//@description Sends a callback query to a bot and returns an answer. Returns an error with code 502 if the bot fails to answer the query before the query timeout expires @chat_id Identifier of the chat with the message @message_id Identifier of the message from which the query originated @payload Query payload
|
||||
getCallbackQueryAnswer chat_id:int53 message_id:int53 payload:CallbackQueryPayload = CallbackQueryAnswer;
|
||||
|
||||
|
@ -151,7 +151,7 @@ class SetInlineBotResultsQuery final : public Td::ResultHandler {
|
||||
|
||||
bool result = result_ptr.ok();
|
||||
if (!result) {
|
||||
LOG(INFO) << "Sending answer to an inline query has failed";
|
||||
LOG(ERROR) << "Sending answer to an inline query has failed";
|
||||
}
|
||||
promise_.set_value(Unit());
|
||||
}
|
||||
@ -161,6 +161,33 @@ class SetInlineBotResultsQuery final : public Td::ResultHandler {
|
||||
}
|
||||
};
|
||||
|
||||
class SendWebViewResultMessageQuery final : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
|
||||
public:
|
||||
explicit SendWebViewResultMessageQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(const string &bot_query_id, tl_object_ptr<telegram_api::InputBotInlineResult> &&result) {
|
||||
send_query(G()->net_query_creator().create(
|
||||
telegram_api::messages_sendWebViewResultMessage(bot_query_id, std::move(result))));
|
||||
}
|
||||
|
||||
void on_result(BufferSlice packet) final {
|
||||
auto result_ptr = fetch_result<telegram_api::messages_sendWebViewResultMessage>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
// auto ptr = result_ptr.move_as_ok();
|
||||
promise_.set_value(Unit());
|
||||
}
|
||||
|
||||
void on_error(Status status) final {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
InlineQueriesManager::InlineQueriesManager(Td *td, ActorShared<> parent) : td_(td), parent_(std::move(parent)) {
|
||||
drop_inline_query_result_timeout_.set_callback(on_drop_inline_query_result_timeout_callback);
|
||||
drop_inline_query_result_timeout_.set_callback_data(static_cast<void *>(this));
|
||||
@ -367,9 +394,7 @@ void InlineQueriesManager::answer_inline_query(
|
||||
int64 inline_query_id, bool is_personal, vector<td_api::object_ptr<td_api::InputInlineQueryResult>> &&input_results,
|
||||
int32 cache_time, const string &next_offset, const string &switch_pm_text, const string &switch_pm_parameter,
|
||||
Promise<Unit> &&promise) const {
|
||||
if (!td_->auth_manager_->is_bot()) {
|
||||
return promise.set_error(Status::Error(400, "Method can be used by bots only"));
|
||||
}
|
||||
CHECK(td_->auth_manager_->is_bot());
|
||||
|
||||
if (!switch_pm_text.empty()) {
|
||||
if (switch_pm_parameter.empty()) {
|
||||
@ -398,6 +423,16 @@ void InlineQueriesManager::answer_inline_query(
|
||||
switch_pm_text, switch_pm_parameter);
|
||||
}
|
||||
|
||||
void InlineQueriesManager::answer_web_view_query(const string &web_view_query_id,
|
||||
td_api::object_ptr<td_api::InputInlineQueryResult> &&input_result,
|
||||
Promise<Unit> &&promise) const {
|
||||
CHECK(td_->auth_manager_->is_bot());
|
||||
|
||||
TRY_RESULT_PROMISE(promise, result, get_input_bot_inline_result(std::move(input_result), nullptr, nullptr));
|
||||
|
||||
td_->create_handler<SendWebViewResultMessageQuery>(std::move(promise))->send(web_view_query_id, std::move(result));
|
||||
}
|
||||
|
||||
Result<tl_object_ptr<telegram_api::InputBotInlineResult>> InlineQueriesManager::get_input_bot_inline_result(
|
||||
td_api::object_ptr<td_api::InputInlineQueryResult> &&result, bool *is_gallery, bool *force_vertical) const {
|
||||
if (result == nullptr) {
|
||||
|
@ -45,6 +45,10 @@ class InlineQueriesManager final : public Actor {
|
||||
const string &next_offset, const string &switch_pm_text, const string &switch_pm_parameter,
|
||||
Promise<Unit> &&promise) const;
|
||||
|
||||
void answer_web_view_query(const string &web_view_query_id,
|
||||
td_api::object_ptr<td_api::InputInlineQueryResult> &&input_result,
|
||||
Promise<Unit> &&promise) const;
|
||||
|
||||
uint64 send_inline_query(UserId bot_user_id, DialogId dialog_id, Location user_location, const string &query,
|
||||
const string &offset, Promise<Unit> &&promise);
|
||||
|
||||
|
@ -7321,6 +7321,14 @@ void Td::on_request(uint64 id, td_api::answerInlineQuery &request) {
|
||||
request.next_offset_, request.switch_pm_text_, request.switch_pm_parameter_, std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::answerWebViewQuery &request) {
|
||||
CHECK_IS_BOT();
|
||||
CLEAN_INPUT_STRING(request.web_view_query_id_);
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
inline_queries_manager_->answer_web_view_query(request.web_view_query_id_, std::move(request.result_),
|
||||
std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::getCallbackQueryAnswer &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_REQUEST_PROMISE();
|
||||
|
@ -1151,6 +1151,8 @@ class Td final : public Actor {
|
||||
|
||||
void on_request(uint64 id, td_api::answerInlineQuery &request);
|
||||
|
||||
void on_request(uint64 id, td_api::answerWebViewQuery &request);
|
||||
|
||||
void on_request(uint64 id, td_api::getCallbackQueryAnswer &request);
|
||||
|
||||
void on_request(uint64 id, td_api::answerCallbackQuery &request);
|
||||
|
Loading…
Reference in New Issue
Block a user