Once authenticed, users can send or received messages such as: text, photo, vieo, audio, location, contact... To send a message contains media content (photo, video, audio, file...), you need to upload media content to your server first. Then you use Stringee SDK to send the uploaded url.
Create a message in JSON format:
// Text message
var txtMsg = {
type: 1,
convId: "YOUR_CONVERSATION_ID",
message: {
content: 'Hello'
}
};
In which:
message: {
// Audio
audio: {
duration: // number type, value in milliseconds.
filePath: // audio file's url.
},
// Contact
contact: {
vcard: // contact as vcard, string value.
}
// File
file: {
filePath: // file's url.
filename: ,
length: // number type, number of bytes
}
// Location
location: {
lat: // number type, latitude
lon: // number type, longitude
}
// Photo
photo: {
filePath: // photo file's url.
thumbnail: // thumbnail file's url.
ratio: // number type
}
// Text
content: ''
// Video
video: {
filePath: // photo file's url.
thumbnail: // thumbnail file's url.
ratio: // number type
duration: // number type, value in milliseconds.
}
// Sticker
sticker: {
name: // string type
category: // string type
}
}
Ex: Location message.
var locationMsg = {
convId: 'ABC',
type: 9, // location message type
message: {
location: {
lat: 123
lon: 456
}
},
}
Send a Message by calling:
this.client.current.sendMessage(message, (status, code, message) => {
console.log("status-" + status + " code-" + code + " message-" + message);
});
Messages are stored on Stringee server and cached on Local Database as well. You can get messages as follows:
To get local messages of a conversation, you call:
this.client.current.getLocalMessages(convId, count, isAscending, (status, code, message, messages) => {
console.log("status-" + status + " code-" + code + " message-" + message);
messages.map((message) => {
console.log("Message's Id" + message.id + "==== " + message.content);
});
});
In which:
To get latest messages from Stringee server, you call:
this.client.current.getLastMessages(convId, count, isAscending, (status, code, message, messages) => {
console.log("status-" + status + " code-" + code + " message-" + message);
messages.map((message) => {
console.log("Message's Id" + message.id + "==== " + message.content);
});
});
In which:
To get a list of messages tied to a conversation from server which have sequence greater than seq, you call:
this.client.current.getMessagesAfter(convId, sequence, count, isAscending, (status, code, message, messages) => {
console.log("status-" + status + " code-" + code + " message-" + message);
messages.map((message) => {
console.log("Message's Id" + message.id + "==== " + message.content);
});
});
In which:
To get a list of messages tied to a conversation from server which have sequence smaller than seq, you call:
this.client.current.getMessagesBefore(this.state.convId, sequence, count, isAscending, (status, code, message, messages) => {
console.log("status-" + status + " code-" + code + " message-" + message);
messages.map((message) => {
console.log("Message's Id" + message.id + "==== " + message.content);
});
});
In which:
Stringee keeps track of the recipient status of each message. There are five possible statuses: INITIALIZE, SENDING, SENT, DELIVERED, READ. Stringee automatically updates the recipient status to sent, delivered. The only update your app can perform is to mark a conversation's messages as read:
this.client.current.markConversationAsRead(this.state.convId, (status, code, message) => {
console.log("status-" + status + " code-" + code + " message-" + message);
});
Stringee notify you the status update of a message via the onObjectChange event of StringeeClient.
To delete a message, you call:
this.client.current.deleteMessage(conversationId, messageId, (status, code, message) => {
console.log("status-" + status + " code-" + code + " message-" + message);
});