Skip to content

Signalbot

Python package to build your own Signal bots.

The package provides methods to easily listen for incoming messages and responding or reacting on them. It also provides a class to develop new commands, which then can be registered within the bot.

Here is minimal example of what that looks like:

import logging
import os

from signalbot import (
    Command,
    Config,
    Context,
    SignalBot,
    enable_console_logging,
    triggered,
)


class PingCommand(Command):
    @triggered("Ping")
    async def handle(self, c: Context) -> None:
        await c.send("Pong")


if __name__ == "__main__":
    enable_console_logging(logging.INFO)

    bot = SignalBot(
        Config(
            signal_service=os.environ["SIGNAL_SERVICE"],
            phone_number=os.environ["PHONE_NUMBER"],
        )
    )
    bot.register(PingCommand())  # Run the command for all contacts and groups
    bot.start()

To set it up follow the steps in the getting started page.

Methods overview

The bot can do a lot more, here is a quick overview of the most common methods:

  • bot.register(command, contacts=True, groups=True): Register a new command, listen in all contacts and groups, same as bot.register(command)
  • bot.register(command, contacts=False, groups=["Hello World"]): Only listen in the "Hello World" group
  • bot.register(command, contacts=["+49123456789"], groups=False): Only respond to one contact
  • bot.start(): Start the bot
  • bot.send(receiver, text): Send a new message
  • bot.react(message, emoji): React to a message
  • bot.start_typing(receiver): Start typing
  • bot.stop_typing(receiver): Stop typing
  • bot.send(receiver, text, edit_timestamp=timestamp): Edit a previously sent message
  • bot.remote_delete(receiver, timestamp): Delete a previously sent message
  • bot.receipt(message, receipt_type): Mark a message as read
  • bot.update_group(group_id, avatar, description, expiration, name): Change group settings
  • bot.delete_attachment(attachment_filename): Delete the local copy of an attachment
  • bot.scheduler: Schedule tasks, see the scheduler examples.

Real world bot examples

There are many real world examples of bot implementations using this library. Check the whole list at https://github.com/signalbot-org/signalbot/network/dependents