Add td_api::sendWebViewData.

This commit is contained in:
levlam 2022-03-28 15:18:15 +03:00
parent e8a82f9e70
commit d9ddb53056
6 changed files with 69 additions and 0 deletions

View File

@ -4843,6 +4843,10 @@ 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 Sends data received from keyboardButtonTypeWebView web view to a bot
//@bot_user_id Identifier of the target bot @button_text Text of the keyboardButtonTypeWebView button, which opened the web view @data Received data
sendWebViewData bot_user_id:int53 button_text:string data: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

View File

@ -35,6 +35,7 @@
#include "td/telegram/TdDb.h"
#include "td/telegram/TdParameters.h"
#include "td/telegram/telegram_api.hpp"
#include "td/telegram/UpdatesManager.h"
#include "td/telegram/Venue.h"
#include "td/telegram/VideosManager.h"
#include "td/telegram/VoiceNotesManager.h"
@ -45,6 +46,7 @@
#include "td/utils/HttpUrl.h"
#include "td/utils/logging.h"
#include "td/utils/misc.h"
#include "td/utils/Random.h"
#include "td/utils/Slice.h"
#include "td/utils/SliceBuilder.h"
#include "td/utils/Time.h"
@ -161,6 +163,35 @@ class SetInlineBotResultsQuery final : public Td::ResultHandler {
}
};
class SendWebViewDataQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
public:
explicit SendWebViewDataQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
}
void send(tl_object_ptr<telegram_api::InputUser> &&input_user, int64 random_id, const string &button_text,
const string &data) {
send_query(G()->net_query_creator().create(
telegram_api::messages_sendWebViewData(std::move(input_user), random_id, button_text, data)));
}
void on_result(BufferSlice packet) final {
auto result_ptr = fetch_result<telegram_api::messages_sendWebViewData>(packet);
if (result_ptr.is_error()) {
return on_error(result_ptr.move_as_error());
}
auto ptr = result_ptr.move_as_ok();
LOG(INFO) << "Receive result for SendWebViewDataQuery: " << to_string(ptr);
td_->updates_manager_->on_get_updates(std::move(ptr), std::move(promise_));
}
void on_error(Status status) final {
promise_.set_error(std::move(status));
}
};
class SendWebViewResultMessageQuery final : public Td::ResultHandler {
Promise<Unit> promise_;
@ -423,6 +454,21 @@ void InlineQueriesManager::answer_inline_query(
switch_pm_text, switch_pm_parameter);
}
void InlineQueriesManager::send_web_view_data(UserId bot_user_id, string &&button_text, string &&data,
Promise<Unit> &&promise) const {
TRY_RESULT_PROMISE(promise, bot_data, td_->contacts_manager_->get_bot_data(bot_user_id));
int64 random_id;
do {
random_id = Random::secure_int64();
} while (random_id == 0);
TRY_RESULT_PROMISE(promise, input_user, td_->contacts_manager_->get_input_user(bot_user_id));
td_->create_handler<SendWebViewDataQuery>(std::move(promise))
->send(std::move(input_user), random_id, button_text, data);
}
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 {

View File

@ -45,6 +45,8 @@ class InlineQueriesManager final : public Actor {
const string &next_offset, const string &switch_pm_text, const string &switch_pm_parameter,
Promise<Unit> &&promise) const;
void send_web_view_data(UserId bot_user_id, string &&button_text, string &&data, 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;

View File

@ -7328,6 +7328,15 @@ 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::sendWebViewData &request) {
CHECK_IS_USER();
CLEAN_INPUT_STRING(request.button_text_);
CLEAN_INPUT_STRING(request.data_);
CREATE_OK_REQUEST_PROMISE();
inline_queries_manager_->send_web_view_data(UserId(request.bot_user_id_), std::move(request.button_text_),
std::move(request.data_), std::move(promise));
}
void Td::on_request(uint64 id, td_api::answerWebViewQuery &request) {
CHECK_IS_BOT();
CLEAN_INPUT_STRING(request.web_view_query_id_);

View File

@ -1153,6 +1153,8 @@ class Td final : public Actor {
void on_request(uint64 id, td_api::answerInlineQuery &request);
void on_request(uint64 id, td_api::sendWebViewData &request);
void on_request(uint64 id, td_api::answerWebViewQuery &request);
void on_request(uint64 id, td_api::getCallbackQueryAnswer &request);

View File

@ -3419,6 +3419,12 @@ class CliClient final : public Actor {
bool is_added;
get_args(args, user_id, is_added);
send_request(td_api::make_object<td_api::toggleBotIsAddedToAttachMenu>(user_id, is_added));
} else if (op == "swwd") {
UserId user_id;
string button_text;
string data;
get_args(args, user_id, button_text, data);
send_request(td_api::make_object<td_api::sendWebViewData>(user_id, button_text, data));
} else if (op == "sca") {
ChatId chat_id;
string message_thread_id;