Gediminas Lelešius

Signal bot in Python

2021-10-14, U: 2021-12-13

Install Java 17


sudo add-apt-repository ppa:linuxuprising/java -y
sudo apt update
sudo apt-get install oracle-java17-installer oracle-java17-set-default

Install Signal-cli

Download latest version directly from releases:
Extract it and try to run signal-cli -u [PHONE NUMBER] receive.
If libsignal fails to load because architectures don't match, go to

Short version of Signal-cli guide
Choose your architecture and download latest version (dpkg --print-architecture).
Go to signal-cli/lib, remove included versions of libraries and add downloaded ones:

zip -d signal-client-java-*.jar

zip -u signal-client-java-*.jar

Log in to Signal

As main device (not tested!)
signal-cli --config /var/lib/signal-cli -u [PHONE NUMBER] register
signal-cli --config /var/lib/signal-cli -u [PHONE NUMBER] verify [CODE FROM SMS]
As secondary device
signal-cli --config /var/lib/signal-cli link -n "[DEVICE NAME]"

Copy printed link, paste it into QR generator and scan using Signal app on mobile.

Create DBus service

Write bot

Install python dependencies:

pip install git+
pip install PyGObject
pip install pycairo

Simple echo bot:

from pydbus import SystemBus
from gi.repository import GLib
import base64

bus = SystemBus()
loop = GLib.MainLoop()

signal = bus.get('org.asamk.Signal')

def send_message(source, groupID, text, attachments=[]):
    if len(groupID) == 0:
        signal.sendMessage(text, attachments, [source])
        signal.sendGroupMessage(text, attachments, groupID)

def msgRcv (timestamp, source, groupID, message, attachments):
    send_message(source, groupID, 'text', ['attachment_file_path'])

signal.onMessageReceived = msgRcv