More details and API reference: Messages
| Key | Type | Description |
|---|---|---|
number | string unique | Phone number of the conversation (recipient) (1-32 characters) |
timestamp | number | Date (unix ms, UTC) |
last_message_content | string | Content of the last message (1-1024 characters) |
self | boolean | Is phone number of custom_id equals to the last message sender? |
| Key | Type | Description |
|---|---|---|
number | string | Phone number of the sender (1-32 characters) |
timestamp | number | Date (unix ms, UTC) |
message_content | string | Message content (1-1024 characters) |
.send(senderCustomId, senderNumber, receiverCustomId, receiverNumber, receiverOnline, content)
Send message to profile
More details and API reference: (out.) Send message from server
| Key | Type | Description |
|---|---|---|
senderCustomId | string required | Unique identifier of the sender (1-64 characters) |
senderNumber | string required | Phone number of the sender profile (1-32 characters) |
receiverCustomId | string required | Unique identifier of the receiver (1-64 characters) |
receiverNumber | string required | Phone number of the receiver (1-32 characters) |
receiverOnline | boolean required | Specify if the receiver is connected on your server. If he's not, iPear send a notification to the recipient |
content | string required | Message content (1-1024 characters) |
void
app.messages.send("1234", // senderCustomId
"555-3467", // senderNumber
"9876", // receiverCustomId
"555-4500", // receiverNumber
true, // receiverIsOnline
"Hey, how are you?"); // Message content
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 (100 last) of conversations for a specific player/profile.
More details and API reference: (in.) Get conversation list
Event class: GetConversationsEvent
| Key | Type | Description |
|---|---|---|
.customId | string | CustomID of the event requester. |
| Key | Returns | Description |
|---|---|---|
.reply(conversations) | void | conversations is the conversation list, more information below |
| Key | Type | Description |
|---|---|---|
conversations (first parameter) | Conversation[] (required) | Conversation list (0-100 items) |
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);
});
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
| Key | Type | Description |
|---|---|---|
.customId | string | CustomID of the event requester. |
.conversationNumber | string | Conversation phone number. |
| Key | Returns | Description |
|---|---|---|
.reply(messages) | void | messages is the message list, more information below |
| Key | Type | Description |
|---|---|---|
messages (first parameter) | Message[] (required) | Message list (0-100 items) |
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);
});
Request to send a message for a specific player/profile.
More details and API reference: (in.) Publish message from mobile app
Event class: ReceiveMessageEvent
| Key | Type | Description |
|---|---|---|
.senderCustomId | string | Sender (event requester) custom ID |
.senderPhoneNumber | string | Sender phone number |
.recipientCustomId | string [or null] | Recipient custom ID. It's null if the recipient isn't registered on iPear |
.recipientPhoneNumber | string | Recipient phone number |
.content | string | Message content |
.timestamp | number | Timestamp (unix ms, UTC) |
| Key | Returns | Description |
|---|---|---|
.reply(success, recipient_online) | void | success and recipient_online are a boolean, more information below |
| Key | Type | Description |
|---|---|---|
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 |
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