Contacts

More details and API reference: Contacts

Reference

'Contact' details

KeyTypeDescription
uidstring
unique
Unique identifier of the contact (1-32 characters)
displayNamestringDisplay name of the contact (1-64 characters)
numberstring
unique
Phone number, need to be unique in the contact list of the profile (1-32 characters)

'AddContact' details

Also used for 'update'.

KeyTypeDescription
displayNamestringDisplay name of the contact (1-64 characters)
numberstringPhone number (1-32 characters)

Methods

.add

.add(customId, contact)

Adds a contact to specific player/profile

More details and API reference: (out.) Add - server

Parameters

KeyTypeDescription
customIdstring
unique
required
Unique identifier of the player/profile (1-64 characters)
contactContact (required)Contact details

Returns

void

Example

Usage

app.contacts.add("1234", { 
    uid: "98694", 
    displayName: 'Jane Doe', 
    number: '555-93749' 
});

Result

No result

.update

.update(customId, contact)

Update contact of specific player/profile

More details and API reference: (out.) Update - server

Parameters

KeyTypeDescription
customIdstring
unique
required
Unique identifier of the player/profile (1-64 characters)
contactContact (required)Contact details to update

Returns

void

Example

Usage

app.contacts.update("1234", { 
    uid: "98694", 
    displayName: 'Jane Doe <3', 
    number: '555-93749'
});

Result

No result

.delete

.delete(customId, contactUid)

Remove contact from specific player/profile

More details and API reference: (out.) Remove - server

Parameters

KeyTypeDescription
customIdstring
unique
required
Unique identifier of the player/profile (1-64 characters)
contactUidstring
required
Unique identifier of the contact

Returns

void

Example

Usage

app.contacts.delete("1234", "98694");

Result

No result

Events

For each event you will receive an event param. It's a class object that allows you to get the event data and manage your reply to iPear.

With most of the events you need to send a reply to iPear with the method .reply(...).

In some cases you also have the .error(...) methods to specify at iPear that the data doesn't match your requirements.

'get'

Request list of contacts for a specific player/profile.

More details and API reference: (in.) Get contact list

Event class: GetContactsEvent

Properties

KeyTypeDescription
.customIdstringCustomID of the event requester.

Methods

KeyReturnsDescription
.reply(contacts)voidcontacts is the contacts list, more information below

Reply structure

KeyTypeDescription
contacts (first parameter)Contact[] (required)Contact list (0-100 items)

Example

app.contacts.events.on('get', (event) => {
    // local function to get contacts associated to the customId in my database
    const contacts = getContacts(event.customId);
    
    // TODO - process data to fit with structure requirements 
    
    // reply to iPear
    event.reply(contacts);
});

You can also use async if needed:

app.contacts.events.on('get', async (event) => {
    // local function to get contacts associated to the customId in my database
    const contacts = await getContacts(event.customId);
    
    // TODO - process data to fit with structure requirements 
    
    // reply to iPear
    event.reply(contacts);
});

'add'

A player wants to add a contact from mobile app.

More details and API reference: (in.) Add - mobile app

Event class: AddContactEvent

Properties

KeyTypeDescription
.customIdstringCustomID of the event requester.
.contactAddContactContact details sent by the requester

Methods

KeyReturnsDescription
.reply(contact)voidcontact is the full contact details, more information below
.error(code)voidcode - string, is one of theses: player-not-found, contact-already-exist, unknown

Reply structure

KeyTypeDescription
contact (first parameter)Contact (required)Contact details with uid

Example

app.contacts.events.on('add', (event) => {
    // we check if the custom id still exists in our database
    const isPlayerExist = checkCustomId(event.customId);
    if (!isPlayerExist) {
        // the player doesn't exist anymore
        return event.error('player-not-found');
    }
    
    // TODO - check request data with your requirements
    
    // check if the number exist
    const isNumberExist = checkNumberExist(event.contact.number);
    if (!isNumberExist) { 
        // doesn't exist, so we don't want to add it
        return event.error('unknown');
    }
    
    // check if the number is already in the contact list of the player
    const inContactList = checkContactsNumber(event.customId, event.contact.number);
    if (inContactList) {
        // the contact is already in the list
        return event.error('contact-already-exist');
    }
    
    // local function to insert contact associated to the customId in my database
    const contact = insertContactDatabase(event.contact.displayName, event.contact.number);
    
    // TODO - process data to fit with structure requirements 
    
    // reply to iPear
    event.reply(contact);
});

'update'

A player wants to update a contact from mobile app.

More details and API reference: (in.) Update - mobile app

Event class: UpdateContactEvent

Properties

KeyTypeDescription
.customIdstringCustomID of the event requester.
.contactUidstringContact unique identifier to update.
.updatedContactAddContactNew contact details sent by the requester

Methods

KeyReturnsDescription
.reply(contact)voidcontact is the full contact details, more information below
.error(code)voidcode - string, is one of theses: player-not-found, contact-already-exist, contact-not-found, unknown

Reply structure

KeyTypeDescription
contact (first parameter)Contact (required)Contact details with uid

Example

app.contacts.events.on('update', (event) => {
    // we check if the custom id still exists in our database
    const isPlayerExist = checkCustomId(event.customId);
    if (!isPlayerExist) {
        // the player doesn't exist anymore
        return event.error('player-not-found');
    }
    
    // TODO - check request data with your requirements
    
    // we get the current details to compare the data
    const currentDetails = getContactById(event.contactUid);
    
    if (currentDetails == null) {
        // couldn't find the contact with this uid
        return event.error('contact-not-found');
    }
    
    if (currentDetails.phoneNumber !== event.updatedContact.number) {
        // he changed the number, so check if the new number exist
        const isNumberExist = checkNumberExist(event.contact.number);
        if (!isNumberExist) {
            // doesn't exist, so we don't want to update it
            return event.error('unknown');
        }
        
        // check if the number is already in the contact list of the player
        const inContactList = checkContactsNumber(event.customId, event.contact.number);
        if (inContactList) {
            // A contact already exists with this number
            return event.error('contact-already-exist');
        }
    }
    
    // local function to insert contact associated to the customId in my database
    const contact = updateContact(event.contactUid, event.updatedContact.displayName, event.updatedContact.number);
    
    // TODO - process data to fit with structure requirements 
    
    // reply to iPear
    event.reply(contact);
});

'remove'

A player wants to delete a contact from mobile app.

More details and API reference: (in.) Remove - mobile app

Event class: RemoveContactEvent

Properties

KeyTypeDescription
.customIdstringCustomID of the event requester.
.contactUidstringContact unique identifier to remove.

Methods

KeyReturnsDescription
.reply(contactUid)voidcontactUid is the uid to remove
.error(code)voidcode - string, is one of theses: player-not-found, contact-not-found, unknown

Reply structure

KeyTypeDescription
contactUid (first parameter)string
required
Contact uid

Example

app.contacts.events.on('remove', (event) => {
    // we check if the custom id still exists in our database
    const isPlayerExist = checkCustomId(event.customId);
    if (!isPlayerExist) {
        // the player doesn't exist anymore
        return event.error('player-not-found');
    }
    
    // TODO - check request data with your requirements
    
    // we get the current details to compare the data
    const currentDetails = getContactById(event.contactUid);
    if (currentDetails == null) {
        // couldn't find the contact
        return event.error('contact-not-found')
    }
    
    // local function to insert contact associated to the customId in my database
    removeContactDatabase(event.contactUid);
    
    // reply to iPear
    event.reply(event.contactUid);
});

Powered by Doctave