Add optional administrator_rights to internalLinkTypeBotStartInGroup.
This commit is contained in:
parent
eef401cea0
commit
da4282a6d9
@ -3371,9 +3371,13 @@ internalLinkTypeBackground background_name:string = InternalLinkType;
|
|||||||
internalLinkTypeBotStart bot_username:string start_parameter:string = InternalLinkType;
|
internalLinkTypeBotStart bot_username:string start_parameter:string = InternalLinkType;
|
||||||
|
|
||||||
//@description The link is a link to a Telegram bot, which is supposed to be added to a group chat. Call searchPublicChat with the given bot username, check that the user is a bot and can be added to groups,
|
//@description The link is a link to a Telegram bot, which is supposed to be added to a group chat. Call searchPublicChat with the given bot username, check that the user is a bot and can be added to groups,
|
||||||
//-ask the current user to select a basic group or a supergroup chat to add the bot to, and then call sendBotStartMessage with the given start parameter and the chosen chat. Bots can be added to a public supergroup only by administrators of the supergroup
|
//-ask the current user to select a basic group or a supergroup chat to add the bot to, taking into account that bots can be added to a public supergroup only by administrators of the supergroup.
|
||||||
//@bot_username Username of the bot @start_parameter The parameter to be passed to sendBotStartMessage
|
//-If administrator rights are provided by the link, call getChatMember to receive the current bot rights in the chat and if the bot already is an administrator,
|
||||||
internalLinkTypeBotStartInGroup bot_username:string start_parameter:string = InternalLinkType;
|
//-check that the current user can edit its administrator rights, combine received rights with the requested administrator rights, show confirmation box to the user,
|
||||||
|
//-and call setChatMemberStatus with the chosen chat and confirmed administrator rights. Before call to setChatMemberStatus it may be required to upgrade the chosen basic group chat to a supergroup chat.
|
||||||
|
//-Then if start_parameter isn't empty, call sendBotStartMessage with the given start parameter and the chosen chat, otherwise just send /start message with bot's username added to the chat.
|
||||||
|
//@bot_username Username of the bot @start_parameter The parameter to be passed to sendBotStartMessage @administrator_rights Expected administrator rights for the bot; may be null
|
||||||
|
internalLinkTypeBotStartInGroup bot_username:string start_parameter:string administrator_rights:chatAdministratorRights = InternalLinkType;
|
||||||
|
|
||||||
//@description The link is a link to a Telegram bot, which is supposed to be added to a channel chat as an administrator. Call searchPublicChat with the given bot username and check that the user is a bot,
|
//@description The link is a link to a Telegram bot, which is supposed to be added to a channel chat as an administrator. Call searchPublicChat with the given bot username and check that the user is a bot,
|
||||||
//-ask the current user to select a channel chat to add the bot to as an administrator. Then call getChatMember to receive the current bot rights in the chat and if the bot already is an administrator,
|
//-ask the current user to select a channel chat to add the bot to as an administrator. Then call getChatMember to receive the current bot rights in the chat and if the bot already is an administrator,
|
||||||
|
@ -228,14 +228,20 @@ class LinkManager::InternalLinkBotStart final : public InternalLink {
|
|||||||
class LinkManager::InternalLinkBotStartInGroup final : public InternalLink {
|
class LinkManager::InternalLinkBotStartInGroup final : public InternalLink {
|
||||||
string bot_username_;
|
string bot_username_;
|
||||||
string start_parameter_;
|
string start_parameter_;
|
||||||
|
AdministratorRights administrator_rights_;
|
||||||
|
|
||||||
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 {
|
||||||
return td_api::make_object<td_api::internalLinkTypeBotStartInGroup>(bot_username_, start_parameter_);
|
return td_api::make_object<td_api::internalLinkTypeBotStartInGroup>(
|
||||||
|
bot_username_, start_parameter_,
|
||||||
|
administrator_rights_ == AdministratorRights() ? nullptr
|
||||||
|
: administrator_rights_.get_chat_administrator_rights_object());
|
||||||
}
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
InternalLinkBotStartInGroup(string bot_username, string start_parameter)
|
InternalLinkBotStartInGroup(string bot_username, string start_parameter, AdministratorRights &&administrator_rights)
|
||||||
: bot_username_(std::move(bot_username)), start_parameter_(std::move(start_parameter)) {
|
: bot_username_(std::move(bot_username))
|
||||||
|
, start_parameter_(std::move(start_parameter))
|
||||||
|
, administrator_rights_(std::move(administrator_rights)) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -914,7 +920,11 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_tg_link_query(Slice que
|
|||||||
}
|
}
|
||||||
if (arg.first == "startgroup" && is_valid_start_parameter(arg.second)) {
|
if (arg.first == "startgroup" && is_valid_start_parameter(arg.second)) {
|
||||||
// resolve?domain=<bot_username>&startgroup=<parameter>
|
// resolve?domain=<bot_username>&startgroup=<parameter>
|
||||||
return td::make_unique<InternalLinkBotStartInGroup>(std::move(username), arg.second);
|
// resolve?domain=<bot_username>&startgroup=>parameter>&admin=change_info+delete_messages+restrict_members
|
||||||
|
// resolve?domain=<bot_username>&startgroup&admin=change_info+delete_messages+restrict_members
|
||||||
|
auto administrator_rights = get_administrator_rights(url_query.get_arg("admin"), false);
|
||||||
|
return td::make_unique<InternalLinkBotStartInGroup>(std::move(username), arg.second,
|
||||||
|
std::move(administrator_rights));
|
||||||
}
|
}
|
||||||
if (arg.first == "startchannel") {
|
if (arg.first == "startchannel") {
|
||||||
// resolve?domain=<bot_username>&startchannel&admin=change_info+post_messages+promote_members
|
// resolve?domain=<bot_username>&startchannel&admin=change_info+post_messages+promote_members
|
||||||
@ -1219,7 +1229,11 @@ unique_ptr<LinkManager::InternalLink> LinkManager::parse_t_me_link_query(Slice q
|
|||||||
}
|
}
|
||||||
if (arg.first == "startgroup" && is_valid_start_parameter(arg.second)) {
|
if (arg.first == "startgroup" && is_valid_start_parameter(arg.second)) {
|
||||||
// /<bot_username>?startgroup=<parameter>
|
// /<bot_username>?startgroup=<parameter>
|
||||||
return td::make_unique<InternalLinkBotStartInGroup>(std::move(username), arg.second);
|
// /<bot_username>?startgroup=<parameter>&admin=change_info+delete_messages+restrict_members
|
||||||
|
// /<bot_username>?startgroup&admin=change_info+delete_messages+restrict_members
|
||||||
|
auto administrator_rights = get_administrator_rights(url_query.get_arg("admin"), false);
|
||||||
|
return td::make_unique<InternalLinkBotStartInGroup>(std::move(username), arg.second,
|
||||||
|
std::move(administrator_rights));
|
||||||
}
|
}
|
||||||
if (arg.first == "startchannel") {
|
if (arg.first == "startchannel") {
|
||||||
// /<bot_username>?startchannel&admin=change_info+post_messages+promote_members
|
// /<bot_username>?startchannel&admin=change_info+post_messages+promote_members
|
||||||
|
@ -117,8 +117,10 @@ TEST(Link, parse_internal_link) {
|
|||||||
auto bot_start = [](const td::string &bot_username, const td::string &start_parameter) {
|
auto bot_start = [](const td::string &bot_username, const td::string &start_parameter) {
|
||||||
return td::td_api::make_object<td::td_api::internalLinkTypeBotStart>(bot_username, start_parameter);
|
return td::td_api::make_object<td::td_api::internalLinkTypeBotStart>(bot_username, start_parameter);
|
||||||
};
|
};
|
||||||
auto bot_start_in_group = [](const td::string &bot_username, const td::string &start_parameter) {
|
auto bot_start_in_group = [](const td::string &bot_username, const td::string &start_parameter,
|
||||||
return td::td_api::make_object<td::td_api::internalLinkTypeBotStartInGroup>(bot_username, start_parameter);
|
td::td_api::object_ptr<td::td_api::chatAdministratorRights> &&administrator_rights) {
|
||||||
|
return td::td_api::make_object<td::td_api::internalLinkTypeBotStartInGroup>(bot_username, start_parameter,
|
||||||
|
std::move(administrator_rights));
|
||||||
};
|
};
|
||||||
auto change_phone_number = [] {
|
auto change_phone_number = [] {
|
||||||
return td::td_api::make_object<td::td_api::internalLinkTypeChangePhoneNumber>();
|
return td::td_api::make_object<td::td_api::internalLinkTypeChangePhoneNumber>();
|
||||||
@ -640,14 +642,31 @@ TEST(Link, parse_internal_link) {
|
|||||||
parse_internal_link("t.me//username?start=", nullptr);
|
parse_internal_link("t.me//username?start=", nullptr);
|
||||||
parse_internal_link("https://telegram.dog/tele%63ram?start=t%63st", bot_start("telecram", "tcst"));
|
parse_internal_link("https://telegram.dog/tele%63ram?start=t%63st", bot_start("telecram", "tcst"));
|
||||||
|
|
||||||
parse_internal_link("tg:resolve?domain=username&startgroup=aasdasd", bot_start_in_group("username", "aasdasd"));
|
parse_internal_link("tg:resolve?domain=username&startgroup=aasdasd",
|
||||||
parse_internal_link("TG://resolve?domain=username&startgroup=", bot_start_in_group("username", ""));
|
bot_start_in_group("username", "aasdasd", nullptr));
|
||||||
|
parse_internal_link("TG://resolve?domain=username&startgroup=", bot_start_in_group("username", "", nullptr));
|
||||||
parse_internal_link("TG://test@resolve?domain=username&startgroup=", nullptr);
|
parse_internal_link("TG://test@resolve?domain=username&startgroup=", nullptr);
|
||||||
parse_internal_link("tg:resolve:80?domain=username&startgroup=", nullptr);
|
parse_internal_link("tg:resolve:80?domain=username&startgroup=", nullptr);
|
||||||
parse_internal_link("tg:http://resolve?domain=username&startgroup=", nullptr);
|
parse_internal_link("tg:http://resolve?domain=username&startgroup=", nullptr);
|
||||||
parse_internal_link("tg:https://resolve?domain=username&startgroup=", nullptr);
|
parse_internal_link("tg:https://resolve?domain=username&startgroup=", nullptr);
|
||||||
parse_internal_link("tg:resolve?domain=&startgroup=", unknown_deep_link("tg://resolve?domain=&startgroup="));
|
parse_internal_link("tg:resolve?domain=&startgroup=", unknown_deep_link("tg://resolve?domain=&startgroup="));
|
||||||
parse_internal_link("tg:resolve?domain=telegram&&&&&&&startgroup=%30", bot_start_in_group("telegram", "0"));
|
parse_internal_link("tg:resolve?domain=telegram&&&&&&&startgroup=%30", bot_start_in_group("telegram", "0", nullptr));
|
||||||
|
|
||||||
|
parse_internal_link("tg:resolve?domain=username&startgroup", bot_start_in_group("username", "", nullptr));
|
||||||
|
parse_internal_link("tg:resolve?domain=username&startgroup&admin=asdas", bot_start_in_group("username", "", nullptr));
|
||||||
|
parse_internal_link("tg:resolve?domain=username&startgroup&admin=post_messages",
|
||||||
|
bot_start_in_group("username", "", nullptr));
|
||||||
|
parse_internal_link(
|
||||||
|
"tg:resolve?domain=username&startgroup=1&admin=delete_messages+anonymous",
|
||||||
|
bot_start_in_group("username", "1",
|
||||||
|
td::td_api::make_object<td::td_api::chatAdministratorRights>(
|
||||||
|
true, false, false, false, true, false, false, false, false, false, true)));
|
||||||
|
parse_internal_link(
|
||||||
|
"tg:resolve?domain=username&startgroup&admin=manage_chat+change_info+post_messages+edit_messages+delete_messages+"
|
||||||
|
"invite_users+restrict_members+pin_messages+promote_members+manage_video_chats+anonymous",
|
||||||
|
bot_start_in_group("username", "",
|
||||||
|
td::td_api::make_object<td::td_api::chatAdministratorRights>(
|
||||||
|
true, true, false, false, true, true, true, true, true, true, true)));
|
||||||
|
|
||||||
parse_internal_link("tg:resolve?domain=username&startchannel", public_chat("username"));
|
parse_internal_link("tg:resolve?domain=username&startchannel", public_chat("username"));
|
||||||
parse_internal_link("tg:resolve?domain=username&startchannel&admin=", public_chat("username"));
|
parse_internal_link("tg:resolve?domain=username&startchannel&admin=", public_chat("username"));
|
||||||
@ -661,14 +680,31 @@ TEST(Link, parse_internal_link) {
|
|||||||
bot_add_to_channel("username", td::td_api::make_object<td::td_api::chatAdministratorRights>(
|
bot_add_to_channel("username", td::td_api::make_object<td::td_api::chatAdministratorRights>(
|
||||||
true, true, true, true, true, true, true, false, true, true, false)));
|
true, true, true, true, true, true, true, false, true, true, false)));
|
||||||
|
|
||||||
parse_internal_link("t.me/username/0/a//s/as?startgroup=", bot_start_in_group("username", ""));
|
parse_internal_link("t.me/username/0/a//s/as?startgroup=", bot_start_in_group("username", "", nullptr));
|
||||||
parse_internal_link("t.me/username/aasdas?test=1&startgroup=#12312", bot_start_in_group("username", ""));
|
parse_internal_link("t.me/username/aasdas?test=1&startgroup=#12312", bot_start_in_group("username", "", nullptr));
|
||||||
parse_internal_link("t.me/username/0?startgroup=", bot_start_in_group("username", ""));
|
parse_internal_link("t.me/username/0?startgroup=", bot_start_in_group("username", "", nullptr));
|
||||||
parse_internal_link("t.me/username/-1?startgroup=asdasd", bot_start_in_group("username", "asdasd"));
|
parse_internal_link("t.me/username/-1?startgroup=asdasd", bot_start_in_group("username", "asdasd", nullptr));
|
||||||
parse_internal_link("t.me/username?startgroup=", bot_start_in_group("username", ""));
|
parse_internal_link("t.me/username?startgroup=", bot_start_in_group("username", "", nullptr));
|
||||||
parse_internal_link("t.me/username#startgroup=asdas", public_chat("username"));
|
parse_internal_link("t.me/username#startgroup=asdas", public_chat("username"));
|
||||||
parse_internal_link("t.me//username?startgroup=", nullptr);
|
parse_internal_link("t.me//username?startgroup=", nullptr);
|
||||||
parse_internal_link("https://telegram.dog/tele%63ram?startgroup=t%63st", bot_start_in_group("telecram", "tcst"));
|
parse_internal_link("https://telegram.dog/tele%63ram?startgroup=t%63st",
|
||||||
|
bot_start_in_group("telecram", "tcst", nullptr));
|
||||||
|
|
||||||
|
parse_internal_link("t.me/username?startgroup", bot_start_in_group("username", "", nullptr));
|
||||||
|
parse_internal_link("t.me/username?startgroup&admin=asdas", bot_start_in_group("username", "", nullptr));
|
||||||
|
parse_internal_link("t.me/username?startgroup&admin=post_messages", bot_start_in_group("username", "", nullptr));
|
||||||
|
parse_internal_link(
|
||||||
|
"t.me/username?startgroup=1&admin=delete_messages+anonymous",
|
||||||
|
bot_start_in_group("username", "1",
|
||||||
|
td::td_api::make_object<td::td_api::chatAdministratorRights>(
|
||||||
|
true, false, false, false, true, false, false, false, false, false, true)));
|
||||||
|
parse_internal_link(
|
||||||
|
"t.me/"
|
||||||
|
"username?startgroup&admin=manage_chat+change_info+post_messages+edit_messages+delete_messages+invite_users+"
|
||||||
|
"restrict_members+pin_messages+promote_members+manage_video_chats+anonymous",
|
||||||
|
bot_start_in_group("username", "",
|
||||||
|
td::td_api::make_object<td::td_api::chatAdministratorRights>(
|
||||||
|
true, true, false, false, true, true, true, true, true, true, true)));
|
||||||
|
|
||||||
parse_internal_link("t.me/username?startchannel", public_chat("username"));
|
parse_internal_link("t.me/username?startchannel", public_chat("username"));
|
||||||
parse_internal_link("t.me/username?startchannel&admin=", public_chat("username"));
|
parse_internal_link("t.me/username?startchannel&admin=", public_chat("username"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user