Matrix Admin Bot is a command-line bot for Matrix server administration tasks.
!server_notice- Send server notices to users!reset_password- Reset user passwords!deactivate- Deactivate user accounts!reactivate- Reactivate user accounts!ping- Ask all bots to reply to this command!account_validity- Manage account validity periods (needsemail_account_validitymodule)!room_details- Return the details of a room!room_state- Return the state of a room!lock- Locks a user!unlock- Unlocks a user!add_email- Adds an email to user with mxid!remove_email- Removes an email from a user!memberships- Gets the room memberships of users
The bot is configured using a TOML file (config.toml). Here's an explanation of the available configuration options:
homeserver = "http://127.0.0.1:8008" # Matrix homeserver URL
identity_server = "http://127.0.0.1" # Identity server URL
bot_username = "admin" # Bot username
bot_password = "***" # Bot password
mas_base_url = "http://127.0.0.1:8080" # Matrix Authentication Service URL
mas_access_token = "***" # Matrix Authentication Service PAT to access Admin API
# Set to true for the primary bot instance
# Set to false for secondary instances if you have multiple bots in one admin room
is_coordinator = true
# List of room IDs where the bot is allowed to operate
# If no rooms is specified, any room can be used
allowed_room_ids = [
"!tBprUmUcgXAdErtpA:example.org",
]The bot uses TOTP (Time-based One-Time Password) for secure authentication. You need to specify a TOTP seed per user. Only users with a TOTP defined are allowed to use the bot.
[totps]
"@john:example.org" = "AAAAAAAABBBBBBBBCCCCCCCCDDDDDDDD"
"@jack:example.org" = "EEEEEEEEFFFFFFFFGGGGGGGGHHHHHHHH"Configure user roles to control access to commands:
# If no roles are defined, all users defined in `totps` have access to all commands
# Admin role with access to all commands
[roles.admin]
all_commands = true
user_ids = ["@john:example.org"]
# Limited role with access to specific commands only
[roles.resetpwdonly]
allowed_commands = ["ResetPasswordCommand"]
user_ids = ["@jack:example.org"]
# Limited role where other users can interact with the command
# Useful for bots
[roles.bot]
allowed_commands = ["ResetPasswordCommand"]
allow_other_users_interaction = true
user_ids = ["@bot:example.org"]The bot is available as a Docker image at ghcr.io/tchapgouv/matrix-admin-bot.
docker run --rm --name matrix-admin-bot \
--mount type=bind,src="/path/to/data/folder",dst="/data" \
--network=host \
ghcr.io/tchapgouv/matrix-admin-bot:latestNotes:
- Mount your local configuration directory to
/datainside the container - The container expects
config.tomlto be in the mounted/datadirectory - Use
--network=hostwhen your configuration referenceslocalhostor127.0.0.1 - For production use, consider setting a specific version tag instead of
latest
Once the bot is running and joined to an authorized room:
- Invoke a command with the proper syntax (e.g.,
!server_notice) - Follow the interactive prompts to complete the action
- Authenticate with your TOTP code when requested
For detailed command help, use the help parameter (e.g., !server_notice help)
This project is managed by uv.
Please proceed to the installation of uv https://docs.astral.sh/uv/getting-started/installation/
uv sync
source .venv/bin/activateuv run --frozen pytest --covuv run --frozen basedpyright
uv run --frozen ruff checkuv run --frozen ruff format