slidge.plugins.whatsapp.session
#
Module Contents#
Classes#
Represents a gateway user logged in to the legacy network and performing actions. |
|
A file attachment to a message |
Functions#
|
|
|
Wrap async function in synchronous operation, running against the given loop in thread-safe mode. |
|
Return multi-line text without leading quote marks (i.e. the ">" character). |
Attributes#
- slidge.plugins.whatsapp.session.MESSAGE_PAIR_SUCCESS = 'Pairing successful! You might need to repeat this process in the future if the Linked Device is...'[source]#
- slidge.plugins.whatsapp.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 slidge.plugins.whatsapp.session.Session(user)[source]#
Bases:
slidge.BaseSession
[str
,Recipient
]Represents a gateway user logged in to the legacy network and performing actions.
Will be instantiated automatically when a user sends an online presence to the gateway component, as per XEP-0100.
Must be subclassed for a functional slidge plugin.
- Parameters:
user (slidge.GatewayUser) –
- async login()[source]#
Initiate login process and connect session to WhatsApp. Depending on existing state, login might either return having initiated the Linked Device registration process in the background, or will re-connect to a previously existing Linked Device session.
- async logout()[source]#
Logout from the active WhatsApp session. This will also force a remote log-out, and thus require pairing on next login. For simply disconnecting the active session, look at the
Session.disconnect()
function.
- async disconnect()[source]#
Disconnect the active WhatsApp session. This will not remove any local or remote state, and will thus allow previously authenticated sessions to re-authenticate without needing to pair.
- async handle_event(event, ptr)[source]#
Handle incoming event, as propagated by the WhatsApp adapter. Typically, events carry all state required for processing by the Gateway itself, and will do minimal processing themselves.
- async handle_chat_state(state)[source]#
- Parameters:
state (slidge.plugins.whatsapp.generated.whatsapp.ChatState) –
- async handle_receipt(receipt)[source]#
Handle incoming delivered/read receipt, as propagated by the WhatsApp adapter.
- Parameters:
receipt (slidge.plugins.whatsapp.generated.whatsapp.Receipt) –
- async _get_reply_to(message)[source]#
- Parameters:
message (slidge.plugins.whatsapp.generated.whatsapp.Message) –
- async _get_preview(text)[source]#
- Parameters:
text (str) –
- Return type:
Optional[slidge.plugins.whatsapp.generated.whatsapp.Preview]
- async handle_message(message)[source]#
Handle incoming message, as propagated by the WhatsApp adapter. Messages can be one of many types, including plain-text messages, media messages, reactions, etc., and may also include other aspects such as references to other messages for the purposes of quoting or correction.
- Parameters:
message (slidge.plugins.whatsapp.generated.whatsapp.Message) –
- async send_text(chat, text, *, reply_to_msg_id=None, reply_to_fallback_text=None, reply_to=None, **_)[source]#
Send outgoing plain-text message to given WhatsApp contact.
- async send_file(chat, url, http_response, reply_to_msg_id=None, **_)[source]#
Send outgoing media message (i.e. audio, image, document) to given WhatsApp contact.
- async active(c, thread=None)[source]#
WhatsApp has no equivalent to the “active” chat state, so calls to this function are no-ops.
- Parameters:
c (Recipient) –
- async inactive(c, thread=None)[source]#
WhatsApp has no equivalent to the “inactive” chat state, so calls to this function are no-ops.
- Parameters:
c (Recipient) –
- async composing(c, thread=None)[source]#
Send “composing” chat state to given WhatsApp contact, signifying that a message is currently being composed.
- Parameters:
c (Recipient) –
- async paused(c, thread=None)[source]#
Send “paused” chat state to given WhatsApp contact, signifying that an (unsent) message is no longer being composed.
- Parameters:
c (Recipient) –
- async displayed(c, legacy_msg_id, thread=None)[source]#
Send “read” receipt, signifying that the WhatsApp message sent has been displayed on the XMPP client.
- Parameters:
c (Recipient) –
legacy_msg_id (str) –
- async react(c, legacy_msg_id, emojis, thread=None)[source]#
Send or remove emoji reaction to existing WhatsApp message. Slidge core makes sure that the emojis parameter is always empty or a single emoji.
- async retract(c, legacy_msg_id, thread=None)[source]#
Request deletion (aka retraction) for a given WhatsApp message.
- Parameters:
c (Recipient) –
legacy_msg_id (str) –
- async correct(c, text, legacy_msg_id, thread=None)[source]#
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 inLegacyContact.send_text()
orslidge.LegacyContact.send_file()
.
- async search(form_values)[source]#
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:
- class slidge.plugins.whatsapp.session.Attachment[source]#
Bases:
slidge.util.types.LegacyAttachment
A file attachment to a message
At the minimum, one of the
path
,steam
,data
orurl
attribute has to be setTo be used with
LegacyContact.send_files()
orLegacyParticipant.send_files()
- static convert(wa_attachment)[source]#
- Parameters:
wa_attachment (slidge.plugins.whatsapp.generated.whatsapp.Attachment) –