Improve td_api::internalLinkTypeAttachmentMenuBot.

This commit is contained in:
levlam 2022-06-01 18:06:49 +03:00
parent 9aac7a4d0c
commit 8c59d4bd6d
3 changed files with 41 additions and 24 deletions

View File

@ -3540,12 +3540,20 @@ chatReportReasonPersonalDetails = ChatReportReason;
chatReportReasonCustom = ChatReportReason; chatReportReasonCustom = ChatReportReason;
//@description Describes supported chat types //@class TargetChat @description Describes the target chat to be opened
//@supports_user_chats True, if private chats with ordinary users are supported
//@supports_bot_chats True, if private chats with other bots are supported //@description The currently opened chat needs to be kept
//@supports_group_chats True, if basic group and supergroup chats are supported targetChatCurrent = TargetChat;
//@supports_channel_chats True, if channel chats are supported
supportedChatTypes supports_user_chats:Bool supports_bot_chats:Bool supports_group_chats:Bool supports_channel_chats:Bool = SupportedChatTypes; //@description The chat needs to be chosen by the user among chats of the specified types
//@allow_user_chats True, if private chats with ordinary users are allowed
//@allow_bot_chats True, if private chats with other bots are allowed
//@allow_group_chats True, if basic group and supergroup chats are allowed
//@allow_channel_chats True, if channel chats are allowed
targetChatChosen allow_user_chats:Bool allow_bot_chats:Bool allow_group_chats:Bool allow_channel_chats:Bool = TargetChat;
//@description The chat needs to be open with the provided internal link @link An internal link pointing to the chat
targetChatInternalLink link:InternalLinkType = TargetChat;
//@class InternalLinkType @description Describes an internal https://t.me or tg: link, which must be processed by the application in a special way //@class InternalLinkType @description Describes an internal https://t.me or tg: link, which must be processed by the application in a special way
@ -3553,12 +3561,12 @@ supportedChatTypes supports_user_chats:Bool supports_bot_chats:Bool supports_gro
//@description The link is a link to the active sessions section of the application. Use getActiveSessions to handle the link //@description The link is a link to the active sessions section of the application. Use getActiveSessions to handle the link
internalLinkTypeActiveSessions = InternalLinkType; internalLinkTypeActiveSessions = InternalLinkType;
//@description The link is a link to an attachment menu bot to be opened in the specified or a chosen chat. Process given chat_types and chat_link to choose and open the corresponding chat. //@description The link is a link to an attachment menu bot to be opened in the specified or a chosen chat. Process given target_chat to open the chat.
//-Then call searchPublicChat with the given bot username, check that the user is a bot and can be added to attachment menu. Then use getAttachmentMenuBot to receive information about the bot. //-Then call searchPublicChat with the given bot username, check that the user is a bot and can be added to attachment menu. Then use getAttachmentMenuBot to receive information about the bot.
//-If the bot isn't added to attachment menu, then user needs to confirm adding the bot to attachment menu. If user confirms adding, then use toggleBotIsAddedToAttachmentMenu to add it. //-If the bot isn't added to attachment menu, then user needs to confirm adding the bot to attachment menu. If user confirms adding, then use toggleBotIsAddedToAttachmentMenu to add it.
//-If the attachment menu bot can't be used in the opened chat, show an error to the user. If the bot is added to attachment menu, then use openWebApp with the given URL //-If the attachment menu bot can't be used in the opened chat, show an error to the user. If the bot is added to attachment menu and can be used in the chat, then use openWebApp with the given URL
//@chat_types List of chat types, supported by the link; may be null if chat_link must be processed instead @chat_link An internal link pointing to a chat; may be null if the current chat needs to be kept @bot_username Username of the bot @url URL to be passed to openWebApp //@target_chat Description of the chat to be opened @bot_username Username of the bot @url URL to be passed to openWebApp
internalLinkTypeAttachmentMenuBot chat_types:supportedChatTypes chat_link:InternalLinkType bot_username:string url:string = InternalLinkType; internalLinkTypeAttachmentMenuBot target_chat:TargetChat bot_username:string url:string = InternalLinkType;
//@description The link contains an authentication code. Call checkAuthenticationCode with the code if the current authorization state is authorizationStateWaitCode @code The authentication code //@description The link contains an authentication code. Call checkAuthenticationCode with the code if the current authorization state is authorizationStateWaitCode @code The authentication code
internalLinkTypeAuthenticationCode code:string = InternalLinkType; internalLinkTypeAuthenticationCode code:string = InternalLinkType;

View File

