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 a text message
This method lets you send a text message to a user. Generally, this method is used when sending the first message to another i.e no conversation and conversation ID exists b/w them.
channelize.Message.sendTextMessage(userId, body, function (err, message) {
});
Function Params
This table lists all possible parameters this function supports.
Name | Type | Description |
---|---|---|
userId | array | Specifies an array of one or more unique IDs of the users who'll get the message. |
body | array | The content of the message. |
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.
Send a Location Attachment
This method lets you send a text message to a user. Generally, this method is used when sending the first message to another i.e no conversation and conversation ID exists b/w them.
channelize.Message.sendLocationMessage(userId, location, function (err, message) {
});
Function Params
This table lists all possible parameters this function supports.
Name | Type | Description |
---|---|---|
userId | array | Specifies an array of one or more unique IDs of the users who'll get the message. |
location | object | Specifies the location object. |
Location Params
The location object will have the below properties:
Name | Type | Description |
---|---|---|
latitude | number | Specifies the latitude of the location. |
longitude | number | Specifies the longitude of the location. |
title | string | Specifies the name for the location. |
address | string | 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 the response which is the message's object.
Send a File Attachment
This method lets you send a file attachment to a user. Generally, this method is used when sending the first message to another i.e no conversation and conversation ID exists b/w them.
<input type="file" id="profile">
let file = document.getElementById('profile').files[0];
channelize.Message.sendFileMessage(userId, file, thumbnail, function (err, message) {
});
Function Params
This table lists all possible parameters this function supports.
Name | Type | Description |
---|---|---|
userId | array | Specifies an array of one or more unique IDs of the users who'll get the message. |
file | fileobject | Specifies the file object. |
thumbnail | boolean | Specifies if you want to create thumbnail for this file. |
The file provided will be stored on the Channelize server. If you want to store the file separately on your server, you have to send the file as a javascript object with the below properties.
File Object Params
This table lists all possible parameters this file object supports.
Name | Type | Required | Description |
---|---|---|---|
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. |
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.
Send Messages to Multiple
This method lets you send the message to multiple users/conversations using their user IDs or conversation IDs.
channelize.Message.sendMessageToMultiple(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 Params
Message data can have the below properties:
Name | Type | Description |
---|---|---|
body | string | Specifies the content of the message. |
contentType | number | Specifies the type of message. Allowed values are 0,1,2 and 3 for text/media, meta-message, sticker/gif, and location messages respectively. |
attachmentType | string | Specifies the type of attachment. This is used to further filter the text/media contentType. Allowed values are text, image, video, audio. Multiple values can also be passed in attachmentType as comma-separated values. |
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)
Deletes a message from a conversation.
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. |
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.
Delete Messages for Everyone / Recall sent messages
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. |
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.
Message Model Object
A message's object can be retrieved either using send message methods or through various other methods.
{
"id":"1f1d473e-b3cd-4be9-b745-66872c443ebc",
"attachmentType":"text",
"contentType":0,
"body":"Hi! This is a test message.",
"ownerId":"20697",
"recipients":[
{
"id":"95572bf0-7ded-11e9-92d9-83eb9b13aea0",
"recipientId":"18859",
"status":3,
"createdAt":"2019-05-24T06:31:37.775Z"
},
{
"id":"95572bf1-7ded-11e9-92d9-83eb9b13aea0",
"recipientId":"20697",
"status":3,
"createdAt":"2019-05-24T06:31:37.775Z"
}
],
"owner":{
"id":"20697",
"displayName":"Channelize Demo User",
"profileImageUrl":"http://mobiledemodevelopment.s3.amazonaws.com/public/user/33/19/02/b5ceb45b2d6c74e4fc89673a5675c09c.jpg"
},
"tags":[]
}
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.
Delete Messages (Own copy)
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
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.