Messages
This section contains what all messages related actions can be performed using Channelize.io JavaScript SDK functions.
Get Unread Count
Retrieves the total number of unread messages for a user.
channelize.Message.getUnreadCount(function (err, res) {
});
Callback Params
err
Indicates if there is an error. It will be null if there is no error.res
Indicates response object having count as property.{ "count": 62 }
Forward Message
Forward a message into one or multiple conversations. Consider the forwarded messages as a new instance of the message.
channelize.Message.forwardMessages(messageIds, userIds, conversationIds, function (err, res) {
});
Function Params
This table lists all possible parameters this function supports.
Name | Type | Description |
---|---|---|
messageIds | array | Specifies an array of one or more unique IDs of the messages to forward. |
userIds | array | Specifies an array of one or more unique IDs of the users who'll get the message. |
conversationIds | array | Specifies an array of one or more unique IDs of the conversations where the message is sent to. |
Callback Params
err
Indicates if there is any error. It will be null if there is no error.res
Indicates response which will be an array of message ids being created.
Send Message
Sends a message to convesation.
channelize.Message.sendMessage(data, function (err, message) {
});
Channelize supports different types of messages like normal, reply, forward, admin.
normal : A normal message created in the conversation.
forward : A forwarded message from previous message. Moreover Forward messages API call automatically send messages of this type.
reply : A message sent as a reply to a parent message. With every new message, the replyCount of the parent message will increase.
admin : A message generated by a system event, like updating the group, add members, remove members etc.
Function Params
This table lists all possible parameters this function supports.
Name | Type | Required | Description |
---|---|---|---|
data | object | yes | It is the object which contain message data fields. |
Data Object Keys
Below table lists all possible keys of above data param.
Name | Type | Required | Description |
---|---|---|---|
id | string | no | The unique ID of the message. |
type | string | no | Specify the type of message. Allowed values are normal, reply, forward, admin . |
userId | array | yes | Specify the user ID of message receiver. |
body | string | no | The content of the message. |
attachments | array | no | A list of attachments (audio, video, image, location, gif & sticker and text). |
mentionedUsers | array | no | Specifies the tagged members details. |
metaData | object | no | Specifies the meta data of message |
customType | string | no | For grouping messages for customers. |
showInConversation | boolean | no | Specify the showInConversation value for a message to make it visible in both the thread of replies and the main conversation. By default, its value is true. |
parentId | string | no | The ID of the parent message, if the message is a reply. |
events | object | no | You can send supportable events with their values. |
createdAt | date | no | The creation time of message. |
recipients | array | no | The ID of users who you want to send and display messages in a conversation but not for other users. If recipients field is not passed, by default the message is sent to all members of a conversation. |
Events in a message: Need to set below object pattern in events
key.
{
"sendPushNotification": true, // Determines whether to send push notification, default value is true.
"updateUnreadCount": true, // Determines whether to send update unread message count of a conversation, default value is true.
}
Mention users in a message: Need to set below object pattern in mentionedUsers
key.
[
{
"wordCount": 2, // Mentioned user's name word count
"order": 1, // Mention user's order in the message in reference to another mentioned user.
"userId": "USER_ID" // User ID of mentioned user
},
{
"wordCount": 2,
"order": 2,
"userId": "USER_ID"
}
]
By default Channelize’s pre built UI components support the following attachment types:
- Audio
- Video
- Image
- Text
- Location
- Gif & Sticker
- Admin Message
NOTE: If you want to build your own UI, the API allows type
field value different apart from supported by our UI components. Moreover you are able to send extra keys as well as different keys in attachments apart from supported by our UI components. If you take type
field value different and different extra keys, our UI components will not be supporting these attachments.
Predefine Attachments Params
1. File Attachment Params
This table lists all possible parameters this file object supports.
Name | Type | Required | Description |
---|---|---|---|
type | string | yes | Specify the type of the attachment. |
name | string | yes | Name of the file. |
mimeType | string | yes | Specifies the MIME type of file. |
attachmentType | string | yes | Specifies the type of file. Allowed values are an image, audio, and video. |
extension | string | yes | Specifies the extension of the file. |
fileUrl | string | yes | The file URL where a file is stored. This URL should be publicly accessible. |
thumbnailUrl | string | no | The thumbnail URL where thumbnail has been stored. This URL should be publicly accessible. |
2. Location Attachment Params
The location object will have the below properties.
Name | Type | Required | Description |
---|---|---|---|
type | string | yes | Specify the type of the attachment. |
latitude | number | yes | Specifies the latitude of the location. |
longitude | number | yes | Specifies the longitude of the location. |
title | string | yes | Specifies the name for the location. |
address | string | yes | Specifies the address of the location. |
Callback Params
err
Indicates if there is an error. It will be null if there is no error.message
Indicates response which will be message's object.
Add Reaction
Adds a Reaction to the message. The conversation members can add a reaction to the received messages.
channelize.Conversation.getConversation(conversationId, include, function (err, conversation) {
if (err) return console.error(err);
let messageListQuery = conversation.createMessageListQuery();
messageListQuery.ids = messageId;
messageListQuery.list(function (err, messages) {
messages[0].addReaction(data, function (err, res) {
});
});
});
Function Params
This table lists all possible parameters this function supports.
Name | Type | Required | Description |
---|---|---|---|
data | object | yes | It is the object which contain reaction type. |
Data Object Keys
Below table lists all possible keys of above data param.
Name | Type | Required | Default | Description |
---|---|---|---|---|
type | string | yes | - | Specifies a reaction type. Example 'like', 'dislike' and more. |
Callback Params
err
Indicates if there is an error. It will be null if there is no error.res
Indicates the response. It will be a null value for this case.
Remove Reaction
Removes a reaction from a message. Only the conversation members can remove their reactions.
channelize.Conversation.getConversation(conversationId, include, function (err, conversation) {
if (err) return console.error(err);
let messageListQuery = conversation.createMessageListQuery();
messageListQuery.ids = messageId;
messageListQuery.list(function (err, messages) {
messages[0].removeReaction(data, function (err, res) {
});
});
});
Function Params
This table lists all possible parameters this function supports.
Name | Type | Required | Description |
---|---|---|---|
data | object | yes | It is the object which contain reaction type. |
Data Object Keys
Below table lists all possible keys of above data param.
Name | Type | Required | Default | Description |
---|---|---|---|---|
type | string | yes | - | Specifies a reaction type. Example 'like', 'dislike' and more. |
Callback Params
err
Indicates if there is an error. It will be null if there is no error.res
Indicates the response. It will be a null value for this case.
List Reactions
Retrieves the list of reactions on a message.
channelize.Conversation.getConversation(conversationId, include, function (err, conversation) {
if (err) return console.error(err);
let messageListQuery = conversation.createMessageListQuery();
messageListQuery.ids = messageId;
messageListQuery.list(function (err, messages) {
let reactionListUserQuery = messages[0].createReactionUserListQuery();
// number - represent number of items. (Default: 25)
reactionListUserQuery.limit = 25;
// number - represent number of items to be skipped from begining. (Default: 0)
reactionListUserQuery.skip = 0;
// string - specifies a reaction type. Example 'like', 'dislike' and more. (type is a required argument for get reaction list)
reactionListUserQuery.type = type;
reactionListUserQuery.list(function (err, reactions) {
});
});
});
Callback Params
err
Indicates if there is an error. It will be null if there is no error.reactions
Indicates the response which will be an array of reactions object.
Upload File
This method lets you to upload a single file(image/audio/video) on our server.
<input type="file" id="profile">
let file = document.getElementById('profile').files[0];
channelize.Message.uploadFile(file, createThumbnail, function (err, fileData) {
});
Function Params
Name | Type | Required | Description |
---|---|---|---|
file | file | yes | Specifies the file object. |
createThumbnail | boolean | no | For create a thumbnail of image. |
Broadcast Message
This method lets you send the message to multiple users/conversations using their user IDs or conversation IDs. We can also call it broadcast messaging.
channelize.Message.broadcast(userIds, conversationIds, messageData, function (err, res) {
});
Function Params
This table lists all possible parameters this function supports.
Name | Type | Description |
---|---|---|
userIds | array | Specifies the user ID of message recipient. You can send an empty array here if you have used conversaionId. |
conversationIds | array | Specifies the conversation ID where you want to forward the messages. You can send an empty array here if you have used userIds. |
messageData | object | Specifies the message data as a JavaScript object. |
Message Data Object Keys
It supports all types of messages supported by Send Messages function. To know the body of different types of supported messages check Send Message function.
Callback Params
err
Indicates if there is any error. It will be null if there is no error.res
Indicates the response. It will be a null value for this case.
Delete Messages (Own copy)
You can delete a message via two methods :
- Delete a message using Message ID
- Delete a message from a conversation using it's Object
This functionality is allowed only for private conversations.
1. Delete message via Message ID
Deletes a message from a conversation using Message ID.
channelize.Message.deleteMessagesForMe(messageIds, function (err, res) {
});
Function Params
This table lists all possible parameters this function supports.
Name | Type | Description |
---|---|---|
messageIds | array | Specifies an array of one or more unique IDs of the messages to delete from a conversation. |
2. Delete a conversation message
This method lets you delete a message from a conversation using it's object.
channelize.Conversation.getConversation(conversationId, include, function (err, conversation) {
if (err) return console.error(err);
let lastMessage = conversation.getLastMessage();
lastMessage.deleteForMe(function (err, res) {
});
});
Callback Params
err
Indicates if there is an error. It will be null if there is no error.res
Indicates the response which will be a null value in this case.
Delete Messages for Everyone / Recall sent messages
You can delete a message for everyone / recall a sent message via two methods :
- Delete a message for Everyone using Message ID
- Delete a conversation message for everyone
This will work in case of both Public and Private Conversations.
1. Direct delete messages for everyone via message ids
Recalls messages that you sent from the inbox of the recipients. You can also substitute a replacement message.
channelize.Message.deleteMessagesForEveryone(messageIds, function (err, res) {
});
Function Params
Name | Type | Description |
---|---|---|
messageIds | array | Specifies an array of one or more unique IDs of the messages to delete from a conversation. |
2. Delete a conversation message for everyone
This method lets you recall the message that you sent, from the inbox of the recipients using the message object.
channelize.Conversation.getConversation(conversationId, include, function (err, conversation) {
if (err) return console.error(err);
let lastMessage = conversation.getLastMessage();
lastMessage.deleteForEveryone(function (err, res) {
});
});
Callback Params
err
Indicates if there is an error. It will be null if there is no error.res
Indicates the response which will be a null value in this case.
Message Model Object
A message's object can be retrieved either using send message methods or through various other methods.
{
"id": "9d03e400-5b19-11eb-b6e0-8352343eb6dc",
"conversationId": "45e64e7b-e957-49c9-af88-48c347bb494a",
"type": "normal",
"metaData": {},
"createdAt": "2021-01-20T12:18:33.152Z",
"updatedAt": "2021-01-20T12:18:33.152Z",
"body": "Hi! This is a test message.",
"ownerId": "20697",
"attachments": [],
"isDeleted": false,
"encrypted": false,
"reactionsCount": {},
"reactions": {},
"replyCount": 0,
"showInConversation": true,
"pinned": false,
"owner": {
"id": "20697",
"displayName": "alen joe",
"profileImageUrl": "http://mobiledemodevelopment.s3.amazonaws.com/public/user/33/19/02/b5ceb45b2d6c74e4fc89673a5675c09c.jpg"
},
"mentionedUsers": []
}
You can call the below functions through this message model object.
Mark As Read
Mark a message in a conversation as read for a given user.
channelize.Conversation.getConversation(conversationId, include, function (err, conversation) {
if (err) return console.error(err);
let lastMessage = conversation.getLastMessage();
lastMessage.markRead(function (err, res) {
});
});
Callback Params
err
Indicates if there is an error. It will be null if there is no error.res
Indicates the response which will be a JavaScript object having userID, conversationID, messageID and message status properties.
Pin Message
Pin a message in the conversation. This action can only be performed by conversation admins.
channelize.Conversation.getConversation(conversationId, include, function (err, conversation) {
if (err) return console.error(err);
let messageListQuery = conversation.createMessageListQuery();
messageListQuery.ids = messageId;
messageListQuery.list(function (err, messages) {
messages[0].pin(function (err, res) {
});
});
});
Callback Params
err
Indicates if there is an error. It will be null if there is no error.res
Indicates the response. It will be a null value for this case.
Unpin Message
Unpin a pinned message in the conversation. This action can only be performed by conversation admins.
channelize.Conversation.getConversation(conversationId, include, function (err, conversation) {
if (err) return console.error(err);
let messageListQuery = conversation.createMessageListQuery();
messageListQuery.ids = messageId;
messageListQuery.list(function (err, messages) {
messages[0].unpin(function (err, res) {
});
});
});
Callback Params
err
Indicates if there is an error. It will be null if there is no error.res
Indicates the response. It will be a null value for this case.