slidgnal.session

Attributes

Classes

Session

The session of a registered User.

Attachment

A file attachment to a message

Functions

get_url_bytes(client, url)

Get data from URL as raw bytes, if possible.

strip_quote_prefix(text)

Return multi-line text without leading quote marks (i.e. the ">" character).

make_sync(func, loop)

Wrap async function in synchronous operation, running against the given loop in thread-safe mode.

Module Contents

slidgnal.session.MESSAGE_LOGIN_SUCCESS = 'Login successful! You might need to repeat this process in the future if the Linked Device is...[source]
slidgnal.session.MESSAGE_LOGGED_OUT = 'You have been logged out, please use the re-login adhoc command and re-scan the QR code on your...[source]
slidgnal.session.Recipient[source]
class slidgnal.session.Session(user)[source]

Bases: slidge.BaseSession[str, Recipient]

The session of a registered User.

Represents a gateway user logged in to the legacy network and performing actions.

Will be instantiated automatically on slidge startup for each registered user, or upon registration for new (validated) users.

Must be subclassed for a functional Legacy Module.

Parameters:

user (slidge.GatewayUser)

contacts: slidgnal.contact.Roster[source]
xmpp: slidgnal.gateway.Gateway[source]

The gateway instance singleton. Use it for low-level XMPP calls or custom methods that are not session-specific.

signal[source]
__handle_event[source]
__message_reactions: dict[str, str][source]
__message_ids: dict[str, str][source]
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 handle_event(event, ptr)[source]

Handle incoming event, as propagated by the Signal adapter. Typically, events carry all state required for processing by the Gateway itself, and will do minimal processing themselves.

async handle_login(data)[source]

Handle login event, which either has us complete device linking out-of-bounds with a given QR code or completes linking with device credentials.

Parameters:

data (slidgnal.generated.signal.Login)

async handle_connect(data)[source]

Handle connection event, ensuring that the session is set up correctly for future events.

Parameters:

data (slidgnal.generated.signal.Connect)

async handle_archive_sync(data)[source]

Handle chat archive synchronization event, setting state for the session that ensures that we won’t be making future requests to fetch from the archive.

Parameters:

data (slidgnal.generated.signal.ArchiveSync)

async handle_logout(data)[source]

Handle remote Signal logout event, propagating status to gateway.

Parameters:

data (slidgnal.generated.signal.Logout)

async handle_contact(data)[source]

Handle incoming contact event, updating information from data given and adding to roster if needed.

Parameters:

data (slidgnal.generated.signal.Contact)

async handle_message(data)[source]

Handle incoming message, which is typically a plain-text message but can also denote more complex interactions such as reactions, message edits, etc.

Parameters:

data (slidgnal.generated.signal.Message)

async handle_typing(data)[source]

Handle incoming typing notification, as propagated by the Signal adapter.

Parameters:

data (slidgnal.generated.signal.Typing)

async handle_receipt(data)[source]

Handle incoming delivered/read receipt, as propagated by the Signal adapter.

Parameters:

data (slidgnal.generated.signal.Receipt)

async handle_delete(data)[source]

Handle incoming message deletion, as propagated by the Signal adapter.

Parameters:

data (slidgnal.generated.signal.Delete)

async on_text(chat, text, *, reply_to_msg_id=None, reply_to_fallback_text=None, reply_to=None, **_)[source]

Send outgoing plain-text message to given Signal contact.

Parameters:
  • chat (Recipient)

  • text (str)

  • reply_to_msg_id (str | None)

  • reply_to_fallback_text (str | None)

async on_file(chat, url, http_response, reply_to_msg_id=None, reply_to_fallback_text=None, reply_to=None, **_)[source]

Send outgoing media message (i.e. audio, image, document) to given Signal contact.

Parameters:
  • chat (Recipient)

  • url (str)

  • reply_to_msg_id (str | None)

  • reply_to_fallback_text (str | None)

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

Send or remove emoji reaction to existing Signal message. Slidge core makes sure that the emojis parameter is always empty or a single emoji.

