slidge.plugins.facebook#

Module Contents#

Classes#

Gateway

Must be subclassed by a plugin to set up various aspects of the XMPP

Contact

This class centralizes actions in relation to a specific legacy contact.

Roster

Virtual roster of a gateway user, that allows to represent all

Session

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

FacebookMessage

Messages

Functions#

Attributes#

log

class slidge.plugins.facebook.Gateway[source]#

Bases: slidge.BaseGateway

Must be subclassed by a plugin to set up various aspects of the XMPP component behaviour, such as its display name or its registration process.

On slidge launch, a singleton is instantiated, and it will be made available to public classes such LegacyContact or BaseSession as the .xmpp attribute. Since it inherits from slixmpp.componentxmpp.ComponentXMPP, this gives you a hand on low-level XMPP interactions via slixmpp plugins, e.g.:

self.send_presence(
    pfrom="somebody@component.example.com",
    pto="someonwelse@anotherexample.com",
)

However, you should not need to do so often since the classes of the plugin API provides higher level abstractions around most commonly needed use-cases, such as sending messages, or displaying a custom status.

REGISTRATION_INSTRUCTIONS = Enter facebook credentials[source]#
REGISTRATION_FIELDS[source]#
REGISTRATION_MULTISTEP = True[source]#
ROSTER_GROUP = Facebook[source]#
COMPONENT_NAME = Facebook (slidge)[source]#
COMPONENT_TYPE = facebook[source]#
COMPONENT_AVATAR = https://upload.wikimedia.org/wikipedia/commons/thumb/6/6c/Facebook_Messenger_logo_2018.svg/480px-...[source]#
SEARCH_TITLE = Search in your facebook friends[source]#
SEARCH_INSTRUCTIONS = Enter something that can be used to search for one of your friends, eg, a first name[source]#
SEARCH_FIELDS[source]#
class slidge.plugins.facebook.Contact(*a, **k)[source]#

Bases: slidge.LegacyContact[Session]

This class centralizes actions in relation to a specific legacy contact.

You shouldn’t create instances of contacts manually, but rather rely on LegacyRoster.by_legacy_id() to ensure that contact instances are singletons. The LegacyRoster instance of a session is accessible through the BaseSession.contacts attribute.

Typically, your plugin should have methods hook to the legacy events and call appropriate methods here to transmit the “legacy action” to the xmpp user. This should look like this:

Parameters
  • session – The session this contact is part of

  • legacy_id – The contact’s legacy ID

  • jid_username – User part of this contact’s ‘puppet’ JID. NB: case-insensitive, and some special characters are not allowed

legacy_id :str[source]#
async fb_id()[source]#
async populate_from_participant(participant, update_avatar=True)[source]#
Parameters

participant (maufbapi.types.graphql.ParticipantNode) –

class slidge.plugins.facebook.Roster(*a, **k)[source]#

Bases: slidge.LegacyRoster[Contact, Session]

Virtual roster of a gateway user, that allows to represent all of their contacts as singleton instances (if used properly and not too bugged).

Every BaseSession instance will have its own LegacyRoster instance accessible via the BaseSession.contacts attribute.

Typically, you will mostly use the LegacyRoster.by_legacy_id() function to retrieve a contact instance.

You might need to override LegacyRoster.legacy_id_to_jid_username() and/or LegacyRoster.jid_username_to_legacy_id() to incorporate some custom logic if you need some characters when translation JID user parts and legacy IDs.

async by_fb_id(fb_id)[source]#
Parameters

fb_id (int) –

Return type

Contact

async by_thread_key(t)[source]#
Parameters

t (maufbapi.types.mqtt.ThreadKey) –

async by_thread(t)[source]#
Parameters

t (maufbapi.types.graphql.Thread) –

class slidge.plugins.facebook.Session(user)[source]#

Bases: slidge.BaseSession[Contact, Roster, Gateway]

Represents a gateway user logged in to the 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.

fb_state :maufbapi.AndroidState[source]#
mqtt :maufbapi.AndroidMQTT[source]#
api :maufbapi.AndroidAPI[source]#
me :maufbapi.types.graphql.OwnInfo[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(n=2)[source]#
async logout()[source]#

Logout the gateway user from the legacy network.

Called on user unregistration and gateway shutdown.

async send_text(t, c, *, reply_to_msg_id=None)[source]#

Triggered when the user sends a text message from xmpp to a bridged contact, e.g. to translated_user_name@slidge.example.com.

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

Parameters
  • t (str) – Content of the message

  • c (Contact) – Recipient of the message

  • reply_to_msg_id

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(u, c, *, reply_to_msg_id=None)[source]#

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

Parameters
  • u (str) – URL of the file

  • c (Contact) – Recipient of the file

  • reply_to_msg_id

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

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

Parameters

c (Contact) – Recipient of the active chat state

async inactive(c)[source]#

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

Parameters

c (Contact) –

async composing(c)[source]#

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

Parameters

c (Contact) –

async paused(c)[source]#

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

Parameters

c (Contact) –

async displayed(legacy_msg_id, c)[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 on_fb_message(evt)[source]#
Parameters

evt (Union[maufbapi.types.mqtt.Message, maufbapi.types.mqtt.ExtendedMessage]) –

async on_fb_message_read(receipt)[source]#
Parameters

receipt (maufbapi.types.mqtt.ReadReceipt) –

async on_fb_typing(notification)[source]#
Parameters

notification (maufbapi.types.mqtt.TypingNotification) –

async on_fb_user_read(receipt)[source]#
Parameters

receipt (maufbapi.types.mqtt.OwnReadReceipt) –

async on_fb_reaction(reaction)[source]#
Parameters

reaction (maufbapi.types.mqtt.Reaction) –

async on_fb_unsend(unsend)[source]#
Parameters

unsend (maufbapi.types.mqtt.UnsendMessage) –

async correct(text, legacy_msg_id, c)[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
async react(legacy_msg_id, emojis, c)[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 (Contact) – Contact the reaction refers to

async retract(legacy_msg_id, c)[source]#

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

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

  • c (Contact) – 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

async static on_fb_event(evt)[source]#
class slidge.plugins.facebook.FacebookMessage[source]#
mid :str[source]#
timestamp_ms :int[source]#
class slidge.plugins.facebook.Messages[source]#
__len__()[source]#
add(m)[source]#
Parameters

m (FacebookMessage) –

pop_up_to(approx_t)[source]#
Parameters

approx_t (int) –

Return type

FacebookMessage

slidge.plugins.facebook.is_group_thread(t)[source]#
Parameters

t (maufbapi.types.mqtt.ThreadKey) –

slidge.plugins.facebook.log[source]#