Skip to main content

Python bindings for signald

Project description

Signald python bindings

pypi Documentation Status builds.sr.ht status

Interact with the signal messaging network in python with sweet, sweet autocompletion.

Most of the code is generated by the generate.py script that uses the schema available at https://signald.org/protocol.json.

No 3rd party dep, just the python standard lib.

Install

pip install aiosignald

Have signald running. See their docs about it.

Issue tracker: https://todo.sr.ht/~nicoco/aiosignald

Part of the slidge project (but can be used independently)

Usage

Example: echo bot

import asyncio

from aiosignald import SignaldAPI
import aiosignald.generated as api

class EchoBot(SignaldAPI):
    async def handle_IncomingMessage(self, msg: api.IncomingMessagev1, _payload):
        # hook to the incoming event by naming you function handle_EventName
        # most stuff comes through an IncomingMessage anyway
        print("Received: ", msg)
        if (data_msg := msg.data_message) and (body := data_msg.body):
            await self.send(
                username=PHONE_NUMBER,
                recipientAddress=msg.source,
                messageBody=body
            )

async def main():
    loop = asyncio.get_running_loop()
    _, signald = await loop.create_unix_connection(
        EchoBot, path=SIGNALD_SOCKET_PATH)
    if ACCOUNT_TYPE == "primary":
        await signald.register(account=PHONE_NUMBER)
        # Some async code to get the SMS code
        code = await user_input("Enter your sms code?")
        await signald.verify(account=PHONE_NUMBER, code=code)
    else:
        # linking to an existing account is also possible
        resp = await signald.generate_linking_uri()
        print("Make this a QR code and scan it on your primary signal device:", resp.uri)
        await signald.finish_link(device_name="friendly-device-name", session_id=resp.session_id)
    await signald.on_con_lost

# See https://signald.org/articles/protocol/ for more info about this
SIGNALD_SOCKET_PATH = "/var/run/signald/signald.sock"
PHONE_NUMBER = "+XXXXXX"
ACCOUNT_TYPE = "primary"

asyncio.run(main())

Docs are available on readthedocs.

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

aiosignald-0.3.7.tar.gz (30.8 kB view details)

Uploaded Source

Built Distribution

aiosignald-0.3.7-py3-none-any.whl (31.4 kB view details)

Uploaded Python 3

File details

Details for the file aiosignald-0.3.7.tar.gz.

File metadata

  • Download URL: aiosignald-0.3.7.tar.gz
  • Upload date:
  • Size: 30.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.11.3 Linux/6.1.24-0-lts

File hashes

Hashes for aiosignald-0.3.7.tar.gz
Algorithm Hash digest
SHA256 e92de90b57cc3be70f388b013a310ec64bfc31a58590746582f8f62baffb24f7
MD5 cb7e248064a6f2920399bc542990a95f
BLAKE2b-256 98870c9f9ad9aa08e99212eec853ec98b372bcef0691ec30de6771cefc07354e

See more details on using hashes here.

File details

Details for the file aiosignald-0.3.7-py3-none-any.whl.

File metadata

  • Download URL: aiosignald-0.3.7-py3-none-any.whl
  • Upload date:
  • Size: 31.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.11.3 Linux/6.1.24-0-lts

File hashes

Hashes for aiosignald-0.3.7-py3-none-any.whl
Algorithm Hash digest
SHA256 ba7ebb4eb291666da4d5d22039c4ae1d652d9da7561a221581348c4e1ad64499
MD5 f18666562b807afee6652ee285495954
BLAKE2b-256 d282c62a90bd5ed9ea0230690a1c6f7f8204ef0420f45c4ceb4c1a0e09731b4e

See more details on using hashes here.

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