- Text Message is the most common and standard message type.
- Media Message for sending photos, videos and files.
- Custom Message, for sending completely custom data using JSON structures.
- Interactive Messages, for sending end-user interactive messages of type form, card and custom Interactive
Text Message
In other words, as a sender, how do I send a text message? To send a text message to a single user or group, you need to use thesendMessage()
method and pass a TextMessage
object to it.
Add Metadata
To send custom data along with a text message, you can use thesetMetadata
method and pass a JSON Object
to it.
Add Tags
To add a tag to a message you can use thesetTags()
method of the TextMessage Class. The setTags()
method accepts a list of tags.
sendMessage()
method to send the text message to the recipient.
TextMessage
class constructor takes the following parameters:
Parameter | Description | |
---|---|---|
receiverID | UID of the user or GUID of the group receiving the message | Required |
messageText | The text message | Required |
receiverType | The type of the receiver - CometChat.RECEIVER_TYPE.USER or CometChat.RECEIVER_TYPE.GROUP | Required |
TextMessage
object which includes all information related to the sent message.
Media Message
In other words, as a sender, how do I send a media message like photos, videos & files? To send a media message to any user or group, you need to use thesendMediaMessage()
method and pass a MediaMessage
object to it.
Add Metadata
To send custom data along with a media message, you can use thesetMetadata
method and pass a JSON Object
to it.
Add Caption(Text along with Media Message)
To send a caption with a media message, you can use thesetCaption
method and pass text to it.
Add Tags
To add a tag to a message you can use thesetTags()
method of the MediaMessage Class. The setTags()
method accepts a list of tags.
- By providing the File: You can directly share the file object while creating an object of the MediaMessage class. When the media message is sent using the
sendMediaMessage()
method, this file is then uploaded to CometChat servers and the URL of the file is sent in the success response of thesendMediaMessage()
function.
MediaMessage
class constructor takes the following parameters:
Parameter | Description | |
---|---|---|
receiverId | The UID or GUID of the recipient. | Required |
file | The file object to be sent | Required |
messageType | The type of the message that needs to be sent which in this case can be: 1. CometChat.MESSAGE_TYPE.IMAGE 2. CometChat.MESSAGE_TYPE.VIDEO 3. CometChat.MESSAGE_TYPE.AUDIO 4. CometChat.MESSAGE_TYPE.FILE | Required |
receiverType | The type of the receiver to whom the message is to be sent.1. CometChat.RECEIVER_TYPE.USER 2. CometChat.RECEIVER_TYPE.GROUP | Required |
- By providing the URL of the File: The second way to send media messages using the CometChat SDK is to provide the SDK with the URL of any file that is hosted on your servers or any cloud storage. To achieve this you will have to make use of the Attachment class. For more information, you can refer to the below code snippet:
MediaMessage
object which includes all information related to the sent message.
Multiple Attachments in a Media Message
Starting version 3.0.9 & above the SDK supports sending multiple attachments in a single media message. As in the case of a single attachment in a media message, there are two ways you can send Media Messages using the CometChat SDK:- By providing an array of files: You can now share an array of files while creating an object of the MediaMessage class. When the media message is sent using the
sendMediaMessage()
method, the files are uploaded to the CometChat servers & the URL of the files is sent in the success response of thesendMediaMessage()
method.
MediaMessage
class constructor takes the following parameters:
Parameter | Description |
---|---|
receiverId | The UID or GUID of the recipient. |
files | An array of files. |
messageType | The type of the message that needs to be sent which in this case can be: 1. CometChat.MESSAGE_TYPE.IMAGE 2. CometChat.MESSAGE_TYPE.VIDEO 3. CometChat.MESSAGE_TYPE.AUDIO 4. CometChat.MESSAGE_TYPE.FILE |
receiverType | The type of the receiver to whom the message is to be sent. 1. CometChat.RECEIVER_TYPE.USER 2. CometChat.RECEIVER_TYPE.GROUP |
- By providing the URL of the multiple files: The second way to send multiple attachments in a single media message using the CometChat SDK is to provide the SDK with the URL of multiple files that are hosted on your servers or any cloud storage. To achieve this you will have to make use of the Attachment class. For more information, you can refer to the below code snippet:
MediaMessage
object which includes all information related to the sent message.
You can use the setMetadata()
, setCaption()
& setTags()
methods to add metadata, caption and tags respectively in exactly the same way as it is done while sending a single file or attachment in a Media Message.
Custom Message
In other words, as a sender, how do I send a custom message like location coordinates? CometChat allows you to send custom messages which are neither text nor media messages. In order to send a custom message, you need to use thesendCustomMessage()
method.
The sendCustomMessage()
method takes an object of the CustomMessage
which can be obtained using the below constructor.
custom
.
The parameters involved are:
receiverId
- The unique ID of the user or group to which the message is to be sent.receiverType
- Type of the receiver i.e user or groupcustomType
- custom message type that you need to setcustomData
- The data to be passed as the message in the form of a JSON Object.
CustomMessage
class to set a specific type for the custom message. This can be achieved using the setSubtype()
method.
Add Tags
To add a tag to a message you can use thesetTags()
method of the CustomMessage Class. The setTags()
method accepts a list of tags.
CustomMessage
class is ready you can send the custom message using the sendCustomMessage()
method.
CustomMessage
class.
Update Conversation
How can I decide whether the custom message should update the last message of a conversation? By default, a custom message will update the last message of a conversation. If you wish to not update the last message of the conversation when a custom message is sent, please use shouldUpdateConversation(value: boolean) method of the Custom Message.Custom Notification Body
How can i customise the notification body of custom message? To add a custom notification body forPush, Email & SMS
notification of a custom message you can use the setConversationText(text: string)
method of Custom Message class.
It is also possible to send interactive messages from CometChat, to know more click here