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:
users who have asked for access (by starting a chat session with the bot)
users who have been approved
users who never talked with the bot before (so that the bot knows if it should send the welcome message or not sending it again)
In this PR, those three informations for each users are stored in a simple users.json file for now, structured like this:
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.
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: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 theBotLibConfig
instance.To check if he user is authorized, we use a new
is_authorized
field. If empty, we read from theusers
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 theusers
field. When updating the last activity, if there were none before, we also update the file.