Suggestions

close search

StringeeMessage

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 Flutter Plugin to send the uploaded URL.

1. Create a message

Instantiate a text message by calling:

StringeeMessage msg = = StringeeMessage.typeText(text);

In which:

To instantiate other types of message, you call:

///Photo
StringeeMessage msg = = StringeeMessage.typePhoto(filePath);

///Video
StringeeMessage msg = = StringeeMessage.typeVideo(filePath, duration);

///Audio
StringeeMessage msg = = StringeeMessage.typeAudio(filePath, duration);

///File
StringeeMessage msg = = StringeeMessage.typeFile(filePath);

///Link
StringeeMessage msg = = StringeeMessage.typeLink(text);

///Location
StringeeMessage msg = = StringeeMessage.typeLocation(latitude, longitude);

///Contact
StringeeMessage msg = = StringeeMessage.typeContact(vcard);

///Sticker
StringeeMessage msg = = StringeeMessage.typeSticker(stickerCategory, stickerName);

2. Send a message

After create a StringeeMessage, call _conversation.sendMessage(msg) to send a message
StringeeMessage msg = = StringeeMessage.typeText(text);

_conversation.sendMessage(msg).then((value) {
    print("status-" + value['status'] + " code-" + value['code'] + " message-" + value['message']);
});

Before you can send/receive a sticker message, you must upload sticker sets to your server first.

3. Get Messages

Messages are stored on Stringee server and cached on the local database as well. You can get messages as follows:

3.1. Get local messages

To get local messages of a conversation, you call:

_conversation.getLocalMessages(count).then((value) {
    print("status-" + value['status'] + " code-" + value['code'] + " message-" + value['message']);
    List<StringeeMessage> msgs = value['body'];
});

In which:

3.2. Get latest messages

To get latest messages from Stringee server, you call:

_conversation.getLastMessages(count).then((value) {
    print("status-" + value['status'] + " code-" + value['code'] + " message-" + value['message']);
    List<StringeeMessage> msgs = value['body'];
});

In which:

3.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(count, seq).then((value) {
    print("status-" + value['status'] + " code-" + value['code'] + " message-" + value['message']);
    List<StringeeMessage> msgs = value['body'];
});

In which:

3.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(count, seq).then((value) { print("status-" + value['status'] + " code-" + value['code'] + " message-" + value['message']); List msgs = value['body']; });

In which:

4. Message statuses

Stringee keeps track of the recipient status of each message. There are five possible statuses in MsgState: 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.markAsRead().then((value) {
        print("status-" + value['status'] + " code-" + value['code'] + " message-" + value['message']);
    });

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

5. Delete messages

To delete messages, you call:

_conversation.deleteMessages(msgIds).then((value) {
print("status-" + value['status'] + " code-" + value['code'] + " message-" + value['message']);
});

In which:

6. Pin/Unpin a message

To pin or unpin a message, you call:

_conversation.pinOrUnPin(pinOrUnPin).then((value) {
print("status-" + value['status'] + " code-" + value['code'] + " message-" + value['message']);
});

In which: