Skip to content

Config

BasicAuthConfig pydantic-model

Bases: BaseModel

The configuration for username and password based authentication.

Fields:

Source code in src/signalbot/bot_config.py
class BasicAuthConfig(BaseModel):
    """The configuration for username and password based authentication."""

    type: Literal["basic"] = Field(
        default="basic", description="The type of authentication. Defaults to `basic`."
    )
    username: str = Field(description="The username for the authentication.")
    password: str = Field(description="The password used for authentication.")

password pydantic-field

password: str

The password used for authentication.

type pydantic-field

type: Literal['basic'] = 'basic'

The type of authentication. Defaults to basic.

username pydantic-field

username: str

The username for the authentication.

BearerAuthConfig pydantic-model

Bases: BaseModel

The configuration for token based authentication.

Fields:

Source code in src/signalbot/bot_config.py
class BearerAuthConfig(BaseModel):
    """The configuration for token based authentication."""

    type: Literal["bearer"] = Field(
        default="bearer",
        description="The type of authentication. Defaults to `bearer`.",
    )
    token: str = Field(description="The token used for authentication.")

token pydantic-field

token: str

The token used for authentication.

type pydantic-field

type: Literal['bearer'] = 'bearer'

The type of authentication. Defaults to bearer.

Config pydantic-model

Bases: BaseModel

The configuration for SignalBot.

Fields:

Source code in src/signalbot/bot_config.py
class Config(BaseModel):
    """The configuration for SignalBot."""

    phone_number: str = Field(description="The phone number of the bot.")
    signal_service: str = Field(
        default="localhost:8080",
        description="The URL of the `signal-cli-rest-api` service to connect to, "
        "without protocol.",
    )
    auth: BasicAuthConfig | BearerAuthConfig | None = Field(
        default=None,
        description="The authentication config used for http requests.",
    )
    storage: RedisConfig | SQLiteConfig | InMemoryConfig | None = Field(
        default=None, description="The configuration for the storage backend to use."
    )
    retry_interval: int = Field(
        default=1,
        description="The interval in seconds to wait before retrying a failed "
        "connection to the signal service.",
    )
    download_attachments: bool = Field(
        default=True,
        description="Whether to download attachments from messages.",
    )
    connection_mode: ConnectionMode = Field(
        default=ConnectionMode.AUTO,
        description="The connection mode to use when connecting to the Signal service.",
    )
    logging_level: int = Field(
        default=WARNING, description="The logging level for the bot."
    )

auth pydantic-field

auth: BasicAuthConfig | BearerAuthConfig | None = None

The authentication config used for http requests.

connection_mode pydantic-field

connection_mode: ConnectionMode = ConnectionMode.AUTO

The connection mode to use when connecting to the Signal service.

download_attachments pydantic-field

download_attachments: bool = True

Whether to download attachments from messages.

logging_level pydantic-field

logging_level: int = WARNING

The logging level for the bot.

phone_number pydantic-field

phone_number: str

The phone number of the bot.

retry_interval pydantic-field

retry_interval: int = 1

The interval in seconds to wait before retrying a failed connection to the signal service.

signal_service pydantic-field

signal_service: str = 'localhost:8080'

The URL of the signal-cli-rest-api service to connect to, without protocol.

storage pydantic-field

storage: (
    RedisConfig | SQLiteConfig | InMemoryConfig | None
) = None

The configuration for the storage backend to use.

InMemoryConfig pydantic-model

Bases: BaseModel

The configuration for the in-memory storage backend, which defaults to SQLiteStorage with memory storage.

Fields:

Source code in src/signalbot/bot_config.py
class InMemoryConfig(BaseModel):
    """The configuration for the in-memory storage backend, which defaults to
    [SQLiteStorage](storage.md#signalbot.storage.SQLiteStorage) with memory storage.
    """

    type: Literal["in-memory"] = Field(
        default="in-memory", description="The type of storage. Defaults to `in-memory`."
    )

type pydantic-field

type: Literal['in-memory'] = 'in-memory'

The type of storage. Defaults to in-memory.

RedisConfig pydantic-model

Bases: BaseModel

The configuration for the RedisStorage backend.

Fields:

