Messages
This section contains what all messages related actions can be performed using Channelize.io Android API SDK functions.
Unread message count
Retrieves the total number of unread messages for a user.
channelizeApi.getTotalUnReadMessageCount(new CompletionHandler<TotalCountResponse>() {
@Override
public void onComplete(TotalCountResponse result, ChannelizeError error) {
int count = result.getCount();
}
});
Retrieve Messages List
Retrieves all the messages of a conversation.
* @param CONVERSATION_ID (Required, String): The unique ID of the targeted conversation.
* @param conversationQuery Query for filtering the results.
ConversationQuery conversationQuery = new ConversationQuery.Builder()
.setMessageOwnerId(USER_ID) // The unique ID of the target user.
.setMessageContentType(0) // Specifies the type of message. Allowed Values are 0,1,2 ,and 3 for text/media, meta message, sticker/gif and location messages respectively.
.setMessageAttachmentType("text, audio, video") // Specifies the type of attachment. This is used to further filter the text/media contentType. Allowed values are text, image, audio, and video.
.setSorting(ConversationQuery.SORT_ASCENDING) // Specifies the sorting criteria for the returned results.
.setLimit(20) // Specifies the number of results to return in a single request.
.setOffset(0) // Specifies the number of results you want to skip from the beginning. (Useful in pagination)
.build();
channelizeApi.getMessages(CONVERSATION_ID, conversationQuery, new CompletionHandler<ListMessageResponse>() {
@Override
public void onComplete(ListMessageResponse result, ChannelizeError error) {
if (result != null) {
List<Message> messageList = result.getMessages();
}
}
});
Total Messages Count
Retrieves the total number of messages in a conversation.
* @param CONVERSATION_ID (Required, String): The unique ID of the targeted conversation.
* @param conversationQuery Query for filtering the results.
ConversationQuery conversationQuery = new ConversationQuery.Builder()
.setMessageOwnerId(USER_ID) // The unique ID of the target user.
.setMessageContentType(0) // Specifies the type of message. Allowed Values are 0,1,2 ,and 3 for text/media, meta message, sticker/gif and location messages respectively.
.setMessageAttachmentType("text,audio,video") // Specifies the type of attachment. This is used to further filter the text/media contentType. Allowed values are text, image, audio, and video.
.build();
channelizeApi.getTotalMessageCount(CONVERSATION_ID, conversationQuery, new CompletionHandler<TotalCountResponse>() {
@Override
public void onComplete(TotalCountResponse result, ChannelizeError error) {
int count = result.getCount();
}
});
Send Message
Sends a message to a user.
* @param CONVERSATION_MEMBERS (Required: Set<String>): Set of unique ID of the users who'll get the message.
* @param messageQuery (Required): Query for sending a message.
MessageQuery messageQuery = new MessageQuery.Builder()
.setMessageAttachmentType(ApiConstants.ATTACHMENT_TEXT) // Specifies the type of attachment. Must be one of @ATTACHMENT. ({ATTACHMENT_TEXT, ATTACHMENT_IMAGE, ATTACHMENT_VIDEO, ATTACHMENT_AUDIO, ATTACHMENT_STICKER, ATTACHMENT_GIF, ATTACHMENT_LOCATION})
.setUserId(RECEIVER_USER_ID) // The unique ID of the specific user who'll get the message. (If no ConversationId)
.setConversationId(CONERSATION_ID) // The unique ID of the conversation where the message is sent to. (If no UserId)
.setMessageId(UUID.randomUUID().toString()) // Unique 32 digit message ID, use **UUID.randomUUID().toString()** to generate the random unique messageId while sending a new message.
.setMessageBody("Hello") // The content of the message.
.setTaggedMemberArray(TAG_MEMBER_ARRAY) // Specifies a JSONArray of members that are tagged in a message.
.setGifSticker(ORIGINAL_URL, STILL_URL, DOWNSAMPLED_URL) // If you're sending a message with Sticker/GIF.
.setLocation(LOCATION) // Specifies the location class object containing details of the coordinates i.e Latitude, Longitude, Title & Address.
.build();
channelizeApi.sendMessage(CONVERSATION_MEMBERS, messageQuery, new CompletionHandler<Message>() {
@Override
public void onComplete(Message message, ChannelizeError error) {
}
});
Send a File Attachment:
* @param FILE_PATH (Required: String): Local path of the file.
* @param THUMBNAIL_FILE_PATH (Required: String): Local path of the thumbnail image of the file.
* @param CONVERSATION_MEMBERS (Required: Set<String>): Set of user IDs that're part of a conversation.
* @param messageQuery (Required: MessageQuery): Query for sending a message.
MessageQuery messageQuery = new MessageQuery.Builder()
.setMessageAttachmentType(ApiConstants.ATTACHMENT_IMAGE) // Specifies the type of attachment. Must be one of @ATTACHMENT. ({ATTACHMENT_IMAGE, ATTACHMENT_VIDEO, ATTACHMENT_AUDIO})
.setUserId(RECEIVER_USER_ID) // The unique ID of the specific user who'll get the message. (If no ConversationId)
.setConversationId(CONERSATION_ID) // The unique ID of the conversation where the message is sent to. (If no UserId)
.setMessageId(UUID.randomUUID().toString()) // Unique 32 digit message ID, use **UUID.randomUUID().toString()** to generate the random unique messageId while sending a new message.
.build();
channelizeApi.sendFileMessage(FILE_PATH, THUMBNAIL_FILE_PATH, CONVERSATION_MEMBERS, messageQuery, new CompletionHandler<Message>() {
@Override
public void onComplete(Message message, ChannelizeError error) {
}
});
Quote/Reply a Message
* @param CONVERSATION_MEMBERS (Required: Set<String>): Set of user IDs that're part of a conversation.
* @param QUOTED_MESSAGE (Required: Message): The original message which is quoted/replied.
* @param messageQuery (Required): Query for sending a message.
MessageQuery messageQuery = new MessageQuery.Builder()
.setMessageAttachmentType(ApiConstants.ATTACHMENT_TEXT) // Specifies the type of attachment. Must be one of @ATTACHMENT. ({ATTACHMENT_TEXT})
.setUserId(RECEIVER_USER_ID) // The unique ID of the specific user who'll get the message. (If no ConversationId)
.setConversationId(CONERSATION_ID) // The unique ID of the conversation where the message is sent to. (If no UserId)
.setMessageId(UUID.randomUUID().toString()) // Unique 32 digit message ID, use **UUID.randomUUID().toString()** to generate the random unique messageId while sending a new message.
.setMessageBody("Hello") // The content of the message.
.setTaggedMemberArray(TAG_MEMBER_ARRAY) // Specifies a JSONArray of members that are tagged in a message.
.build();
channelizeApi.quoteMessage(CONVERSATION_MEMBERS, QUOTED_MESSAGE, messageQuery, new CompletionHandler<Message>() {
@Override
public void onComplete(Message message, ChannelizeError error) {
}
});
Forward Messages
Forward a message into one or multiple 1-to-1 or Group conversations.
* @param MESSAGE_IDS_ARRAY (Required: JSONArray): Specifies a JSONArray of one or more unique IDs of the messages to forward.
* @param USER_IDS_ARRAY (Optional: JSONArray): Specifies a JSONArray of one or more unique IDs of the users who'll get the message.
* @param CONVERSATION_IDS_ARRAY (Optional: JSONArray): Specifies a JSONArray of one or more unique IDs of the conversations where the message is sent to.
channelizeApi.forwardMessages(MESSAGE_IDS_ARRAY, USER_IDS_ARRAY, CONVERSATION_IDS_ARRAY, new CompletionHandler<RequestResponse>() {
@Override
public void onComplete(RequestResponse result, ChannelizeError error) {
}
});
Mark as Read
Mark a message in a conversation as read for a given user.
* @param CONVERSATION_ID (Required, String): The unique ID of the conversation in which the message is marked read.
* @param MESSAGE_ID (Required, String): The unique ID of the message to mark as read.
* @param MESSAGE_OWNER_ID (Required, String): Owner Id of the message.
channelizeApi.markMessageRead(CONVERSATION_ID, MESSAGE_ID, MESSAGE_OWNER_ID, new CompletionHandler<RequestResponse>() {
@Override
public void onComplete(RequestResponse response, ChannelizeError error) {
}
});