Project

General

Profile

Actions

Feature #3175

open

Telegram community roles and external roles

Added by Gregory Magarshak 6 months ago.

Status:
New
Priority:
Normal
Start date:
11/24/2024
Due date:
12/19/2024 (about 5 months late)
% Done:

0%

Estimated time:
10.00 h

Description

We want to have a similar approach to Telegram and Web3 platforms. Just as a "CommunityContract" instance on a specific web3 appId (chain) should correspond to a Qbix community, so a Telegram Chat with a specific appId (bot) should correspond to a Qbix community.

Qbix communities are users whose ids start with a capital letter. Please see more here:

https://issues.qbix.com/projects/telegram/wiki/Telegram_Plugin#TELEGRAM-CHATROOMS-THEMSELVES

1) When a bot joins a chat, please use the corresponding update to create a corresponding community in Qbix. The title of the chat should become the name of the community, and the chat_id of the chat should be its xid, you should create a Users_ExternalFrom (which automatically creates a Users_ExternalTo) with platform=telegram, appId=bot, xid=chat_id for that community. The userId of the community should be "Telegram_$chat_id".

2) The community should fetchOrCreate a stream named "Telegram/chat/$chat_id".

3) Call getChatAdministrators in Telegram Bot API and import all the chat administrators as futureUsers using the standard import mechanism of Users_ExternalFrom. Make sure the administrators can authenticate later to adopt these users, see authentication issue . Please add "Telegram/admins" role in the community, to all of these futureUsers. (Insert Users_Label rows using Users_Label::insertManyAndExecute()).

4) Please make a public const PHP array Telegram::$ADMIN_RIGHTS (similar to Streams::$READ_LEVEL) with keys taken from here and values are just true

5) Read the result of getChatAdministrators and see what combinations of rights people have, and also their "custom_title". For each combination / custom title, create a new role (if it doesn't already exist) and give it a name. The icon of the role would be just the Telegram/admins icon (I will make it like Calendars/admins icon {{Calendars}}/img/icons/Calendars/labels/admins). The title would be the custom_title.

6) Create Streams_Access rows with insertManyAndExecute, for this stream, and the roles, with permissions being a JSON array of "administrator rights" in Telegram.

7) The Telegram plugin should add a "before" hook to Users_Label::addLabel() and Users_label::removeLabel(), so that whenever a role is added/removed, you should $stream->calculateAccess(['recalculate' => true]) and get all the permissions with $stream->get('permissions'). Then get the current permissions in the chat, and attempt to add/remove the corresponding permissions in Telegram, to that user, in that chat, using the bot. If a user was not an administrator, try to make them one. If the user was an administrator but all permissions are removed, try to remove user from being administrator. If the bot API responds with an error, then throw @Users_Exception_NotAuthorized for example. This will abort the adding/removing of the label in our database. Otherwise, the permissions will be changed, and the label will be added/removed.

8) One of the admins is a chat member owner whose status is "creator". For them, always add a Users/owners role. Allow Users/owners of the community to create new types of roles in the Telegram_$userId community, and set the permissions of those roles from the standard list. Then, allow some roles to appoint other roles

9) Make a command that the bot can understand, "/roles username which cause it to sendMessage to the chat with all the roles that the given user currently has.

This allows managing the admins and roles in a chat, similarly to how we have an interface for managing web3 roles.

No data to display

Actions

Also available in: Atom PDF