-
-
Notifications
You must be signed in to change notification settings - Fork 964
User Authorized Feature #424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Doing something like this before initializing the bot can do the same thing: $POST = file_get_contents("php://input");
$POST_DATA = json_decode($POST, true);
$user_id = null;
if (isset($POST_DATA['callback_query']['from']['id'])) {
$user_id = $POST_DATA['callback_query']['from']['id'];
} elseif (isset($POST_DATA['inline_query']['from']['id'])) {
$user_id = $POST_DATA['inline_query']['from']['id'];
} elseif (isset($POST_DATA['chosen_inline_result']['from']['id'])) {
$user_id = $POST_DATA['chosen_inline_result']['from']['id'];
} elseif (isset($POST_DATA['message']['from']['id'])) {
$user_id = $POST_DATA['message']['from']['id'];
} elseif (isset($POST_DATA['edited_message']['from']['id'])) {
$user_id = $POST_DATA['edited_message']['from']['id'];
} elseif (isset($POST_DATA['channel_post']['from']['id'])) {
$user_id = $POST_DATA['channel_post']['from']['id'];
} elseif (isset($POST_DATA['edited_channel_post']['from']['id'])) {
$user_id = $POST_DATA['edited_channel_post']['from']['id'];
}
if(!is_null($user_id) {
//query the db with smth like SELECT FROM `whitelist` WHERE `id` = ' . $user_id
// and if no records are found simply exit; and the request will be ignored!
} |
@DragoGold Welcome to GitHub!! Great to have you here contributing 😃 I really like the idea of a more detailed authorisation process, allow more customisations to the bot and its commands. For example: user1 can execute A, B and C, user2 can only execute B, everyone else can't do anything. Borrowing from the way WordPress implements this, a This wouldn't require any database changes, but it would be possible to save it there too. @jacklul A great and simple approach 👍 (semi off topic, @jacklul your code can be optimised and prettified quite a bit) |
@noplanman thanks for your welcome message!
For that reason I added the "profile" field in the new table. Now, for my business, I'm customizing the library but I'm not a master in PHP and I'm pretty sure that my code it's not clean and OO like your code. Thanks |
No problem at all 😃 @jacklul @MBoretto @akalongman What do you think about this? |
guys, this is a great idea with a more detailed authorisation! |
Required Information
I would like to suggest you a new feature: "user access grant".
Only the users enabled can access to the BOT commands.
For the backward compatibility with your code I create a new table (user_profile) with the user_id, isEnable flag (Y/N), profile (future use).
Change in DB.php:
in the "insertUser" method I add the user profile (INSERT INTO user_profile table) with the default values: isEnable = 'N' and profile = NULL
I create a new method "isUserEnable" input param "user_id" and returned value a boolean. Select the "isEnable" and if "Y" return true, else false.
Change in Telegram.php:
processUpdate method, before the "executeCommand" check the user permission with the call of DB method "isUserEnable". If enabled execute the command, if not message with "user not allowed" or something like that.
The text was updated successfully, but these errors were encountered: