Package: semaphore-bot
SemaphoreA simple (rule-based) bot library forSignalPrivate Messenger in Python.
Please note that this library is unofficial, unapproved and not nearly as secure as the real Signal clients.Table of contentsRequirementsInstallationQuick startCode exampleExample botsChangelogLicenseRequirementssignald0.23.0or later, a daemon that facilitates communication overSignalInstallationInstall signald or build from source$gitclonehttps://gitlab.com/signald/signald.git
$cdsignald
$makeinstallDist
$makesetupInstall SemaphoreLatest release from PyPi:$pipinstallsemaphore-botFrom source with pip:$pipinstallgit+https://github.com/lwesterhof/semaphore.gitFrom source:$gitclonehttps://github.com/lwesterhof/semaphore.git
$cdsemaphore
$makebuild
$makeinstallQuick startStart signald$cdsignald
$build/install/signald/bin/signaldOpen a new terminal and connect to signald control socket$nc-U$XDG_RUNTIME_DIR/signald/signald.sock(or/var/run/signald/signald.sockfor older versions of signald,see signald docs)Register phone number with Signal by sending following message on the control socket (replace+xxxxxxxxxxxwith bot Signal number). Sometimes Signal requires completion of acaptchato register.{"type":"register","version":"v1","account":"+xxxxxxxxxxx"}Verify phone number with SMS verification code by sending following message on the control socket (replace+xxxxxxxxxxxwith bot Signal number andzzzzzzwith verification code){"type":"verify","version":"v1","account":"+xxxxxxxxxxx","code":"zzzzzz"}Verify Signal is working by sending following message on the control socket (replace+xxxxxxxxxxxwith bot Signal number and+yyyyyyyyyyywith your Signal number){"type":"send","version":"v1","username":"+xxxxxxxxxxx","recipientAddress":{"number":"+yyyyyyyyyyy"},"messageBody":"Hello world"}Open a new terminal and set theSIGNAL_PHONE_NUMBERenvironment variable to your phone number:$exportSIGNAL_PHONE_NUMBER=+xxxxxxxxxxxStart the example echo bot$pythonexamples/echobot.pySend message to Signal bot running on+xxxxxxxxxxxand wait for an echoNow you can start writing your own bot forSignalPrivate Messenger!Code exampleimportanyiofromsemaphoreimportBot,ChatContext# Connect the bot to number.bot=Bot("+xxxxxxxxxxx")@bot.handler('')asyncdefecho(ctx:ChatContext)->None:awaitctx.message.reply(ctx.message.get_body())asyncdefmain():asyncwithbot:# Set profile name.awaitbot.set_profile("Semaphore example bot")# Run the bot until you press Ctrl-C.awaitbot.start()anyio.run(main)Example botsThe following example bots can be found inexamples:apodbot, replies with Astronomy Picture of the Daybbcbot, replies with latest BBC headlinesbroadcastbot, send broadcast to all subscribersbtcbot, sends notification when BTC price drops below a set priceechobot, repeats received messagesexceptionbot, with custom exception handlerexpirationbot, sets the message expiration timer for a chat to random valuegroups, manage groupslovebot, loves everything you say!profilebot, retrieves profile for personal touchquotebot, quotes and repeats received messagesspongebot, repeats received messages in sPOngEbOb sqUArepAnTs textstickerbot, links to the sticker pack for received stickerstimerbot, sends an alert after a predefined timexkcdbot, replies with latest XKCD comicChangelogv0.17.0Add support for group actions (thanks @sks444)Add support for receiving mentionsv0.16.0Compatibility with signald 0.23.0+Add method to retrieve profile of message senderv0.15.0Compatibility with signald 0.22.0+Add option to automatically accept group invitesv0.14.0Compatibility with signald 0.18.0+Migrate to latest version of anyio (3.5.0)Add Dockerfile to run Signal bot in containerAdd support for link previews (thanks @Era-Dorta)v0.13.0Compatibility with signald 0.17.0+Add method to set expiration timer of chat (thanks @Era-Dorta)Example expiration timer botv0.12.0Compatibility 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)v0.11.0Compatibility 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)v0.10.1Add method to set profile name and profile pictureStore e164 phone number and uuid for received messagesv0.10.0Add 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 v1Compatibility with signald 0.12.0+v0.9.1Fix repeating job re-add to queue (thanks @grandchild)v0.9.0Support for typing indicatorsSupport for GroupsV2 (thanks @thefinn93)Example sticker bot (thanks @iomintz)Compatibility with signald 0.11.0+v0.8.0Support for Python 3.9Support for executing multiple handlers in parallel (thanks @iomintz)Support incoming sticker messages (thanks @iomintz)v0.7.1Support for decorators to register handlersSupport for sending delivery receiptsMark messages as read by defaultv0.7.0Compatibility with signald 0.10.0+Support for multiple replies/reactions by handler (thanks @iomintz)Marking messages as read is optionalFirst release on PyPiv0.6.0Support for message reactionsExample message reaction botv0.5.0Improve the logging systemAdd logging to job queueStrict typingv0.4.0Support for recurring jobsExample BTC price notification botv0.3.0Support for scheduled jobsExample timer botv0.2.0Support for quoting messagesExample quote botv0.1.0First release on GithubLicenseThis project is licensed under the AGPL-v3 license.
The full license can be found inLICENSE.txt.