Messaging

If you need translation feature, see below.

Message translation feature is provided through Google Cloud Translation. To use this feature, register an appropriate Google Cloud Service Account Key on our dashboard.

  • Setting translationLanguage property in TPMessageRetrievalParams object with language code (ISO-639) retrieves message with its translated text.

  • Setting translationLanguage property in TPMessageSendParams with language code (ISO-639) when sending message will automatically translate the message text.

  • Supported languages (ISO-639) can be found here.

  • Calling 'getTranslatedText' on TPMessage object will return a Key-Value map. Translated text(value) can be accessed from the map by using language code (used in 'translationLanguage(s)' parameter) as key.

1. Get Messages

Messages are sorted by most recent (default).

Setting translationLanguage property in TPMessageRetrievalParams object will return TPMessage objects with translated texts via success block (success closure).

  • Use this to translate channel messages from the past.

  • For realtime message translation, see this.

  • TPMessageRetrievalParams class is available starting from TalkPlus Android SDK v0.5.3.

// get messages from channelget messages 
TPMessageRetrievalParams params = new TPMessageRetrievalParams.Builder(channel)
        .setLastMessage(lastMessage)
        .setTranslationLanguage(translationLanguage)
        .build();
                
TalkPlus.getMessages(params,
    new TPCallbackListener<List<TPMessage>, Boolean>() {
    @Override
    public void onSuccess(List<TPMessage> tpMessages, Boolean hasNext) {
        
    }
    @Override
    public void onFailure(int errorCode, Exception exception) {

    }
});

2. View Messages With File Upload

View messages with file attachment.

Messages are sorted by most recent (default).

Setting translationLanguage property in TPMessageRetrievalParams object will return TPMessage objects with translated texts via success block (success closure).

  • Use this to translate channel messages from the past.

  • For realtime message translation, see this.

  • TPMessageRetrievalParams class is available starting from TalkPlus Android SDK v0.5.3.

TPMessageRetrievalParams params = new TPMessageRetrievalParams.Builder(channel)
        .setLastMessage(lastMessage)
        .setTranslationLanguage(translationLanguage)
        .build();
        
TalkPlus.getFileMessages(params,
    new TPCallbackListener<List<TPMessage>, Boolean>() {
    @Override
    public void onSuccess(List<TPMessage> tpMessages, Boolean hasNext) {
        
    }
    @Override
    public void onFailure(int errorCode, Exception exception) {

    }
});

3. Send Message

The following message types are supported: text, hidden, custom.

  • Push notification is not sent for hidden message type.

  • admin, admin_hidden message type can only be sent from TalkPlus dashboard or by calling REST API.

  • If you have users you want to mention, you can pass an array of user IDs in the mentions field.

  • You can enter up to 10 key-value pairs in data field. The maximum size of key is 128 characters and the maximum size of value is 1024 characters. Both key and value must be strings.

  • Both message text and data cannot be empty when sending a message.

  • The maximum size of message text is 8192 characters.

  • The maximum file upload size is 15MB.

    • If you need to handle files bigger than 15MB, see this.

  • Emojis supported by UTF-8 can be used in message text.

  • For custom emojis, required values can be put into message text then parsed directly.

Setting translationLanguages property in TPMessageSendParams object will return TPMessage objects with translated texts via ''success block (success closure). Message recipient will be able to check the message via "onMessageReceived" callback event

  • TPMessageSendParams class is available starting from TalkPlus Android SDK v0.5.3.

// send message
TPMessageSendParams params = new TPMessageSendParams.Builder(channel,
        TPMessageSendParams.MessageType.TEXT,
        TPMessageSendParams.ContentType.TEXT)
        .setText(textMessage)
        .setMentions(mentionsUserIDs)
        .setParentMessageId(parentMessageId)
        .setMetaData(metaData)
        .setFileUrl()
        .setTranslationLanguages(translationLanguages)
        .build();
                
TalkPlus.sendMessage(params, 
    new TalkPlus.CallbackListener<TPMessage>() {
        @Override
        public void onSuccess(TPMessage tpMessage) { 
        }
        @Override
        public void onFailure(int errorCode, Exception exception) {
        }
    }
);

// upload file
TPMessageSendParams params = new TPMessageSendParams.Builder(channel,
        TPMessageSendParams.MessageType.TEXT,
        TPMessageSendParams.ContentType.FILE)
        .setFile(file)
        .setMentions(mentionsUserIDs)
        .setParentMessageId(parentMessageId)
        .setMetaData(metaData)
        .setTranslationLanguages(translationLanguages)
        .build();
                
TalkPlus.sendMessage(params, 
    new TalkPlus.CallbackListener<TPMessage>() {
        @Override
        public void onSuccess(TPMessage tpMessage) { 
        }
        @Override
        public void onFailure(int errorCode, Exception exception) {
        }
    }
);

4. Get Message

View a single message.

TPMessageRetrievalParams params = new TPMessageRetrievalParams.Builder(channel)
        .setMessageId(messageId)
        .setTranslationLanguage(translationLanguage)
        .build();
        
TalkPlus.getMessage(params, new CallbackListener<TPMessage>() {
    @Override
    public void onSuccess(TPMessage tpMessage) {
        
    }
    @Override
    public void onFailure(int errorCode, Exception exception) {

    }
});

5. Reply To Message

Reply to another message.

TPMessageSendParams params = new TPMessageSendParams.Builder(channel)
        .setMessageId(messageId)
        .setTranslationLanguage(translationLanguage)
        .build();
        
params.textMessage = "hello"
params.parentMessageId = "anotherMessageIdThatIamReplyingTo"

TalkPlus.sendMessage(params, new CallbackListener<TPMessage> {
    @Override
    public void onSuccess(TPMessage tpMessage) {
        
    }
    @Override
    public void onFailure(int errorCode, Exception exception) {

    }
});

6. Mark As Read

You can mark a channel as read.

TalkPlus.markAsReadChannel(channel, 
    new TalkPlus.CallbackListener<TPChannel>() {
        @Override
        public void onSuccess(tpChannel: TPChannel) {
        }
        @Override
        public void onFailure(int errorCode, Exception exception) {
        }
    }
);

7. React To Message

You can add/remove reaction to a message.

  • reaction must be alphanumeric and between 1 and 64 characters long.

  • Each message can have up to 10 reaction types.

  • Each reaction type can contain up to 100 user IDs.

// add reaction
TalkPlus.addMessageReaction(tpMessage, 
    "happy", 
    new CallbackListener<TPMessage>() {
        @Override
        public void onSuccess(TPMessage tpMessage) {            
        }
        @Override
        public void onFailure(int errorCode, Exception exception) {
        }
    }
);

// remove reaction
TalkPlus.removeMessageReaction(tpMessage, 
    "happy", 
    new CallbackListener<TPMessage>() {
        @Override
        public void onSuccess(TPMessage tpMessage) {            
        }
        @Override
        public void onFailure(int errorCode, Exception exception) {
        }
    }
);

// view message reactions
tpMessage.getReactions();
/*
{
    "happy": [
        "user1",
        "user2"
    ],
    "sad": [
        "user3"
    ]
}
*/

8. Get Unread Message Count

You can find out how many channel members have not read a particular message.

tpChannel.getMessageUnreadCount(tpMessage);

9. Delete Message

You can delete your own message.

TalkPlus.deleteMessage(channel, 
    message, 
    new TalkPlus.CallbackListener<Void>() {
        @Override
        public void onSuccess(Void unused) {
        }
        @Override
        public void onFailure(int errorCode, Exception exception) {
        }
    }
);

Last updated