More details and API reference: Contacts
| Key | Type | Description |
|---|---|---|
uid | string unique | Unique identifier of the contact (1-32 characters) |
displayName | string | Display name of the contact (1-64 characters) |
number | string unique | Phone number, need to be unique in the contact list of the profile (1-32 characters) |
Also used for 'update'.
| Key | Type | Description |
|---|---|---|
displayName | string | Display name of the contact (1-64 characters) |
number | string | Phone number (1-32 characters) |
.add(customId, contact)
Adds a contact to specific player/profile
More details and API reference: (out.) Add - server
| Key | Type | Description |
|---|---|---|
customId | string unique required | Unique identifier of the player/profile (1-64 characters) |
contact | Contact (required) | Contact details |
void
app.contacts.add("1234", {
uid: "98694",
displayName: 'Jane Doe',
number: '555-93749'
});
No result
.update(customId, contact)
Update contact of specific player/profile
More details and API reference: (out.) Update - server
| Key | Type | Description |
|---|---|---|
customId | string unique required | Unique identifier of the player/profile (1-64 characters) |
contact | Contact (required) | Contact details to update |
void
app.contacts.update("1234", {
uid: "98694",
displayName: 'Jane Doe <3',
number: '555-93749'
});
No result
.delete(customId, contactUid)
Remove contact from specific player/profile
More details and API reference: (out.) Remove - server
| Key | Type | Description |
|---|---|---|
customId | string unique required | Unique identifier of the player/profile (1-64 characters) |
contactUid | string required | Unique identifier of the contact |
void
app.contacts.delete("1234", "98694");
No result
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.
Request list of contacts for a specific player/profile.
More details and API reference: (in.) Get contact list
Event class: GetContactsEvent
| Key | Type | Description |
|---|---|---|
.customId | string | CustomID of the event requester. |
| Key | Returns | Description |
|---|---|---|
.reply(contacts) | void | contacts is the contacts list, more information below |
| Key | Type | Description |
|---|---|---|
contacts (first parameter) | Contact[] (required) | Contact list (0-100 items) |
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);
});
A player wants to add a contact from mobile app.
More details and API reference: (in.) Add - mobile app
Event class: AddContactEvent
| Key | Type | Description |
|---|---|---|
.customId | string | CustomID of the event requester. |
.contact | AddContact | Contact details sent by the requester |
| Key | Returns | Description |
|---|---|---|
.reply(contact) | void | contact is the full contact details, more information below |
.error(code) | void | code - string, is one of theses: player-not-found, contact-already-exist, unknown |
| Key | Type | Description |
|---|---|---|
contact (first parameter) | Contact (required) | Contact details with uid |
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);
});
A player wants to update a contact from mobile app.
More details and API reference: (in.) Update - mobile app
Event class: UpdateContactEvent
| Key | Type | Description |
|---|---|---|
.customId | string | CustomID of the event requester. |
.contactUid | string | Contact unique identifier to update. |
.updatedContact | AddContact | New contact details sent by the requester |
| Key | Returns | Description |
|---|---|---|
.reply(contact) | void | contact is the full contact details, more information below |
.error(code) | void | code - string, is one of theses: player-not-found, contact-already-exist, contact-not-found, unknown |
| Key | Type | Description |
|---|---|---|
contact (first parameter) | Contact (required) | Contact details with uid |
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);
});
A player wants to delete a contact from mobile app.
More details and API reference: (in.) Remove - mobile app
Event class: RemoveContactEvent
| Key | Type | Description |
|---|---|---|
.customId | string | CustomID of the event requester. |
.contactUid | string | Contact unique identifier to remove. |
| Key | Returns | Description |
|---|---|---|
.reply(contactUid) | void | contactUid is the uid to remove |
.error(code) | void | code - string, is one of theses: player-not-found, contact-not-found, unknown |
| Key | Type | Description |
|---|---|---|
contactUid (first parameter) | string required | Contact uid |
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