slidgnal.session¶
Attributes¶
Classes¶
The session of a registered User. |
|
A file attachment to a message |
Functions¶
|
Get data from URL as raw bytes, if possible. |
|
Return multi-line text without leading quote marks (i.e. the ">" character). |
|
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]¶
- 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.
- 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:
- async handle_connect(data)[source]¶
Handle connection event, ensuring that the session is set up correctly for future events.
- Parameters:
- 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:
- async handle_logout(data)[source]¶
Handle remote Signal logout event, propagating status to gateway.
- Parameters:
- async handle_contact(data)[source]¶
Handle incoming contact event, updating information from data given and adding to roster if needed.
- Parameters:
- 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:
- async handle_typing(data)[source]¶
Handle incoming typing notification, as propagated by the Signal adapter.
- Parameters:
- async handle_receipt(data)[source]¶
Handle incoming delivered/read receipt, as propagated by the Signal adapter.
- Parameters:
- async handle_delete(data)[source]¶
Handle incoming message deletion, as propagated by the Signal adapter.
- Parameters:
- 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.
- 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.
- 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.
- async on_correct(chat, text, legacy_msg_id, thread=None, link_previews=(), mentions=None)[source]¶
Request correction (aka editing) for a given Signal message.
- 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.
- async __get_reply_to(data)[source]¶
Get message reference for reply data, or return None.
- Parameters:
- 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:
chat (Recipient)
message (slidgnal.generated.signal.Message)
reply_to_msg_id (str | None)
reply_to_fallback_text (str | None)
- __set_original_message_id(new_legacy_message_id, original_legacy_msg_id)[source]¶
Set new message ID to original message ID mapping.
- __get_original_message_id(new_legacy_message_id)[source]¶
Get original message ID for given new message ID.
- __set_message_reaction(legacy_msg_id, emoji)[source]¶
Set message reaction reference for a legacy message ID.
- class slidgnal.session.Attachment[source]¶
Bases:
slidge.util.types.LegacyAttachmentA file attachment to a message
At the minimum, one of the
path,steam,dataorurlattribute has to be setTo be used with
LegacyContact.send_files()orLegacyParticipant.send_files()- static from_list(attachments)[source]¶
- Async:
- Parameters:
attachments (list[slidgnal.generated.signal.Attachment])
- Return type:
- static from_signal(attachment)[source]¶
- Async:
- Parameters:
attachment (slidgnal.generated.signal.Attachment)
- Return type:
- async slidgnal.session.get_url_bytes(client, url)[source]¶
Get data from URL as raw bytes, if possible.