diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 0c8045d4d..e149ccd29 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2316,6 +2316,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_chatbots_reply_about" = "The bot will be able to view all new incoming messages, but not the messages that had been sent before you added the bot."; "lng_chatbots_remove" = "Remove Bot"; "lng_chatbots_not_found" = "Chatbot not found."; +"lng_chatbots_not_supported" = "This bot doesn't support Telegram Business yet."; "lng_chatbots_add" = "Add"; "lng_chatbots_info_url" = "https://telegram.org/privacy"; "lng_chatbot_status_can_reply" = "bot manages this chat"; diff --git a/Telegram/SourceFiles/data/data_session.cpp b/Telegram/SourceFiles/data/data_session.cpp index c31d22440..3881a601c 100644 --- a/Telegram/SourceFiles/data/data_session.cpp +++ b/Telegram/SourceFiles/data/data_session.cpp @@ -722,6 +722,7 @@ not_null Session::processUser(const MTPUser &data) { result->botInfo->inlinePlaceholder = QString(); } result->botInfo->supportsAttachMenu = data.is_bot_attach_menu(); + result->botInfo->supportsBusiness = data.is_bot_business(); result->botInfo->canEditInformation = data.is_bot_can_edit(); } else { result->setBotInfoVersion(-1); diff --git a/Telegram/SourceFiles/data/data_user.h b/Telegram/SourceFiles/data/data_user.h index fd992a0ef..166988287 100644 --- a/Telegram/SourceFiles/data/data_user.h +++ b/Telegram/SourceFiles/data/data_user.h @@ -22,13 +22,6 @@ struct BusinessDetails; struct BotInfo { BotInfo(); - bool inited = false; - bool readsAllHistory = false; - bool cantJoinGroups = false; - bool supportsAttachMenu = false; - bool canEditInformation = false; - int version = 0; - int descriptionVersion = 0; QString description; QString inlinePlaceholder; std::vector commands; @@ -44,6 +37,15 @@ struct BotInfo { ChatAdminRights groupAdminRights; ChatAdminRights channelAdminRights; + + int version = 0; + int descriptionVersion = 0; + bool inited : 1 = false; + bool readsAllHistory : 1 = false; + bool cantJoinGroups : 1 = false; + bool supportsAttachMenu : 1 = false; + bool canEditInformation : 1 = false; + bool supportsBusiness : 1 = false; }; enum class UserDataFlag : uint32 { diff --git a/Telegram/SourceFiles/settings/business/settings_chatbots.cpp b/Telegram/SourceFiles/settings/business/settings_chatbots.cpp index cb11074ab..d31239e19 100644 --- a/Telegram/SourceFiles/settings/business/settings_chatbots.cpp +++ b/Telegram/SourceFiles/settings/business/settings_chatbots.cpp @@ -38,6 +38,7 @@ constexpr auto kDebounceTimeout = crl::time(400); enum class LookupState { Empty, Loading, + Unsupported, Ready, }; @@ -247,9 +248,14 @@ Main::Session &PreviewController::session() const { return rpl::single(BotState()); } else if (const auto peer = owner->peerByUsername(extracted)) { if (const auto user = peer->asUser(); user && user->isBot()) { + if (user->botInfo->supportsBusiness) { + return rpl::single(BotState{ + .bot = user, + .state = LookupState::Ready, + }); + } return rpl::single(BotState{ - .bot = user, - .state = LookupState::Ready, + .state = LookupState::Unsupported, }); } return rpl::single(BotState{ @@ -314,7 +320,10 @@ Main::Session &PreviewController::session() const { std::move(state) | rpl::filter([=](BotState state) { return state.state != LookupState::Loading; }) | rpl::start_with_next([=](BotState state) { - raw->toggle(state.state == LookupState::Ready, anim::type::normal); + raw->toggle( + (state.state == LookupState::Ready + || state.state == LookupState::Unsupported), + anim::type::normal); if (state.bot) { const auto delegate = parent->lifetime().make_state< PeerListContentDelegateSimple @@ -330,11 +339,14 @@ Main::Session &PreviewController::session() const { controller->setDelegate(delegate); delete base::take(*child); *child = content; - } else if (state.state == LookupState::Ready) { + } else if (state.state == LookupState::Ready + || state.state == LookupState::Unsupported) { const auto content = Ui::CreateChild(inner); const auto label = Ui::CreateChild( content, - tr::lng_chatbots_not_found(), + (state.state == LookupState::Unsupported + ? tr::lng_chatbots_not_supported() + : tr::lng_chatbots_not_found()), st::settingsChatbotsNotFound); content->resize( inner->width(), @@ -483,6 +495,8 @@ void Chatbots::save() { const auto fail = [=](QString error) { if (error == u"BUSINESS_RECIPIENTS_EMPTY"_q) { show->showToast(tr::lng_greeting_recipients_empty(tr::now)); + } else if (error == u"BOT_BUSINESS_MISSING"_q) { + show->showToast(tr::lng_chatbots_not_supported(tr::now)); } }; controller()->session().data().chatbots().save({