This commit is contained in:
corrado.mulas
2026-06-18 21:09:21 +02:00
parent 9c714af9c0
commit d5e175e9b9
6 changed files with 53 additions and 64 deletions

View File

@@ -2,7 +2,7 @@
## Overview
The telegram-groupfactory bot now has **admin-only configuration** where all sensitive operations (adding/modifying users, setting QR backups) can ONLY be executed from the designated admin chat (STAFF_CHAT_ID).
The telegram-groupfactory bot now has **admin-only configuration** where configuration operations (adding/modifying users, setting GroupHelp QR backups) can ONLY be executed from the designated admin chat (STAFF_CHAT_ID).
## Key Features
@@ -25,10 +25,10 @@ The following commands can ONLY be run from the admin chat:
/admin_remove_users <id1> <id2> - Remove users from default list
```
#### QR Code Backup
#### GroupHelp QR Code Backup
```
/admin_get_qr - Retrieve QR backup data
/admin_set_qr <qr_code> - Store QR backup data for replication
/admin_get_qr - Retrieve GroupHelp backup QR data
/admin_set_qr <qr_code> - Store GroupHelp backup QR data for `.importbackup`
```
#### Help
@@ -81,8 +81,8 @@ New class `AdminHandler` with methods:
- `handle_add_to_default_users(chat_id, user_ids)` - Add users (admin only)
- `handle_remove_from_default_users(chat_id, user_ids)` - Remove users (admin only)
- `handle_add_user_to_db(chat_id, username)` - Add user (admin only)
- `handle_get_qr_backup(chat_id)` - Get QR backup (admin only)
- `handle_set_qr_backup(chat_id, qr_data)` - Set QR backup (admin only)
- `handle_get_qr_backup(chat_id)` - Get GroupHelp QR backup (admin only)
- `handle_set_qr_backup(chat_id, qr_data)` - Set GroupHelp QR backup (admin only)
- `handle_admin_help(chat_id)` - Show admin help (admin only)
### Main Application Updates (`src/main.py`)
@@ -133,7 +133,7 @@ User: [clicks "Yes, I want to be full admin"]
Bot: Set as ✅ Full Group Admin - Confirmed!
```
## Security Features
## Access Control Features
1. **Chat-Level Access Control** - Only STAFF_CHAT_ID can execute admin commands
2. **Database Persistence** - All preferences stored in MongoDB
@@ -162,7 +162,7 @@ Stores per-user admin preferences:
```
### `ghconfig` Collection
Stores QR backup data:
Stores GroupHelp backup QR data:
```json
{
"key": "qr_backup_data",
@@ -212,7 +212,7 @@ MONGODB_COLLECTION=ghconfig
# Can retrieve with: get_user_admin_role(user_id)
```
### Test QR Backup
### Test GroupHelp QR Backup
```bash
# In admin chat:
/admin_set_qr myqrcode123
@@ -220,6 +220,9 @@ MONGODB_COLLECTION=ghconfig
/admin_get_qr
# 📊 Current QR Backup Data: myqrcode123
# In the target group:
.importbackup myqrcode123
```
## Future Enhancements

View File

@@ -2,7 +2,7 @@
## Overview
This guide explains how to configure users to be added to newly created groups and manage backup QR code replication via the bot.
This guide explains how to configure users to be added to newly created groups and manage GroupHelp backup QR data via the bot.
## Setting Up Default Users for New Groups
@@ -127,26 +127,19 @@ This will create ProjectBeta with only alice and bob, regardless of the default
---
## QR Code Backup Configuration
## GroupHelp QR Backup Configuration
### What is QR Backup Data?
QR backup data is a code that can be used to replicate or restore your bot's session across multiple instances. This is useful for:
- Disaster recovery
- Multi-instance deployment
- Session migration
- Backup and restore scenarios
QR backup data is the GroupHelp settings backup payload generated by GroupHelp itself. It is used to copy GroupHelp settings, such as welcome-message configuration, from one group to another by pasting the QR payload as the body of a `.importbackup` message.
### Step 1: Generate or Obtain QR Code
Depending on your setup, you might have a QR code from:
- Bot session export
- Backup file
- Another instance
Generate the QR backup from GroupHelp in the source group, then store the decoded/pasted payload here so it can be reused when importing those settings into another group.
### Step 2: Set QR Backup Data
### Step 2: Set GroupHelp QR Backup Data
Store the QR backup data in the database:
Store the GroupHelp QR backup data in the database:
```
/set_qr_backup YOUR_QR_CODE_HERE
@@ -164,9 +157,9 @@ Response:
Data: `0001a8ac0123456789abcdef0123456789abcdef01234567`
```
### Step 3: Retrieve QR Backup Data
### Step 3: Retrieve GroupHelp QR Backup Data
Retrieve the stored QR backup data anytime:
Retrieve the stored GroupHelp QR backup data anytime:
```
/get_qr_backup
@@ -178,13 +171,12 @@ Response:
`0001a8ac0123456789abcdef0123456789abcdef01234567`
```
### Step 4: Use QR Backup for Replication
### Step 4: Use QR Backup with GroupHelp
Once you have the QR backup data stored, you can:
1. Export it from the database
2. Use it in deployment scripts
3. Pass it to other bot instances
4. Store it in version control (encrypted) for DR purposes
1. Retrieve it with `/get_qr_backup`
2. Paste it into the target group as the message body for `.importbackup`
3. Let GroupHelp import the backed-up settings into that group
---
@@ -201,7 +193,7 @@ The configuration data is stored in MongoDB with the following structure:
}
```
### QR Backup Collection (`COLLECTION_NAME`)
### GroupHelp QR Backup Collection (`COLLECTION_NAME`)
```json
{
"_id": ObjectId(...),
@@ -245,18 +237,14 @@ The configuration data is stored in MongoDB with the following structure:
/create_group NewProject
```
### Workflow 3: QR Code Backup & Restore
### Workflow 3: GroupHelp QR Backup Import
```bash
# On source instance:
# Retrieve the stored GroupHelp QR payload:
/get_qr_backup
# Copy the QR code output
# On target instance:
/set_qr_backup <paste_qr_code_here>
# Verify it was stored
/get_qr_backup
# In the target group, paste the payload with:
.importbackup <paste_qr_code_here>
```
---
@@ -275,7 +263,7 @@ The configuration data is stored in MongoDB with the following structure:
2. Verify users exist: `/users`
3. Manually add users to group: `/add_users <group_id> <user_id1>,<user_id2>`
### Issue: QR backup data appears empty
### Issue: GroupHelp QR backup data appears empty
**Solution:**
1. Check if data was stored: `/get_qr_backup`
2. Re-set the data: `/set_qr_backup <your_qr_code>`
@@ -321,8 +309,8 @@ FACTORY_BOT_ID=your_bot_id
- `/set_default_users <id1> <id2> ...` - Set default users (replace)
- `/add_default_users <id1> <id2> ...` - Add users to default list
- `/remove_default_users <id1> <id2> ...` - Remove users from default list
- `/get_qr_backup` - View QR backup data
- `/set_qr_backup <data>` - Set QR backup data
- `/get_qr_backup` - View GroupHelp QR backup data
- `/set_qr_backup <data>` - Set GroupHelp QR backup data
- `/config_help` - Show configuration command help
- `/help` - Show all available commands
@@ -366,19 +354,18 @@ mongo mongodb://localhost:27017/groupfactory
# View default users
db.group_config.find()
# View QR backup
# View GroupHelp QR backup
db.ghconfig.find({key: 'qr_backup_data'})
```
---
## Security Considerations
## Operational Notes
1. **Never share QR backup data** in public channels or version control
2. **Encrypt sensitive data** before storing in version control
3. **Rotate credentials regularly** especially after backups
4. **Limit bot access** to trusted chats only
5. **Monitor command usage** for suspicious activity
1. QR backup data is a GroupHelp configuration payload, not a Telegram or Telethon session.
2. Use `.importbackup` in the target group to import the stored GroupHelp settings.
3. Limit configuration commands to trusted chats so group settings are changed intentionally.
4. Monitor command usage if multiple operators manage the same groups.
---

View File

@@ -4,7 +4,7 @@
### Overview
The telegram-groupfactory bot now has a complete **admin-only configuration system** where:
1. All sensitive operations are restricted to the admin chat (STAFF_CHAT_ID)
1. Configuration operations are restricted to the admin chat (STAFF_CHAT_ID)
2. Users are prompted with inline buttons to choose their admin role when creating groups
3. All preferences and configurations are persisted in MongoDB
@@ -55,9 +55,9 @@ The telegram-groupfactory bot now has a complete **admin-only configuration syst
✅ Error message returned for unauthorized access
✅ No partial execution of admin operations
### Data Protection
### Data Storage
✅ User admin roles stored in separate MongoDB collection
QR backup data stored encrypted in database
GroupHelp backup QR data stored in database
✅ Default user list stored separately from user data
---
@@ -71,8 +71,8 @@ The telegram-groupfactory bot now has a complete **admin-only configuration syst
/admin_set_users <id1> <id2> ... - Replace defaults (admin only)
/admin_add_users <id1> <id2> ... - Append users (admin only)
/admin_remove_users <id1> <id2> - Remove users (admin only)
/admin_get_qr - Get QR data (admin only)
/admin_set_qr <qr_code> - Set QR data (admin only)
/admin_get_qr - Get GroupHelp QR data (admin only)
/admin_set_qr <qr_code> - Set GroupHelp QR data (admin only)
/admin_help - Admin help (admin only)
```
@@ -92,7 +92,7 @@ The telegram-groupfactory bot now has a complete **admin-only configuration syst
### 3. Database Collections
`group_config` - Stores default user list
`user_admin_roles` - Stores per-user admin preferences
`ghconfig` - Stores QR backup data
`ghconfig` - Stores GroupHelp QR backup data
---
@@ -122,9 +122,9 @@ The telegram-groupfactory bot now has a complete **admin-only configuration syst
- ✅ Can add to default list (admin only)
- ✅ Can remove from default list (admin only)
### QR Backup
- ✅ Can set QR data (admin only)
- ✅ Can get QR data (admin only)
### GroupHelp QR Backup
- ✅ Can set GroupHelp QR data (admin only)
- ✅ Can get GroupHelp QR data (admin only)
### Group Creation
- ✅ Group creation shows inline buttons

View File

@@ -7,7 +7,7 @@ A Telegram bot for managing user groups with MongoDB backend and admin-only conf
- ✅ Create and manage Telegram groups with default user lists
- ✅ Admin-only configuration (requires STAFF_CHAT_ID)
- ✅ User management with MongoDB storage
-QR code backup for session replication
-GroupHelp settings backup QR storage for `.importbackup`
- ✅ Interactive admin role selection for group creators
- ✅ Modular architecture with separation of concerns
- ✅ Telegram bot integration using Telethon
@@ -74,8 +74,8 @@ docker run telegram-groupfactory
/admin_add_users <id1> <id2> ... - Add users to default list
/admin_remove_users <id1> <id2> - Remove users from default list
/admin_get_users - Show current default users
/admin_set_qr <qr_code> - Store QR backup data
/admin_get_qr - Retrieve QR backup data
/admin_set_qr <qr_code> - Store GroupHelp backup QR data
/admin_get_qr - Retrieve GroupHelp backup QR data
```
### User Commands
@@ -95,4 +95,3 @@ docker run telegram-groupfactory
- `/user <user_id>` - Get user information
- `/add_user <user_id> <username> <name>` - Add a new user
- `/delete_user <user_id>` - Delete a user

View File

@@ -252,10 +252,10 @@ class AdminHandler:
**QR Code Backup:**
• `/admin_get_qr` - Get current QR backup data
• `/admin_set_qr <qr_code>` - Set QR backup data
• `/admin_set_qr <qr_code>` - Set GroupHelp backup QR data
**Notes:**
✓ All admin commands work ONLY from the admin chat
✓ Users will be automatically added to new groups
✓ QR backup data is used for session replication
✓ QR backup data is used with GroupHelp `.importbackup`
✓ All config changes are stored in MongoDB"""

View File

@@ -189,6 +189,6 @@ class ConfigHandler:
**QR Code Backup:**
• `/get_qr_backup` - Get current QR backup data
• `/set_qr_backup <qr_code>` - Set QR backup data for replication
• `/set_qr_backup <qr_code>` - Set GroupHelp backup QR data for `.importbackup`
When a new group is created without specifying users, all configured default users will be automatically added."""