-
Notifications
You must be signed in to change notification settings - Fork 0
Config
This page provides the documentation of the Config class, which serves as a configuration handler for Matrix client settings. It explains the purpose of the class, its constructor parameters, and common usage patterns. Use this documentation to understand how to integrate and customize the Config class within your own matrix.py based bot.
The Config class centralizes all configuration related to connecting and authenticating with a Matrix server. It supports:
- Your homeserver or a default homeserver URL (https://matrix.org)
- User identification via Matrix user ID (username)
- Authentication through either a password or an access token
- A command prefix for bot interactions (default: !)
- Loading settings from a YAML file
In essence, you can either supply settings directly via keyword arguments when instantiating Config, or keep them in a YAML file and load them at runtime. If both are provided, values passed via **kwargs will act as defaults until overridden by the YAML file.
Below are two common patterns for instantiating and configuring your bot. The first example loads the settings from a YAML file through the Bot instance, and the second example uses keyword arguments directly through the Bot instance.
from matrixpy import Bot, Config
# 1st way
bot = Bot('examples/config.yaml')
# 2nd way
bot = Bot(username="@my-bot:matrix.org", password="my_secure_password")Note
By default, homeserver is https://matrix.org. If you run your own Matrix instance, make sure to override this to avoid unexpected behavior.
If you are using a YAML file to load your settings, your file would look like this:
HOMESERVER: "your_matrix_homeserver(default to https://matrix.org)"
USERNAME: "your_bot_username"
PASSWORD: "your_Password"
TOKEN: "your_optional_token" # If you prefer tokens over passwords
PREFIX: "your_custom_prefix(default to !)"Important
If neither PASSWORD nor TOKEN is supplied (either via kwargs or YAML), your bot will fail to log into Matrix.