slidge.plugins.facebook.session#

Module Contents#

Classes#

Session

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

Attributes#

slidge.plugins.facebook.session.Recipient[source]#
class slidge.plugins.facebook.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.

contacts: slidge.plugins.facebook.contact.Roster[source]#
mqtt: slidge.plugins.facebook.client.AndroidMQTT[source]#
api: maufbapi.AndroidAPI[source]#
me: maufbapi.types.graphql.OwnInfo[source]#
my_id: int[source]#
async login()[source]#

Login 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 add_friends()[source]#
async logout()[source]#

Logout the gateway user from the legacy network.

Called on user unregistration and gateway shutdown.

async send_text(chat, text, *, reply_to_msg_id=None, **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) – RecipientType 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 – 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.

  • 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:

str

async send_file(chat, url, http_response, reply_to_msg_id=None, **_)[source]#

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

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

Parameters:

c (Recipient) – RecipientType of the active chat state

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

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

Parameters:

c (Recipient) –

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

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

Parameters:

c (Recipient) –

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

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

Parameters:

c (Recipient) –

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

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 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 in LegacyContact.send_text() or slidge.LegacyContact.send_file().

Parameters:
  • text (str) –

  • legacy_msg_id (str) –

  • c (Recipient) –

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

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

Parameters:
  • legacy_msg_id (str) – 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 (Recipient) – Contact or MUC the reaction refers to

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

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

Parameters:
  • legacy_msg_id (str) – Legacy ID of the retracted message

  • c (Recipient) – The contact this retraction refers to

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:

Return type:

slidge.SearchResult

slidge.plugins.facebook.session.log[source]#