@ -154,27 +154,29 @@ class LinkManager::InternalLinkActiveSessions final : public InternalLink {
}; };
class LinkManager::InternalLinkAttachMenuBot final : public InternalLink { class LinkManager::InternalLinkAttachMenuBot final : public InternalLink {
td_api::object_ptr<td_api::supportedChatTypes> dialog_types_; td_api::object_ptr<td_api::targetChatChosen> allowed_chat_types_;
unique_ptr<InternalLink> dialog_link_; unique_ptr<InternalLink> dialog_link_;
string bot_username_; string bot_username_;
string url_; string url_;
td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final { td_api::object_ptr<td_api::InternalLinkType> get_internal_link_type_object() const final {
td_api::object_ptr<td_api::supportedChatTypes> dialog_types; td_api::object_ptr<td_api::TargetChat> target_chat;
if (dialog_types_ != nullptr) { if (dialog_link_ != nullptr) {
dialog_types = td_api::make_object<td_api::supportedChatTypes>( target_chat = td_api::make_object<td_api::targetChatInternalLink>(dialog_link_->get_internal_link_type_object());
dialog_types_->supports_user_chats_, dialog_types_->supports_bot_chats_, dialog_types_->supports_group_chats_, } else if (allowed_chat_types_ != nullptr) {
dialog_types_->supports_channel_chats_); target_chat = td_api::make_object<td_api::targetChatChosen>(
allowed_chat_types_->allow_user_chats_, allowed_chat_types_->allow_bot_chats_,
allowed_chat_types_->allow_group_chats_, allowed_chat_types_->allow_channel_chats_);
} else {
target_chat = td_api::make_object<td_api::targetChatCurrent>();
} }
return td_api::make_object<td_api::internalLinkTypeAttachmentMenuBot>( return td_api::make_object<td_api::internalLinkTypeAttachmentMenuBot>(std::move(target_chat), bot_username_, url_);
std::move(dialog_types), dialog_link_ == nullptr ? nullptr : dialog_link_->get_internal_link_type_object(),
bot_username_, url_);
} }
public: public:
InternalLinkAttachMenuBot(td_api::object_ptr<td_api::supportedChatTypes> dialog_types, InternalLinkAttachMenuBot(td_api::object_ptr<td_api::targetChatChosen> allowed_chat_types,
unique_ptr<InternalLink> dialog_link, string bot_username, Slice start_parameter) unique_ptr<InternalLink> dialog_link, string bot_username, Slice start_parameter)
: dialog_types_(std::move(dialog_types)) : allowed_chat_types_(std::move(allowed_chat_types))
, dialog_link_(std::move(dialog_link)) , dialog_link_(std::move(dialog_link))
, bot_username_(std::move(bot_username)) { , bot_username_(std::move(bot_username)) {
if (!start_parameter.empty()) { if (!start_parameter.empty()) {

View File

@ -98,12 +98,19 @@ TEST(Link, parse_internal_link) {
auto active_sessions = [] { auto active_sessions = [] {
return td::td_api::make_object<td::td_api::internalLinkTypeActiveSessions>(); return td::td_api::make_object<td::td_api::internalLinkTypeActiveSessions>();
}; };
auto attachment_menu_bot = [](td::td_api::object_ptr<td::td_api::supportedChatTypes> chat_types, auto attachment_menu_bot = [](td::td_api::object_ptr<td::td_api::targetChatChosen> chat_types,
td::td_api::object_ptr<td::td_api::InternalLinkType> chat_link, td::td_api::object_ptr<td::td_api::InternalLinkType> chat_link,
const td::string &bot_username, const td::string &start_parameter) { const td::string &bot_username, const td::string &start_parameter) {
td::td_api::object_ptr<td::td_api::TargetChat> target_chat;
if (chat_link != nullptr) {
target_chat = td::td_api::make_object<td::td_api::targetChatInternalLink>(std::move(chat_link));
} else if (chat_types != nullptr) {
target_chat = std::move(chat_types);
} else {
target_chat = td::td_api::make_object<td::td_api::targetChatCurrent>();
}
return td::td_api::make_object<td::td_api::internalLinkTypeAttachmentMenuBot>( return td::td_api::make_object<td::td_api::internalLinkTypeAttachmentMenuBot>(
std::move(chat_types), std::move(chat_link), bot_username, std::move(target_chat), bot_username, start_parameter.empty() ? td::string() : "start://" + start_parameter);
start_parameter.empty() ? td::string() : "start://" + start_parameter);
}; };
auto authentication_code = [](const td::string &code) { auto authentication_code = [](const td::string &code) {
return td::td_api::make_object<td::td_api::internalLinkTypeAuthenticationCode>(code); return td::td_api::make_object<td::td_api::internalLinkTypeAuthenticationCode>(code);