AddressbookPlugin reference#

The complete AddressbookPlugin interface looks like this:

class tattler.server.pluginloader.AddressbookPlugin#

Base class for AddressBook plug-ins.

You can either implement the attributes() method, returning a dictionary with the relevant contacts – or implement methods for individual attributes: email(), mobile(), meth:first_name etc.

The default implementation for attributes() calls the individual email(), mobile() etc methods, so do not implement the latter ones by calling meth:attributes, as that would cause an infinite loop.

Unknown contacts should be None.

account_type(recipient_id, role=None)#

Return the type of account that the user is on, if known and relevant.

Parameters:
  • recipient_id (str) – Unique identifier for the intended recipient, e.g. user ID from IAM system.

  • role (Optional[str]) – Intended role within the account to get address for, e.g. ‘billing’ or ‘technical’.

Return type:

Optional[str]

Returns:

A descriptor of the account type the user is on (e.g. “free”, “paid”, “planX”), or None if unknown.

attributes(recipient_id, role=None)#

Return all attributes for a user at once.

You may either implement this method, or implement each of the alternative methods to look up individual contacts – such as email().

This method’s default implementation simply collects the attributes by calling the respective individual, e.g. ‘email’: self.email(). A key should be returned for every required vector name. The default implementation of this method simply collects the return values of the individual methods, such as {‘mobile’: self.mobile() }, and then adds aliases for the vector names, such as {‘sms’: =’mobile’, ‘whatsapp’: =’mobile’}.

Implementing this method is more efficient if your lookup returns all user contacts in one call, e.g. because they are all in one database. Implementing the individual contact methods may help to keep your logic simpler, if the look ups for each method actually involve different logic.

This is the method ultimately called by tattler.

Parameters:
  • recipient_id (str) – Unique identifier for the intended recipient, e.g. user ID from IAM system.

  • role (Optional[str]) – Intended role within the account to get address for, e.g. ‘billing’ or ‘technical’.

Return type:

Mapping[str, Optional[str]]

Returns:

Map of known contact types and either their value, or None if unknown, for at least {‘email’, ‘mobile’, ‘account_type’, ‘first_name’}.

email(recipient_id, role=None)#

Return the email address associated with a user identifier, if known.

Parameters:
  • recipient_id (str) – Unique identifier for the intended recipient, e.g. user ID from IAM system.

  • role (Optional[str]) – intended role within the account to get address for, e.g. ‘billing’ or ‘technical’.

Return type:

Optional[str]

Returns:

email address to deliver to, or None if unknown.

first_name(recipient_id, role=None)#

Return the user’s first name, if known.

Parameters:
  • recipient_id (str) – Unique identifier for the intended recipient, e.g. user ID from IAM system.

  • role (Optional[str]) – Intended role within the account to get address for, e.g. ‘billing’ or ‘technical’.

Return type:

Optional[str]

Returns:

User’s first name (e.g. “Paul”), or None if unknown.

language(recipient_id, role=None)#

Return the user’s language, if known; only supported in tattler enterprise edition.

Parameters:
  • recipient_id (str) – Unique identifier for the intended recipient, e.g. user ID from IAM system.

  • role (Optional[str]) – Intended role within the account to get address for, e.g. ‘billing’ or ‘technical’.

Return type:

Optional[str]

Returns:

Language code requested by the user (e.g. “en” or “en_US” – consult with template designer), or None if unknown.

mobile(recipient_id, role=None)#

Return the mobile number associated with a user identifier, if known.

Parameters:
  • recipient_id (str) – Unique identifier for the intended recipient, e.g. user ID from IAM system.

  • role (Optional[str]) – Intended role within the account to get address for, e.g. ‘billing’ or ‘technical’.

Return type:

Optional[str]

Returns:

Mobile number to deliver to, or None if unknown.

recipient_exists(recipient_id)#

Returns whether a user exists at all.

Parameters:
  • recipient_id (str) – Unique identifier for the intended recipient, e.g. user ID from IAM system.

  • role – Intended role within the account to get address for, e.g. ‘billing’ or ‘technical’.

Return type:

bool

Returns:

Whether an account exists for the recipient.