Parameters:
  • chat (Recipient)

  • legacy_msg_id (str)

  • emojis (list[str])

async on_correct(chat, text, legacy_msg_id, thread=None, link_previews=(), mentions=None)[source]

Request correction (aka editing) for a given Signal message.

Parameters:
  • chat (Recipient)

  • text (str)

  • legacy_msg_id (str)

async on_presence(*args, **kwargs)[source]

Signal doesn’t support contact presence, so calls to this function are no-ops.

async on_active(*args, **kwargs)[source]

Signal has no equivalent to the “active” chat state, so calls to this function are no-ops.

async on_inactive(*args, **kwargs)[source]

Signal has no equivalent to the “inactive” chat state, so calls to this function are no-ops.

async on_composing(chat, thread=None)[source]

Send “started” typing state to given Signal contact, signifying that a message is currently being composed.

Parameters:

chat (Recipient)

async on_paused(chat, thread=None)[source]

Send “stopped” typing state to given Signal contact, signifying that an (unsent) message is no longer being composed.

Parameters:

chat (Recipient)

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

Send “read” receipt, signifying that the Signal message sent has been displayed on the XMPP client.

Parameters:
  • c (Recipient)

  • legacy_msg_id (str)

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

Request deletion (aka retraction) for a given Signal message.

Parameters:
  • c (Recipient)

  • legacy_msg_id (str)

async __get_recipient(legacy_sender_id, legacy_chat_id=None, is_carbon=False)[source]

Return correct recipient for given references to sender and chat IDs, the latter of which can either represent another contact, or a group-chat.

Parameters:
  • legacy_sender_id (str)

  • legacy_chat_id (str | None)

  • is_carbon (bool)

Return type:

Recipient

async __get_reply_to(data)[source]

Get message reference for reply data, or return None.

Parameters:

data (slidgnal.generated.signal.Reply)

Return type:

slidge.util.types.MessageReference | None

__set_reply_to(chat, message, reply_to_msg_id=None, reply_to_fallback_text=None, reply_to=None)[source]

Sets ReplyTo fields for given Message, returning the Message.

Parameters:
__set_original_message_id(new_legacy_message_id, original_legacy_msg_id)[source]

Set new message ID to original message ID mapping.

Parameters:
  • new_legacy_message_id (str)

  • original_legacy_msg_id (str)

Return type:

None

__get_original_message_id(new_legacy_message_id)[source]

Get original message ID for given new message ID.

Parameters:

new_legacy_message_id (str)

Return type:

str | None

__set_message_reaction(legacy_msg_id, emoji)[source]

Set message reaction reference for a legacy message ID.

Parameters:
  • legacy_msg_id (str)

  • emoji (str)

Return type:

None

__get_message_reaction(legacy_msg_id)[source]

Get message reaction reference for a legacy message ID.

Parameters:

legacy_msg_id (str)

Return type:

str | None

__reset_connected()[source]
class slidgnal.session.Attachment[source]

Bases: slidge.util.types.LegacyAttachment

A file attachment to a message

At the minimum, one of the path, steam, data or url attribute has to be set

To be used with LegacyContact.send_files() or LegacyParticipant.send_files()

static from_list(attachments)[source]
Async:

Parameters:

attachments (list[slidgnal.generated.signal.Attachment])

Return type:

list[Attachment]

static from_signal(attachment)[source]
Async:

Parameters:

attachment (slidgnal.generated.signal.Attachment)

Return type:

Attachment

async slidgnal.session.get_url_bytes(client, url)[source]

Get data from URL as raw bytes, if possible.

Parameters:
  • client (aiohttp.ClientSession)

  • url (str)

Return type:

bytes | None

slidgnal.session.strip_quote_prefix(text)[source]

Return multi-line text without leading quote marks (i.e. the “>” character).

Parameters:

text (str)

slidgnal.session.make_sync(func, loop)[source]

Wrap async function in synchronous operation, running against the given loop in thread-safe mode.