Signal-Bot
An asyncio Python 3.11 module for building Signal bots that interact with AsamK/signal-cli.
📖 Documentation and Examples
Features
- Construct different "personalities" for different contexts (users, groups, etc).
- Callbacks for the following events:
- Cron schedules.
- Any message is received.
- Message matches a prefix (e.g.,
/command ...). - Message contains a keyword.
- Message contains an
@-mention.
- Currently supported signal-cli functions:
- "Typing..." indicators.
- Reacting to messages.
- Sending messages, including:
- Inline mentions.
- Inline text styles.
- More to come...
- Deleting messages.
Usage
For development: python3.11 -m pip install signal_bot_framework.
# test_bot.py
import asyncio
from signal_bot_framework import create, AccountNumber
async def crabby_callback(signal: Signal, context: Context, message: DataMessage) -> bool:
to = context[1]
await signal.send_reaction(message, "🦀")
await signal.send_message(to, f"Sorry, just feeling a little crabby, {message.sender_name}.",
args=SendMessageArgs(mention=[f"37:{len(message.sender_name)}:{message.sender}"]))
return True
async def main():
# The default, finds `signal-cli` on path and launches it as a subprocess
connection = 'ipc://'
# or, use TCP: connection = 'tcp://HOST:PORT'
signal = await create(AccountNumber('+12345678900'), connection)
signal.on_keyword('ok?', crabby_callback)
await signal.run()
if __name__ == '__main__':
asyncio.run(main())
Docker
For convenience, a base Docker image can be built as sidneys1/signal_bot, based on python:3.11-alpine.
You can base your bot on it like so:
FROM sidneys1/signal_bot:latest
COPY ./test_bot.py .
CMD ["python", "test_bot.py"]
You can easily combine this in Docker-Compose with a signal-cli container.
Make sure to change your test_bot.py's connection string to tcp://signal-cli:7583.
Additionally, an easy way to keep your Signal account from being stored in your image or docker-compose.yml is to
store it in a Docker secret, as shown below.
secrets:
signal-account:
file: .signal-account
services:
test_bot:
build: .
depends_on: [signal-cli]
signal-cli:
image: registry.gitlab.com/packaging/signal-cli/signal-cli-native:latest
volumes:
# Mount an existing signal-cli configuration directory from the host.
- "${HOME}/.local/share/signal-cli:/var/lib/signal-cli:rw"
ports: ["7583"]
secrets: [signal-account]
entrypoint: sh -c
command: "'signal-cli -c /var/lib/signal-cli --account $(cat /run/secrets/signal-account) daemon --receive-mode on-connection --no-receive-stdout --send-read-receipts --tcp 0.0.0.0:7583'"
Building
- Clone this repository and install the prerequisites:
- Python >= 3.11 with
venvsupport (included with Python for Windows,python3.11-venvon most package managers). python3.11 -m pip install build
- Python >= 3.11 with
- Run
python3.11 -m buildin the repository folder. - Distribute or install
./dist/signal_bot_framework-X.Y.Z-py3-none-any.whl.
Dependencies
cron-converter(for Cron-based hooks).humanize(for debugging output related to Cron-based hooks).
Signal-Bot assumes that you already have signal-cli available and registered with an account from which messages will
be sent and received.
Metadata
Release files for signal-bot-framework 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| signal_bot_framework-0.2.2.tar.gz | 66.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| signal_bot_framework-0.2.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 122.8 kB
Release files / signal_bot_framework-0.2.2.tar.gz
| Download URL | signal_bot_framework-0.2.2.tar.gz |
|---|---|
| Size | 66.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
133f284b978e1b980a2732a6eaf3505c1f5801a7688bbf4b308129bc4ebec1df
|
|
BLAKE2b-256 checksum How to use checksums |
d85087ba6ecae7d5532d3fe8698412bc3513b3b10c4815d5faeced3fae817ac6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.5
|
Release files / signal_bot_framework-0.2.2-py3-none-any.whl
| Download URL | signal_bot_framework-0.2.2-py3-none-any.whl |
|---|---|
| Size | 56.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
72f03b9d0177968a19842f758e849d7c7008739b96242931177a06c4bf49198b
|
|
BLAKE2b-256 checksum How to use checksums |
b146607a5cc828cead9ab21f9b934c9ac4176fb271495364f4bf6ee955442532
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/5.1.1 CPython/3.12.5
|