SignalBot
MIN_SIGNAL_CLI_REST_API_VERSION
module-attribute
¶
MIN_SIGNAL_CLI_REST_API_VERSION = Version('0.95.0')
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 commands, start the bot, and interact with messages.
Attributes:
| Name | Type | Description |
|---|---|---|
config |
Config
|
The configuration for the bot. |
commands |
CommandList
|
A list of registered commands with their filters.
Only available after |
groups |
list
|
A list of groups the bot is a member of.
Only available after |
storage |
SQLiteStorage | RedisStorage
|
The storage backend used by the bot. |
scheduler |
AsyncIOScheduler
|
The scheduler for running scheduled tasks. |
init_task |
None | Task
|
The initialization async task for the bot.
Only available after |
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Config | Mapping | Path | str
|
the configuration for the bot. |
required |
Example config:
{
signal_service: "127.0.0.1:8080",
phone_number: "+49123456789"
}
Source code in src/signalbot/bot.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 | |
delete_attachment
async
¶
delete_attachment(attachment_filename: str) -> None
Delete an attachment from local storage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
attachment_filename
|
str
|
File name to delete. |
required |
Source code in src/signalbot/bot.py
464 465 466 467 468 469 470 | |
react
async
¶
React to a message with an emoji.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
Message
|
The message to react to. |
required |
emoji
|
str
|
Emoji reaction value. |
required |
Source code in src/signalbot/bot.py
344 345 346 347 348 349 350 351 352 353 354 355 356 357 | |
receipt
async
¶
Send a read or viewed receipt for a message if supported.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
Message
|
The message to acknowledge. |
required |
receipt_type
|
Literal['read', 'viewed']
|
Receipt type to send. |
required |
Source code in src/signalbot/bot.py
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 | |
register ¶
register(
command: Command,
contacts: list[str] | bool = True,
groups: list[str] | bool = True,
f: Callable[[Message], bool] | None = None,
) -> None
Register a command with optional contact/group filters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
command
|
Command
|
Command 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[[Message], bool] | None
|
Optional function to further filter messages. |
None
|
Source code in src/signalbot/bot.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | |
remote_delete
async
¶
Delete a previously sent message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
receiver
|
str
|
Recipient identifier. |
required |
timestamp
|
int
|
Timestamp of the message to delete. |
required |
Returns:
| Type | Description |
|---|---|
int
|
The timestamp of the delete action. |
Source code in src/signalbot/bot.py
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 | |
send
async
¶
send(
receiver: str,
text: str,
*,
base64_attachments: list | None = None,
link_preview: LinkPreview | None = None,
quote_author: str | None = None,
quote_mentions: list | None = None,
quote_message: str | None = None,
quote_timestamp: int | None = None,
mentions: list[dict[str, Any]] | None = None,
edit_timestamp: int | None = None,
text_mode: str | None = None,
view_once: bool = False,
) -> int
Send or edit a message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
receiver
|
str
|
The recipient of the message. |
required |
text
|
str
|
The content of the message. |
required |
base64_attachments
|
list | None
|
List of attachments encoded in base64. |
None
|
link_preview
|
LinkPreview | None
|
Link previews to be sent with the message. |
None
|
quote_author
|
str | None
|
The author of the quoted message, required if quote_message is set. |
None
|
quote_mentions
|
list | None
|
List of mentioned users in the quoted message, required if quote_message is set. |
None
|
quote_message
|
str | None
|
The content of the quoted message, required if quote_message is set. |
None
|
quote_timestamp
|
int | None
|
The timestamp of the quoted message, required if quote_message is set. |
None
|
mentions
|
list[dict[str, Any]] | None
|
List of dictionary of mentions, it has the format
|
None
|
edit_timestamp
|
int | None
|
The timestamp of the message to edit, if not set a new message will be sent. |
None
|
text_mode
|
str | None
|
The text mode of the message, can be "normal" or "styled". |
None
|
view_once
|
bool
|
Whether the message should be view once or not. |
False
|
Returns:
| Type | Description |
|---|---|
int
|
The timestamp of the sent or edited message. |
Source code in src/signalbot/bot.py
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
signal_cli_rest_api_mode
async
¶
signal_cli_rest_api_mode() -> str
Return the signal-cli-rest-api mode.
Source code in src/signalbot/bot.py
274 275 276 | |
signal_cli_rest_api_version
async
¶
signal_cli_rest_api_version() -> str
Return the signal-cli-rest-api version.
Source code in src/signalbot/bot.py
270 271 272 | |
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
255 256 257 258 259 260 261 262 263 264 265 266 267 268 | |
start_typing
async
¶
start_typing(receiver: str) -> None
Send a typing indicator to a receiver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
receiver
|
str
|
Message recipient. |
required |
Source code in src/signalbot/bot.py
378 379 380 381 382 383 384 385 | |
stop_typing
async
¶
stop_typing(receiver: str) -> None
Stop a typing indicator for a receiver.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
receiver
|
str
|
Message recipient. |
required |
Source code in src/signalbot/bot.py
387 388 389 390 391 392 393 394 | |
update_contact
async
¶
update_contact(
receiver: str,
expiration_in_seconds: int | None = None,
name: str | None = None,
) -> None
Update a contact's metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
receiver
|
str
|
Contact identifier. |
required |
expiration_in_seconds
|
int | None
|
Expiration timer in seconds. |
None
|
name
|
str | None
|
Contact display name. |
None
|
Source code in src/signalbot/bot.py
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 | |
update_group
async
¶
update_group(
group_id: str,
base64_avatar: str | None = None,
description: str | None = None,
expiration_in_seconds: int | None = None,
name: str | None = None,
) -> None
Update a group's metadata.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group_id
|
str
|
Group identifier or name. |
required |
base64_avatar
|
str | None
|
Base64-encoded avatar. |
None
|
description
|
str | None
|
Group description. |
None
|
expiration_in_seconds
|
int | None
|
Expiration timer in seconds. |
None
|
name
|
str | None
|
Group display name. |
None
|
Source code in src/signalbot/bot.py
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 | |
enable_console_logging ¶
Enable console logging for the signalbot logger.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level
|
int
|
Logging level for the logger. |
WARNING
|
Source code in src/signalbot/bot.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |