Messages

More details and API reference: Messages

Reference

'Conversation' details

KeyTypeDescription
numberstring
unique
Phone number of the conversation (recipient) (1-32 characters)
timestampnumberDate (unix ms, UTC)
last_message_contentstringContent of the last message (1-1024 characters)
selfbooleanIs phone number of custom_id equals to the last message sender?

'Message' details

KeyTypeDescription
numberstringPhone number of the sender (1-32 characters)
timestampnumberDate (unix ms, UTC)
message_contentstringMessage content (1-1024 characters)

Methods

.send

.send(senderCustomId, senderNumber, receiverCustomId, receiverNumber, receiverOnline, content)

Send message to profile

More details and API reference: (out.) Send message from server

Parameters

KeyTypeDescription
senderCustomIdstring
required
Unique identifier of the sender (1-64 characters)
senderNumberstring
required
Phone number of the sender profile (1-32 characters)
receiverCustomIdstring
required
Unique identifier of the receiver (1-64 characters)
receiverNumberstring
required
Phone number of the receiver (1-32 characters)
receiverOnlineboolean
required
Specify if the receiver is connected on your server. If he's not, iPear send a notification to the recipient
contentstring
required
Message content (1-1024 characters)

Returns

void

Example

Usage

app.messages.send("1234", // senderCustomId
    "555-3467", // senderNumber
    "9876", // receiverCustomId
    "555-4500", // receiverNumber
    true, // receiverIsOnline
    "Hey, how are you?"); // Message content

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.

'list'

Request list (100 last) of conversations for a specific player/profile.

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

Event class: GetConversationsEvent

Properties

KeyTypeDescription
.customIdstringCustomID of the event requester.

Methods

KeyReturnsDescription
.reply(conversations)voidconversations is the conversation list, more information below

Reply structure

KeyTypeDescription
conversations (first parameter)Conversation[] (required)Conversation list (0-100 items)

Example

app.messages.events.on('list', (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');
    }
    
    // local function to get conversations associated to the customId in my database
    const conversations = getConversations(event.customId);
    
    // TODO - process data to fit with structure requirements 
    
    // reply to iPear
    event.reply(conversations);
});

'conversation'

Request the last 100 messages of one conversation for a specific player/profile.

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

Event class: GetConversationEvent

Properties

KeyTypeDescription
.customIdstringCustomID of the event requester.
.conversationNumberstringConversation phone number.

Methods

KeyReturnsDescription
.reply(messages)voidmessages is the message list, more information below

Reply structure

KeyTypeDescription
messages (first parameter)Message[] (required)Message list (0-100 items)

Example

app.messages.events.on('conversation', (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');
    }
    
    // local function to get messages associated to the customId and the conversation number in my database
    const messages = getMessages(event.customId);
    
    // TODO - process data to fit with structure requirements 
    
    // reply to iPear
    event.reply(messages);
});

'message'

Request to send a message for a specific player/profile.

More details and API reference: (in.) Publish message from mobile app

Event class: ReceiveMessageEvent

Properties

KeyTypeDescription
.senderCustomIdstringSender (event requester) custom ID
.senderPhoneNumberstringSender phone number
.recipientCustomIdstring [or null]Recipient custom ID. It's null if the recipient isn't registered on iPear
.recipientPhoneNumberstringRecipient phone number
.contentstringMessage content
.timestampnumberTimestamp (unix ms, UTC)

Methods

KeyReturnsDescription
.reply(success, recipient_online)voidsuccess and recipient_online are a boolean, more information below

Reply structure

KeyTypeDescription
success (1st parameter)boolean
required
The message has been saved/sent
recipient_online (2nd parameter)boolean
required
Recipient online? If he's, then iPear doesn't send the notification

Example

app.messages.events.on('message', (event) => {
    // we check if the sender custom id still exists in our database
    const isSenderExist = checkCustomId(event.senderCustomId);
    if (!isSenderExist) {
        // the player doesn't exist anymore
        return event.reply(false, false);
    }
    // we retrieve the recipient custom id from our database if iPear does not have access to it
    const recipientCustomId = event.recipientCustomId ? event.recipientCustomId : getCustomId(event.recipientPhoneNumber);
    if (recipientCustomId == null) {
        // the recipient doesn't exist in database
        return event.reply(false, false);
    }
    const isPhoneNumberExist = isPhoneNumberValid(event.recipientPhoneNumber);
    if (!isPhoneNumberValid) {
        // the phone number doesn't exist
        return event.reply(false, false);
    }
    
    // TODO - check if data meets your requirements (for example message length...)
    
    // local function to get conversations associated to the customId in my database
    const conversations = insertMessage(event.senderPhoneNumber, event.recipientPhoneNumber, event.content);
    
    // ESX example
    const isRecipientOnline = ESX.FromPlayerId(recipientCustomId);
    if (isRecipientOnline) {
        // TODO - send ingame notification here
    }

    // reply to iPear
    event.reply(true, isRecipientOnline);
});

Powered by Doctave