From 476e4f739768ffaee7431c4c90063cdcba328593 Mon Sep 17 00:00:00 2001 From: John Preston Date: Mon, 29 Jun 2026 19:22:48 +0400 Subject: [PATCH] Round-trip guard-bot join webview query_id --- Telegram/SourceFiles/api/api_chat_invite.cpp | 2 +- .../inline_bots/bot_attach_web_view.cpp | 24 ++++++++++++++++--- .../inline_bots/bot_attach_web_view.h | 3 ++- Telegram/SourceFiles/mtproto/scheme/api.tl | 8 ++++--- 4 files changed, 29 insertions(+), 8 deletions(-) diff --git a/Telegram/SourceFiles/api/api_chat_invite.cpp b/Telegram/SourceFiles/api/api_chat_invite.cpp index e1a855fa96..b6c7af06e8 100644 --- a/Telegram/SourceFiles/api/api_chat_invite.cpp +++ b/Telegram/SourceFiles/api/api_chat_invite.cpp @@ -660,7 +660,7 @@ void ProcessChatInviteJoinResult( .maySkipConfirmation = false, }, .source = InlineBots::WebViewSourceJoinChat{ - .result = InlineBots::ParseWebViewResult(data.vwebview()), + .queryId = data.vquery_id().v, }, }); }); diff --git a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp index 046322ed2b..9303b3445f 100644 --- a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp +++ b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.cpp @@ -1027,9 +1027,7 @@ void WebViewInstance::resolve() { requestMain(); }, [&](WebViewSourceJoinChat data) { confirmOpen([=] { - show({ - .result = data.result, - }); + requestChatJoin(); }, true); }); } @@ -1327,6 +1325,26 @@ void WebViewInstance::requestApp(bool allowWrite) { }).send(); } +void WebViewInstance::requestChatJoin() { + const auto &join = v::get(_source); + using Flag = MTPmessages_RequestChatJoinWebView::Flag; + _requestId = _session->api().request(MTPmessages_RequestChatJoinWebView( + MTP_flags(Flag::f_theme_params), + MTP_long(join.queryId), + MTP_dataJSON(MTP_bytes(botThemeParams().json)), + MTP_string("tdesktop") + )).done([=](const MTPWebViewResult &result) { + _requestId = 0; + show({ + .result = ParseWebViewResult(result), + }); + }).fail([=](const MTP::Error &error) { + _requestId = 0; + _parentShow->showToast(error.type()); + close(); + }).send(); +} + void WebViewInstance::requestWithMainMenuDisclaimer() { using Result = AttachWebView::AddToMenuResult; const auto done = crl::guard(this, [=](Result value, auto) { diff --git a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.h b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.h index 6b922469a3..3b06ee8fc4 100644 --- a/Telegram/SourceFiles/inline_bots/bot_attach_web_view.h +++ b/Telegram/SourceFiles/inline_bots/bot_attach_web_view.h @@ -190,7 +190,7 @@ struct WebViewResultData { const MTPWebViewResult &result); struct WebViewSourceJoinChat { - WebViewResultData result; + uint64 queryId = 0; friend inline bool operator==( const WebViewSourceJoinChat &, @@ -264,6 +264,7 @@ private: void requestSimple(); void requestMain(); void requestApp(bool allowWrite); + void requestChatJoin(); void requestWithMainMenuDisclaimer(); void requestWithMenuAdd(); void maybeChooseAndRequestButton(PeerTypes supported); diff --git a/Telegram/SourceFiles/mtproto/scheme/api.tl b/Telegram/SourceFiles/mtproto/scheme/api.tl index 114cb324b2..b61f335444 100644 --- a/Telegram/SourceFiles/mtproto/scheme/api.tl +++ b/Telegram/SourceFiles/mtproto/scheme/api.tl @@ -2201,6 +2201,7 @@ stats.pollStats#2999beed votes_graph:StatsGraph = stats.PollStats; inputAiComposeToneDefault#1fe9a9bf tone:string = InputAiComposeTone; inputAiComposeToneID#773c080 id:long access_hash:long = InputAiComposeTone; inputAiComposeToneSlug#1fa01357 slug:string = InputAiComposeTone; +inputAiComposeToneSingleUse#e0c35af custom_prompt:string = InputAiComposeTone; aiComposeTone#cff63ea9 flags:# creator:flags.0?true id:long access_hash:long slug:string title:string emoji_id:flags.1?long prompt:flags.4?string installs_count:flags.2?int author_id:flags.3?long example_english:flags.5?AiComposeToneExample = AiComposeTone; aiComposeToneDefault#9bad6414 tone:string emoji_id:long title:string = AiComposeTone; @@ -2213,7 +2214,7 @@ aiComposeToneExample#f1d628ec from:TextWithEntities to:TextWithEntities = AiComp bots.accessSettings#dd1fbf93 flags:# restricted:flags.0?true add_users:flags.1?Vector = bots.AccessSettings; messages.chatInviteJoinResultOk#445663a7 updates:Updates = messages.ChatInviteJoinResult; -messages.chatInviteJoinResultWebView#2f51c337 bot_id:long webview:WebViewResult users:Vector = messages.ChatInviteJoinResult; +messages.chatInviteJoinResultWebView#61ca29d3 bot_id:long query_id:long users:Vector = messages.ChatInviteJoinResult; joinChatBotResultApproved#ae152a69 = JoinChatBotResult; joinChatBotResultDeclined#efa0194 = JoinChatBotResult; @@ -2712,7 +2713,8 @@ messages.deleteParticipantReaction#e3b7f82c peer:InputPeer msg_id:int participan messages.getPersonalChannelHistory#55fb0996 user_id:InputUser limit:int max_id:int min_id:int hash:long = messages.Messages; messages.getRichMessage#501569cf peer:InputPeer id:int = messages.Messages; messages.translateRichMessage#1a542004 flags:# peer:flags.0?InputPeer id:flags.0?Vector text:flags.1?Vector to_lang:string tone:flags.2?string = messages.TranslatedRichMessage; -messages.composeRichMessageWithAI#b4e4eec7 flags:# proofread:flags.0?true emojify:flags.3?true text:InputRichMessage translate_to_lang:flags.1?string tone:flags.2?InputAiComposeTone = messages.ComposedRichMessageWithAI; +messages.composeRichMessageWithAI#8d7ae6af flags:# proofread:flags.0?true emojify:flags.3?true text:flags.4?InputRichMessage translate_to_lang:flags.1?string tone:flags.2?InputAiComposeTone = messages.ComposedRichMessageWithAI; +messages.requestChatJoinWebView#ba9ee679 flags:# query_id:long theme_params:flags.0?DataJSON platform:string = WebViewResult; updates.getState#edd4882a = updates.State; updates.getDifference#19c2f763 flags:# pts:int pts_limit:flags.1?int pts_total_limit:flags.0?int date:int qts:int qts_limit:flags.2?int = updates.Difference; @@ -3066,7 +3068,7 @@ aicompose.getTone#b2e8ba03 tone:InputAiComposeTone = aicompose.Tones; aicompose.getTones#abd59201 hash:long = aicompose.Tones; aicompose.getToneExample#d1b4ab14 tone:InputAiComposeTone num:int = AiComposeToneExample; -communities.create#a63859ec flags:# title:string about:flags.0?string peer:InputPeer = Updates; +communities.create#a63859ec flags:# hidden:flags.1?true title:string about:flags.0?string peer:InputPeer = Updates; communities.togglePeerLink#736dcfea flags:# visible:flags.0?true hidden:flags.1?true deleted:flags.2?true community:InputChannel peer:InputPeer = Bool; communities.getJoinedCommunities#a663e830 = messages.Chats; communities.toggleCommunityCollapsedInDialogs#d766e3ea flags:# collapsed:flags.0?true community:InputChannel = Updates;