slidgnal.session#

Attributes#

Classes#

Session

Represents a signal account

Functions#

Module Contents#

slidgnal.session.T[source]#
slidgnal.session.handle_unregistered_recipient(func)[source]#
Parameters:

func (T) –

Return type:

T

slidgnal.session.Recipient[source]#
class slidgnal.session.Session(user)[source]#

Bases: slidge.BaseSession[int, Recipient]

Represents a signal account

Parameters:

user (slidge.GatewayUser) –

xmpp: slidgnal.gateway.Gateway[source]#
contacts: slidgnal.contact.Roster[source]#
bookmarks: slidgnal.group.Bookmarks[source]#
phone[source]#
signal[source]#
user_uuid: asyncio.Future[str][source]#
connected[source]#
sent_in_muc[source]#
static xmpp_to_legacy_msg_id(i)[source]#

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 <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 on_paused(c, thread=None)[source]#

Triggered when the user pauses typing in a legacy chat (XEP-0085)

Parameters:
  • chat – See BaseSession.on_text()

  • thread

  • c (Recipient) –

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()[source]#

Logs in the gateway user to the legacy network.

Triggered when the gateway start and on user registration. It is recommended that this function returns once the user is logged in, so if you need to await forever (for instance to listen to incoming events), it’s a good idea to wrap your listener in an asyncio.Task.

Returns:

Optionally, a text to use as the gateway status, e.g., “Connected as ‘dude@legacy.network’”

async on_websocket_connection_state(state)[source]#
Parameters:

state (aiosignald.generated.WebSocketConnectionStatev1) –

async logout()[source]#

Logs out the gateway user from the legacy network.

Called on gateway shutdown.

async on_signal_message(msg)[source]#

User has received ‘something’ from signal

Parameters:

msg (aiosignald.generated.IncomingMessagev1) –

async on_signal_sync_message(sync_msg)[source]#
Parameters:

sync_msg (aiosignald.generated.JsonSyncMessagev1) –

static on_signal_call_message(contact, _call_message)[source]#
Parameters:
async on_signal_data_message(contact, data, carbon=False)[source]#
Parameters:
async on_signal_typing(contact, typing_message)[source]#
Parameters:
async on_signal_receipt(contact, receipt_message)[source]#
Parameters:
async __get_entity_by_sent_msg_id(contact, t)[source]#
Parameters:
async on_text(chat, text, *, reply_to_msg_id=None, reply_to_fallback_text=None, reply_to=None, thread=None, link_previews=(), **_kwargs)[source]#

Triggered when the user sends a text message from XMPP to a bridged entity, e.g. to translated_user_name@slidge.example.com, or translated_group_name@slidge.example.com

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

Parameters:
  • text (str) – Content of the message

  • chat (Recipient) – Recipient of the message. LegacyContact instance for 1:1 chat, MUC instance for groups.

  • reply_to_msg_id – A legacy message ID if the message references (quotes) another message (XEP-0461)

  • reply_to_fallback_text – Content of the quoted text. Not necessarily set by XMPP clients

  • reply_to (Optional[Union[slidgnal.contact.Contact, slidgnal.group.Participant]]) – Author of the quoted message. LegacyContact instance for 1:1 chat, LegacyParticipant instance for groups. If None, should be interpreted as a self-reply if reply_to_msg_id is not None.

  • link_previews – A list of sender-generated link previews. At the time of writing, only Cheogram supports it.

  • mentions – (only for groups) A list of Contacts mentioned by their nicknames.

  • thread

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 on_file(chat, url, *, http_response, reply_to_msg_id=None, reply_to_fallback_text=None, reply_to=None, **_kwargs)[source]#

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

Parameters:
  • url (str) – URL of the file

  • chat (Recipient) – See BaseSession.on_text()

  • http_response – The HTTP GET response object on the URL

  • reply_to_msg_id – See BaseSession.on_text()

  • reply_to_fallback_text – See BaseSession.on_text()

  • reply_to (Optional[Union[slidgnal.contact.Contact, slidgnal.group.Participant]]) – See BaseSession.on_text()

  • thread

Returns:

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

static _get_args_from_entity(e)[source]#
async on_composing(c, thread=None)[source]#

Triggered when the user starts typing in a legacy chat (XEP-0085)

Parameters:
  • chat – See BaseSession.on_text()

  • thread

  • c (Recipient) –

async on_displayed(entity, legacy_msg_id, thread=None)[source]#

Triggered when the user reads a message in a legacy chat. (XEP-0333)

This is only possible if a valid legacy_msg_id was passed when transmitting a message from a legacy chat to the user, eg in slidge.contact.LegacyContact.send_text() or slidge.group.LegacyParticipant.send_text().

Parameters:
  • chat – See BaseSession.on_text()

  • legacy_msg_id (int) – Identifier of the message/

  • thread

  • entity (Recipient) –

async on_react(chat, legacy_msg_id, emojis, thread=None)[source]#

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

Parameters:
  • chat (Recipient) – See BaseSession.on_text()

  • thread

  • 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

async on_retract(c, legacy_msg_id, thread=None)[source]#

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

Parameters:
  • chat – See BaseSession.on_text()

  • thread

  • legacy_msg_id (int) – Legacy ID of the retracted message

  • c (Recipient) –

async add_device(uri)[source]#
Parameters:

uri (str) –

async on_avatar(bytes_, hash_, type_, width, height)[source]#

Triggered when the user uses modifies their avatar via XEP-0084.

Parameters:
  • bytes – The data of the avatar. According to the spec, this should always be a PNG, but some implementations do not respect that. If None it means the user has unpublished their avatar.

  • hash – The SHA1 hash of the avatar data. This is an identifier of the avatar.

  • type – The MIME type of the avatar.

  • width (Optional[int]) – The width of the avatar image.

  • height (Optional[int]) – The height of the avatar image.

  • bytes_ (Optional[bytes]) –

  • hash_ (Optional[str]) –

  • type_ (Optional[str]) –

Return type:

None

slidgnal.session.log[source]#