slidge.plugins.signal#

Submodules#

Package Contents#

Classes#

Contact

This class centralizes actions in relation to a specific legacy contact.

Roster

Virtual roster of a gateway user, that allows to represent all

Gateway

Must be subclassed by a plugin to set up various aspects of the XMPP

Session

Represents a signal account

class slidge.plugins.signal.Contact(*a, **k)[source]#

Bases: slidge.LegacyContact[slidge.plugins.signal.session.Session]

This class centralizes actions in relation to a specific legacy contact.

You shouldn’t create instances of contacts manually, but rather rely on LegacyRoster.by_legacy_id() to ensure that contact instances are singletons. The LegacyRoster instance of a session is accessible through the BaseSession.contacts attribute.

Typically, your plugin should have methods hook to the legacy events and call appropriate methods here to transmit the “legacy action” to the xmpp user. This should look like this:

Parameters
  • session – The session this contact is part of

  • legacy_id – The contact’s legacy ID

  • jid_username – User part of this contact’s ‘puppet’ JID. NB: case-insensitive, and some special characters are not allowed

CORRECTION = False#
signal_address()#
async get_identities()#
async carbon_send_attachments(attachments)#
Parameters

attachments (list[aiosignald.generated.JsonAttachmentv1]) –

async send_attachments(attachments, /, legacy_msg_id=None, reply_to_msg_id=None, when=None)#
Parameters
async update_info(profile=None)#
Parameters

profile (Optional[aiosignald.generated.Profilev1]) –

async update_and_add()#
class slidge.plugins.signal.Roster(session)[source]#

Bases: slidge.LegacyRoster[Contact, slidge.plugins.signal.session.Session]

Virtual roster of a gateway user, that allows to represent all of their contacts as singleton instances (if used properly and not too bugged).

Every BaseSession instance will have its own LegacyRoster instance accessible via the BaseSession.contacts attribute.

Typically, you will mostly use the LegacyRoster.by_legacy_id() function to retrieve a contact instance.

You might need to override LegacyRoster.legacy_id_to_jid_username() and/or LegacyRoster.jid_username_to_legacy_id() to incorporate some custom logic if you need some characters when translation JID user parts and legacy IDs.

Parameters

session (slidge.core.session.SessionType) –

by_json_address(address)#
Parameters

address (aiosignald.generated.JsonAddressv1) –

class slidge.plugins.signal.Gateway[source]#

Bases: slidge.BaseGateway

Must be subclassed by a plugin to set up various aspects of the XMPP component behaviour, such as its display name or its registration process.

On slidge launch, a singleton is instantiated, and it will be made available to public classes such LegacyContact or BaseSession as the .xmpp attribute. Since it inherits from slixmpp.componentxmpp.ComponentXMPP, this gives you a hand on low-level XMPP interactions via slixmpp plugins, e.g.:

self.send_presence(
    pfrom="somebody@component.example.com",
    pto="someonwelse@anotherexample.com",
)

However, you should not need to do so often since the classes of the plugin API provides higher level abstractions around most commonly needed use-cases, such as sending messages, or displaying a custom status.

COMPONENT_NAME = Signal (slidge)#
COMPONENT_TYPE = signal#
COMPONENT_AVATAR = https://upload.wikimedia.org/wikipedia/commons/5/56/Logo_Signal..png#
REGISTRATION_INSTRUCTIONS#
REGISTRATION_FIELDS#
REGISTRATION_MULTISTEP = True#
ROSTER_GROUP = Signal#
SEARCH_FIELDS#
signal :asyncio.Future[Signal]#
sessions_by_phone :dict[str, slidge.plugins.signal.session.Session]#
CHAT_COMMANDS#
async connect_signal(socket)#

Establish connection to the signald socker

Parameters

socket (pathlib.Path) –

add_adhoc_commands()#

Override this if you want to provide custom adhoc commands (XEP-0050) for your plugin, using slixmpp.plugins.xep_0050.XEP_0050

Basic example:

async _handle_linked_devices(iq, adhoc_session)#
Parameters
  • iq (slixmpp.Iq) –

  • adhoc_session (dict[str, Any]) –

async _handle_add_device1(iq, adhoc_session)#
Parameters
  • iq (slixmpp.Iq) –

  • adhoc_session (dict[str, Any]) –

async _handle_add_device2(stanza, adhoc_session)#
Parameters
  • stanza (slixmpp.plugins.xep_0004.Form) –

  • adhoc_session (dict[str, Any]) –

