Multi-Chat Authorization¶
BamDude's Telegram bot supports multiple chats with independent authorization, role-based permissions, and registration control.
Overview¶
Each Telegram chat (private or group) is linked to a BamDude group (role). This provides:
- Per-chat permissions -- Different chats can have different access levels
- Notification routing -- Each chat receives only the events it's subscribed to
- Quiet hours -- Per-chat quiet hour configuration
- Registration control -- Control how new chats are authorized
Chat Management¶
Manage Telegram chats in the web UI at Settings > Notifications > Telegram Chats.
Chat Properties¶
| Property | Description |
|---|---|
| Chat ID | Telegram chat identifier (auto-detected) |
| Chat Name | Display name |
| Group | BamDude group (role) assignment |
| Notification Events | Which events this chat receives |
| Quiet Hours | Time window to suppress notifications |
| Daily Digest | Receive a summary instead of individual messages |
| Active | Enable/disable the chat |
Permission Gating¶
The bot middleware checks permissions before executing commands:
- User sends a command or taps an inline button
- Middleware looks up the chat's group
- Checks if the group has the required permission
- Allows or denies the action
A chat's printers are those on its own printer list that its group reaches, when the group is limited to printers (Printer access); the linked user adds nothing. A chat limited to printers — by its list or by its group — does not add Auto Queue jobs: it queues to a printer it reaches. Its daily digest lists the events of those printers and the events of no printer.
Permission Examples¶
| Action | Required Permission |
|---|---|
| View printers | printers:read |
| Control printers | printers:control |
| Start prints | queue:create |
| View queue | queue:read |
| Manage maintenance | settings:update |
Registration: open vs. closed¶
A single boolean — telegram_registration_open (Settings → Notifications → Telegram) — controls how new chats appear:
| Setting | Behaviour |
|---|---|
telegram_registration_open=true |
Unknown chats that message the bot are auto-registered with is_active=False, group_id=NULL. They cannot do anything yet — an admin still has to assign a group and flip them active in Settings → Notifications → Telegram Chats. Effectively a "let me see who wants in" mode. |
telegram_registration_open=false (default) |
Unknown chats are silently rejected. To let a new chat in, an admin adds it manually in the web UI — except the very first chat of a newly added bot, which is registered pending approval. |
There is no third "open with auto-active default group" mode — neither option auto-grants permissions. Activation is always a manual step in the web UI.
A chat belongs to the bot it wrote to. A chat in Telegram exists for one bot only — the one you pressed Start in — and BamDude records which Telegram provider (which bot token) that was. Each provider's card lists its own chats, a chat added from a card is registered under that provider, and a provider's notifications and daily digest go to its own chats and to no other's. Deleting a Telegram provider removes its chats with it.
Several bots, several sets of chats. Every switched-on Telegram provider is a bot of its own, and each has its own chats. Telegram identifies a private chat by the person's own user id, the same number in every bot they use — so the same person talking to two of your bots is two chats in BamDude, each with its own role, printer scope and notification choices. Activating them is a separate step in each. A bot that has no chats yet registers its first one the way the very first setup does, whatever the registration switch says: whoever presses Start on a brand-new bot first is the person setting it up.
One token, one provider. The token identifies the bot, so two providers holding the same token would be the same bot twice — which Telegram refuses to serve. Saving a provider with a token another one already has is turned down, and an installation that already carried such a pair keeps the older provider and switches the younger one off, moving its chats across.
Auth Middleware¶
The auth middleware (telegram_handlers/auth_middleware.py) runs on every message and callback:
- Checks if the chat exists in the
telegram_chatstable. - If new and
telegram_registration_open=true: inserts a row withis_active=False, group_id=NULLand silently drops the message — the chat will only become functional after an admin activates + assigns a group in the web UI. - If new and
telegram_registration_open=false: rejects the message outright. - Loads the chat's group and permissions.
- Injects permissions into the handler context.
- Handler checks required permissions before acting.
Per-Chat Notifications¶
Each chat can subscribe to different notification events:
- Print events -- complete, failed, progress
- Queue events -- added, started, waiting, complete
- System events -- printer offline, HMS errors, maintenance due
Configure in the web UI per chat.
Tips¶
Admin Chat
Set up a private chat with the Administrators group for full control, and a group chat with Viewers group for monitoring.
Quiet Hours
Set quiet hours per chat to avoid notifications during off-hours. The daily digest will summarize missed events.
Revoking Access
To revoke a chat's access, either delete it from the web UI or set it to inactive. The bot will stop responding to that chat.