Skip to main content

Semaphore: A simple (rule-based) bot library for Signal Private Messenger.

Project description


PyPI GitHub Workflow Status GitHub tag (latest SemVer) License

A simple (rule-based) bot library for Signal Private Messenger in Python. Please note that this library is unofficial, unapproved and not nearly as secure as the real Signal clients.

Table of contents



  1. Install signald or build from source

    $ git clone
    $ cd signald
    $ make installDist
    $ make setup
  2. Install Semaphore

    Latest release from PyPi:

    $ pip install semaphore-bot

    From source with pip:

    $ pip install git+

    From source:

    $ git clone
    $ cd semaphore
    $ make build
    $ make install

Quick start

  1. Start signald

    $ cd signald
    $ build/install/signald/bin/signald
  2. Open a new terminal and connect to signald control socket

    $ nc -U $XDG_RUNTIME_DIR/signald/signald.sock

    (or /var/run/signald/signald.sock for older versions of signald, see signald docs)

  3. Register phone number with Signal by sending following message on the control socket (replace +xxxxxxxxxxx with bot Signal number). Sometimes Signal requires completion of a captcha to register.

    {"type": "register", "version": "v1", "account": "+xxxxxxxxxxx"}
  4. Verify phone number with SMS verification code by sending following message on the control socket (replace +xxxxxxxxxxx with bot Signal number and zzzzzz with verification code)

    {"type": "verify", "version": "v1", "account": "+xxxxxxxxxxx", "code": "zzzzzz"}
  5. Verify Signal is working by sending following message on the control socket (replace +xxxxxxxxxxx with bot Signal number and +yyyyyyyyyyy with your Signal number)

    {"type": "send", "version": "v1", "username": "+xxxxxxxxxxx", "recipientAddress": {"number": "+yyyyyyyyyyy"}, "messageBody": "Hello world"}
  6. Open a new terminal and set the SIGNAL_PHONE_NUMBER environment variable to your phone number:

    $ export SIGNAL_PHONE_NUMBER=+xxxxxxxxxxx
  7. Start the example echo bot

    $ python examples/
  8. Send message to Signal bot running on +xxxxxxxxxxx and wait for an echo

  9. Now you can start writing your own bot for Signal Private Messenger!

Code example

import anyio
from semaphore import Bot, ChatContext

# Connect the bot to number.
bot = Bot("+xxxxxxxxxxx")

async def echo(ctx: ChatContext) -> None:
    await ctx.message.reply(ctx.message.get_body())

async def main():
    async with bot:
        # Set profile name.
        await bot.set_profile("Semaphore example bot")

        # Run the bot until you press Ctrl-C.
        await bot.start()

Example bots

The following example bots can be found in examples:

  • apodbot, replies with Astronomy Picture of the Day
  • bbcbot, replies with latest BBC headlines
  • broadcastbot, send broadcast to all subscribers
  • btcbot, sends notification when BTC price drops below a set price
  • echobot, repeats received messages
  • exceptionbot, with custom exception handler
  • expirationbot, sets the message expiration timer for a chat to random value
  • lovebot, loves everything you say!
  • profilebot, retrieves profile for personal touch
  • quotebot, quotes and repeats received messages
  • spongebot, repeats received messages in sPOngEbOb sqUArepAnTs text
  • stickerbot, links to the sticker pack for received stickers
  • timerbot, sends an alert after a predefined time
  • xkcdbot, replies with latest XKCD comic



  • Compatibility with signald 0.23.0+
  • Add method to retrieve profile of message sender


  • Compatibility with signald 0.22.0+
  • Add option to automatically accept group invites


  • Compatibility with signald 0.18.0+
  • Migrate to latest version of anyio (3.5.0)
  • Add Dockerfile to run Signal bot in container
  • Add support for link previews (thanks @Era-Dorta)


  • Compatibility with signald 0.17.0+
  • Add method to set expiration timer of chat (thanks @Era-Dorta)
  • Example expiration timer bot


  • Compatibility with signald 0.15.0+
  • Add support for emoji and about to in profile (thanks @EsEnZeT)
  • Add option to throw signals errors on send (thanks @eknoes)


  • Compatibility with signald 0.14.0+ (signald protocol v1)
  • Add support for waiting on signald send confirmation (thanks @eknoes)
  • Add support for sending messages to groups (thanks @brazuzan)


  • Add method to set profile name and profile picture
  • Store e164 phone number and uuid for received messages


  • Add support for sending messages without previous context (thanks @eknoes)
  • Add support for exception handlers (thanks @eknoes)
  • Add ability to set profile picture (thanks @eknoes)
  • Support signald client protocol v1
  • Compatibility with signald 0.12.0+


  • Fix repeating job re-add to queue (thanks @grandchild)


  • Support for typing indicators
  • Support for GroupsV2 (thanks @thefinn93)
  • Example sticker bot (thanks @iomintz)
  • Compatibility with signald 0.11.0+


  • Support for Python 3.9
  • Support for executing multiple handlers in parallel (thanks @iomintz)
  • Support incoming sticker messages (thanks @iomintz)


  • Support for decorators to register handlers
  • Support for sending delivery receipts
  • Mark messages as read by default


  • Compatibility with signald 0.10.0+
  • Support for multiple replies/reactions by handler (thanks @iomintz)
  • Marking messages as read is optional
  • First release on PyPi


  • Support for message reactions
  • Example message reaction bot


  • Improve the logging system
  • Add logging to job queue
  • Strict typing


  • Support for recurring jobs
  • Example BTC price notification bot


  • Support for scheduled jobs
  • Example timer bot


  • Support for quoting messages
  • Example quote bot


  • First release on Github


This project is licensed under the AGPL-v3 license. The full license can be found in LICENSE.txt.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

semaphore-bot-0.16.0.tar.gz (32.7 kB view hashes)

Uploaded source

Built Distribution

semaphore_bot-0.16.0-py3-none-any.whl (45.7 kB view hashes)

Uploaded py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page