async static _chat_command_add_device(*args, msg, session=None)#
Parameters
async static _chat_command_get_identities(*args, msg, session=None)#
Parameters
async validate(user_jid, registration_form)#

Validate a registration form from a user.

Since XEP-0077 is pretty limited in terms of validation, it is OK to validate anything that looks good here and continue the legacy auth process via direct messages to the user (using BaseGateway.input() for instance)

Parameters
async unregister(user)#

Optionally override this if you need to clean additional stuff after a user has been removed from the permanent user_store.

Parameters

user (slidge.GatewayUser) –

Returns

class slidge.plugins.signal.Session(user)[source]#

Bases: slidge.BaseSession[slidge.plugins.signal.contact.Contact, slidge.plugins.signal.contact.Roster, slidge.plugins.signal.gateway.Gateway]

Represents a signal account

Parameters

user (slidge.GatewayUser) –

static xmpp_msg_id_to_legacy_msg_id(i)#

Convert a legacy XMPP ID to a valid XMPP msg ID. Needed for read marks and message corrections.

The default implementation just converts the legacy ID to a str, but this should be overridden in case some characters needs to be escaped, or to add some additional, legacy network-specific logic.

The default implementation is an identity function

Parameters

i (str) – The XMPP stanza ID

Returns

An ID that can be used to identify a message on the legacy network

Return type

int

async paused(c)#

Triggered when the user pauses typing in the window of a legacy contact (XEP-0085)

Parameters

c (slidge.plugins.signal.contact.Contact) –

async correct(text, legacy_msg_id, c)#

Triggered when the user corrected a message using XEP-0308

This is only possible if a valid legacy_msg_id was passed when transmitting a message from a contact to the user in LegacyContact.send_text() or slidge.LegacyContact.send_file().

Parameters
async search(form_values)#

Triggered when the user uses Jabber Search (XEP-0055) on the component

Form values is a dict in which keys are defined in BaseGateway.SEARCH_FIELDS

Parameters

form_values (dict[str, str]) – search query, defined for a specific plugin by overriding in BaseGateway.SEARCH_FIELDS

Returns

async login()#

Attempt to listen to incoming events for this account, or pursue the registration process if needed.

async on_websocket_connection_state(state)#
Parameters

state (aiosignald.generated.WebSocketConnectionStatev1) –

async register()#
async send_linking_qrcode()#
async logout()#

Logout the gateway user from the legacy network.

Called on user unregistration and gateway shutdown.

async add_contacts_to_roster()#

Populate a user’s roster

async on_signal_message(msg)#

User has received ‘something’ from signal

Parameters

msg (aiosignald.generated.IncomingMessagev1) –

async send_text(t, c, *, reply_to_msg_id=None)#

Triggered when the user sends a text message from xmpp to a bridged contact, e.g. to translated_user_name@slidge.example.com.

Override this and implement sending a message to the legacy network in this method.

Parameters
Returns

An ID of some sort that can be used later to ack and mark the message as read by the user

Return type

int

async send_file(u, c, *, reply_to_msg_id=None)#

Triggered when the user has sends a file using HTTP Upload (XEP-0363)

Parameters
Returns

An ID of some sort that can be used later to ack and mark the message as read by the user

async active(c)#

Triggered when the user sends an ‘active’ chat state to the legacy network (XEP-0085)

Parameters

c (slidge.plugins.signal.contact.Contact) – Recipient of the active chat state

async inactive(c)#

Triggered when the user sends an ‘inactive’ chat state to the legacy network (XEP-0085)

Parameters

c (slidge.plugins.signal.contact.Contact) –

async composing(c)#

Triggered when the user starts typing in the window of a legacy contact (XEP-0085)

Parameters

c (slidge.plugins.signal.contact.Contact) –

async displayed(legacy_msg_id, c)#

Triggered when the user reads a message sent by a legacy contact. (XEP-0333)

This is only possible if a valid legacy_msg_id was passed when transmitting a message from a contact to the user in LegacyContact.sent_text() or slidge.LegacyContact.send_file().

Parameters
async react(legacy_msg_id, emojis, c)#

Triggered when the user sends message reactions (XEP-0444).

Parameters
  • legacy_msg_id (int) – ID of the message the user reacts to

  • emojis (list[str]) – Unicode characters representing reactions to the message legacy_msg_id. An empty string means “no reaction”, ie, remove all reactions if any were present before

  • c (slidge.plugins.signal.contact.Contact) – Contact the reaction refers to

async retract(legacy_msg_id, c)#

Triggered when the user retracts (XEP-0424) a message.

Parameters
async add_device(uri)#
Parameters

uri (str) –