Once authenticated, users can send or receive messages such as text, photo, video, audio, location, and contact. Before sending a media message, upload the file to your server, then pass its accessible URL in filePath.
Create a message by using NewMessageInfo Object:
import {NewMessageInfo} from 'stringee-react-native-v2';
// Text message
const msg = new NewMessageInfo({
type: 1,
convId: "YOUR_CONVERSATION_ID",
message: {
content: 'Hello'
}
});
In which:
message: {
// Audio
audio: {
duration: 1000, // milliseconds
filePath: 'https://example.com/audio.m4a'
},
// Contact
contact: {
vcard: 'BEGIN:VCARD...END:VCARD'
},
// File
file: {
filePath: 'https://example.com/file.pdf',
filename: 'file.pdf',
length: 1024
},
// Location
location: {
lat: 21.0278,
lon: 105.8342
},
// Photo
photo: {
filePath: 'https://example.com/photo.jpg',
thumbnail: 'https://example.com/photo-thumbnail.jpg',
ratio: 1.5
},
// Text
content: 'Hello',
// Video
video: {
filePath: 'https://example.com/video.mp4',
thumbnail: 'https://example.com/video-thumbnail.jpg',
ratio: 1.5,
duration: 5000
},
// Sticker
sticker: {
name: 'sticker-name',
category: 'sticker-category'
}
}
Ex: Location message.
const msg = new NewMessageInfo({
type: 9,
convId: "YOUR_CONVERSATION_ID",
message: {
location: {
lat: 21.0278,
lon: 105.8342
}
}
});
Send a Message by calling:
conversation.sendMessage(msg).then(() => {
console.log('sendMessage success');
}).catch(console.log);
Messages are stored on Stringee server and cached on Local Database as well. You can get messages as follows:
Get local messages
To get local messages of a conversation, you call:
conversation.getLocalMessages(count, isAscending).then(messages => {
messages.map(message => {
console.log('getLocalMessages', message);
});
}).catch(console.log);
In which:
Get last messages
To get latest messages from Stringee server, you call:
conversation.getLastMessages(count, isAscending, loadDeletedMessage, loadDeletedMessageContent).then(messages => {
messages.map(message => {
console.log('getLastMessages', message);
});
}).catch(console.log);
In which:
Get messages after
To get a list of messages tied to a conversation from server which have sequence greater than seq, you call:
conversation.getMessagesAfter(sequence, count, isAscending, loadDeletedMessage, loadDeletedMessageContent).then(messages => {
messages.map(message => {
console.log('getMessagesAfter', message);
});
}).catch(console.log);
In which:
Get messages before
To get a list of messages tied to a conversation from server which have sequence smaller than seq, you call:
conversation.getMessagesBefore(sequence, count, isAscending, loadDeletedMessage, loadDeletedMessageContent).then(messages => {
messages.map(message => {
console.log('getMessagesBefore', message);
});
}).catch(console.log);
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:
conversation.markConversationAsRead().then(() => {
console.log('markConversationAsRead success');
}).catch(console.log);
Stringee notify you the status update of a message via the onObjectChange event of StringeeClient.
To delete a message, you call:
conversation.deleteMessage(messageId).then(() => {
console.log('deleteMessage success');
}).catch(console.log);