Source code in src/signalbot/bot_config.py
class RedisConfig(BaseModel):
    """The configuration for the
    [RedisStorage](storage.md#signalbot.storage.RedisStorage) backend.
    """

    type: Literal["redis"] = Field(
        default="redis", description="The type of storage. Defaults to `redis`."
    )
    host: str = Field(description="The hostname of the Redis server.")
    port: int = Field(description="The port number of the Redis server.")
    password: str | None = Field(
        default=None, description="The password for Redis authentication."
    )

host pydantic-field

host: str

The hostname of the Redis server.

password pydantic-field

password: str | None = None

The password for Redis authentication.

port pydantic-field

port: int

The port number of the Redis server.

type pydantic-field

type: Literal['redis'] = 'redis'

The type of storage. Defaults to redis.

SQLiteConfig pydantic-model

Bases: BaseModel

The configuration for the SQLiteStorage backend.

Fields:

Source code in src/signalbot/bot_config.py
class SQLiteConfig(BaseModel):
    """The configuration for the
    [SQLiteStorage](storage.md#signalbot.storage.SQLiteStorage) backend.
    """

    type: Literal["sqlite"] = Field(
        default="sqlite", description="The type of storage. Defaults to `sqlite`."
    )
    db: str | Path = Field(description="The path to the SQLite database file.")
    check_same_thread: bool = Field(
        default=True,
        description="Whether to check the same thread when accessing the database.",
    )

check_same_thread pydantic-field

check_same_thread: bool = True

Whether to check the same thread when accessing the database.

db pydantic-field

db: str | Path

The path to the SQLite database file.

type pydantic-field

type: Literal['sqlite'] = 'sqlite'

The type of storage. Defaults to sqlite.

load_config

load_config(
    config: Config | Mapping | Path | str,
) -> Config

Coerce a Config, mapping, or path to a JSON/YAML file into a Config.

Parameters:

Name Type Description Default
config Config | Mapping | Path | str

An already-built Config, a mapping of config fields, or a path (or path string) to a .json, .yaml, or .yml file.

required

Returns:

Type Description
Config

The resulting Config.

Raises:

Type Description
ValueError

If config is a path with an unsupported suffix, or is none of the accepted types.

Source code in src/signalbot/bot_config.py
def load_config(config: Config | Mapping | Path | str) -> Config:
    """Coerce a `Config`, mapping, or path to a JSON/YAML file into a `Config`.

    Args:
        config: An already-built `Config`, a mapping of config fields, or a
            path (or path string) to a `.json`, `.yaml`, or `.yml` file.

    Returns:
        The resulting `Config`.

    Raises:
        ValueError: If `config` is a path with an unsupported suffix, or is
            none of the accepted types.
    """
    if isinstance(config, Config):
        return config

    if isinstance(config, Mapping):
        return Config.model_validate(config)

    if isinstance(config, (str, Path)):
        if isinstance(config, str):
            config = Path(config)
        if config.suffix.lower() == ".json":
            with config.open() as f:
                return Config.model_validate_json(f.read())
        if config.suffix.lower() in [".yaml", ".yml"]:
            with config.open() as f:
                data = yaml.safe_load(f)
            return Config.model_validate(data)

    error_msg = f"Invalid config {config}"
    raise ValueError(error_msg)

ConnectionMode

Bases: StrEnum

Protocol strategy for connecting to signal-cli-rest-api.

Source code in src/signalbot/_client/base.py
class ConnectionMode(StrEnum):
    """Protocol strategy for connecting to `signal-cli-rest-api`."""

    HTTPS_ONLY = "https_only"
    """Always use HTTPS/WSS."""
    HTTP_ONLY = "http_only"
    """Always use HTTP/WS."""
    AUTO = "auto"
    """Start with HTTPS/WSS and fallback to HTTP/WS if unavailable."""

AUTO class-attribute instance-attribute

AUTO = 'auto'

Start with HTTPS/WSS and fallback to HTTP/WS if unavailable.

HTTPS_ONLY class-attribute instance-attribute

HTTPS_ONLY = 'https_only'

Always use HTTPS/WSS.

HTTP_ONLY class-attribute instance-attribute

HTTP_ONLY = 'http_only'

Always use HTTP/WS.