Suggestions

close search

Messages

Once authenticated, users can send or received messages such as: text, photo, video, 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

Create a message by using NewMessageInfo Object:

// Text message
const msg = new NewMessageInfo({
  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.

const msg = new NewMessageInfo({
  type: 9,
  convId: "YOUR_CONVERSATION_ID",
  message: {
    location: {
      lat: 123
      lon: 456
    }
  }
});

Send a message

Send a Message by calling:

conversation.sendMessage(msg).then(() => {
    console.log('sendMessage success');
}).catch(console.log);

Get Messages

Messages are stored on Stringee server and cached on Local Database as well. You can get messages as follows:

  1. 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:

    • convId: conversation's identifier.
    • count: number of messages.
    • isAscending: This param decide the order of the messages you will receive, sort by sequence attribute of message.
      • isAscending = true, Ascending.
      • isAscending = false, Descending.
  2. 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:

    • convId: conversation's identifier.
    • count: number of messages.
    • isAscending: This param decide the order of the messages you will receive, sort by sequence attribute of message.
      • isAscending = true, Ascending.
      • isAscending = false, Descending.
    • loadDeletedMessage: Load include deleted message
      • loadDeletedMessage = true, Load include deleted message.
      • loadDeletedMessage = false, Load not include deleted message.
    • loadDeletedMessageContent: Load include deleted message content
      • loadDeletedMessageContent = true, Load include deleted message content.
      • loadDeletedMessageContent = false, Load not include deleted message content.
  3. 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:

    • convId: conversation's identifier.
    • count: number of messages.
    • sequence: the sequence of the message
    • isAscending: This param decide the order of the messages you will receive, sort by sequence attribute of message.
      • isAscending = true, Ascending.
      • isAscending = false, Descending.
    • loadDeletedMessage: Load include deleted message
      • loadDeletedMessage = true, Load include deleted message.
      • loadDeletedMessage = false, Load not include deleted message.
    • loadDeletedMessageContent: Load include deleted message content
      • loadDeletedMessageContent = true, Load include deleted message content.
      • loadDeletedMessageContent = false, Load not include deleted message content.
  4. 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:

    • convId: conversation's identifier.
    • count: number of messages.
    • sequence: the sequence of the message
    • isAscending: This param decide the order of the messages you will receive, sort by sequence attribute of message.
      • isAscending = true, Ascending.
      • isAscending = false, Descending.
    • loadDeletedMessage: Load include deleted message
      • loadDeletedMessage = true, Load include deleted message.
      • loadDeletedMessage = false, Load not include deleted message.
    • loadDeletedMessageContent: Load include deleted message content
      • loadDeletedMessageContent = true, Load include deleted message content.
      • loadDeletedMessageContent = false, Load not include deleted message content.

Message statuses

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:

conversationm.markConversationAsRead().then(() => {
    console.log('markConversationAsRead success');
}).catch(console.log);

Stringee notify you the status update of a message via the onObjectChange event of StringeeClient.

Delete message

To delete a message, you call:

conversation.deleteMessage(messageId).then(() => {
    console.log('deleteMessage success');
}).catch(console.log);