Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions telegram-bot-api/ClientManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ void ClientManager::send(PromisedQueryPtr query) {
if (user_id <= 0 || user_id >= (static_cast<td::int64>(1) << 54)) {
return fail_query(401, "Unauthorized: invalid token specified", std::move(query));
}
const auto &allowed_bot_user_ids = parameters_->allowed_bot_user_ids_;
if (!allowed_bot_user_ids.empty() &&
std::find(allowed_bot_user_ids.begin(), allowed_bot_user_ids.end(), user_id) == allowed_bot_user_ids.end()) {
return fail_query(401, "Unauthorized: bot is not allowed to use the server", std::move(query));
}

if (query->is_test_dc()) {
token += "/test";
Expand Down
2 changes: 2 additions & 0 deletions telegram-bot-api/ClientParameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ struct ClientParameters {

td::string version_;

td::vector<td::int64> allowed_bot_user_ids_; // empty means that all bots are allowed

td::int32 default_max_webhook_connections_ = 0;
td::IPAddress webhook_proxy_ip_address_;

Expand Down
13 changes: 13 additions & 0 deletions telegram-bot-api/telegram-bot-api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,19 @@ int main(int argc, char *argv[]) {
token_range = {rem_i, mod_i};
return td::Status::OK();
});
options.add_checked_option('\0', "allowed-bot-ids",
"comma-separated list of bot user identifiers that are allowed to use the server. By "
"default, all bots are allowed",
[&](td::Slice ids) -> td::Status {
for (auto id_str : td::full_split(ids, ',')) {
TRY_RESULT(user_id, td::to_integer_safe<td::int64>(id_str));
if (user_id <= 0) {
return td::Status::Error("Invalid bot user identifier specified");
}
parameters->allowed_bot_user_ids_.push_back(user_id);
}
return td::Status::OK();
});
options.add_checked_option('\0', "max-webhook-connections",
"default value of the maximum webhook connections per bot",
td::OptionParser::parse_integer(parameters->default_max_webhook_connections_));
Expand Down