etalab-ia / albert-tchap

Bot for Tchap (the messaging app of the French State) using Albert, the French administration Artificial Intelligence agent
MIT License
13 stars 1 forks source link

Feat/users whitelist #62

Closed bolinocroustibat closed 4 months ago

bolinocroustibat commented 5 months ago

Related issue: https://github.com/etalab-ia/albert-tchapbot/issues/54

For the beta, each user shuld be able to join the private room with Albert, be must be individually approved one by one to access the beta to be able to talk to the bot, and received information message if they are not yet approved.

For that: 1) Removed JOIN_ON_INVITE logic since all users join automatically 2) we need persistent storage (even if the bot has been stopped and restarted / redeployed) to have persistent info about:

In this PR, those three informations for each users are stored in a simple users.json file for now, structured like this:

{
    "@user-tchap-id-1": {
        "authorized": false,
        "has_activity": false
    },
    "@user-tchap-id-2": {
        "authorized": true,
        "has_activity": false
    }
}

When a user joins and starts talking to the bot, he will be added to that file as a pending user, with "authorized": false and "has_activity": false.

This file is loaded (or created) on the launch of the bot and the data is cached as a Python dict in the field users of the BotLibConfig instance.

To check if he user is authorized, we use a new is_authorized field. If empty, we read from the users field.. When updating that field, we also re-save the file for persistent info.

To check if it's the first time the user talks with the bot (so that we can know if we send the welcome message), we use that existing last_activity field. If empty, we read from the users field. When updating the last activity, if there were none before, we also update the file.