SignalBot
MIN_SIGNAL_CLI_REST_API_VERSION
module-attribute
¶
The minimum required version of signal-cli-rest-api for this version of signalbot.
SignalBot ¶
SignalBot is the main class for the bot. It provides methods to register handlers, start the bot, and interact with messages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config | Mapping | Path | str
|
the configuration for the bot. |
required |
Example config:
Source code in src/signalbot/bot.py
groups
instance-attribute
¶
groups: GroupRegistry
Cache of the groups the bot is a member of, with lookup helpers. Only
populated after SignalBot.start() is called
and SignalBot.init_task is done.
Group actions are available via groups.actions.
handlers
property
¶
handlers: HandlerList
A list of registered handlers with their filters.
Warning
Only available after SignalBot.start() is called and SignalBot.init_task is done.
init_task
instance-attribute
¶
init_task: Task | None = None
The initialization async task for the bot.
Warning
Only available after SignalBot.start() is called.
messages
instance-attribute
¶
messages: MessageActions
Send, edit, or delete messages, and manage typing indicators.
scheduler
instance-attribute
¶
scheduler: AsyncIOScheduler = components.scheduler
The scheduler for running scheduled tasks.
storage
instance-attribute
¶
storage: SQLiteStorage | RedisStorage = components.storage
The storage backend used by the bot.
close
async
¶
Close the shared HTTP session.
Warning
Not safe to call while the pipeline's producer/consumer tasks may still be making requests through this session — it pulls the connection out from under them mid-request. SignalBot.stop() avoids this by cancelling and awaiting those tasks first; call this directly only once you know none of them are still running.
Source code in src/signalbot/bot.py
register ¶
register(
handler: AnyHandler,
*,
contacts: list[str] | bool = True,
groups: list[str] | bool = True,
f: Callable[[ReceivedMessage], bool] | None = None
) -> None
Register a handler with optional contact/group filters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler
|
AnyHandler
|
Handler instance to register. |
required |
contacts
|
list[str] | bool
|
Allowed contacts or True for all. |
True
|
groups
|
list[str] | bool
|
Allowed groups or True for all. |
True
|
f
|
Callable[[ReceivedMessage], bool] | None
|
Optional function to further filter messages. |
None
|
Source code in src/signalbot/bot.py
request_stop ¶
Schedule SignalBot.stop() without blocking the caller.
The non-blocking way to trigger shutdown from within a message handler; see SignalBot.stop() for why calling it directly also works, just not without blocking the handler until shutdown completes.
Source code in src/signalbot/bot.py
start ¶
start(*, run_forever: bool = True) -> None
Start the bot event loop and scheduler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
run_forever
|
bool
|
Whether to start the event loop or only add the task to it. |
True
|
Source code in src/signalbot/bot.py
stop
async
¶
Gracefully stop the bot: cancel background tasks, close the shared HTTP session, and stop the event loop started by SignalBot.start().
Source code in src/signalbot/bot.py
wait_until_ready
async
¶
Wait until the bot has finished connecting and is ready to send messages.