AI Integration Quick Reference
AI Integration Quick Reference
You can also send Interactive Messages for forms, cards, and custom UI elements.
You can also send metadata along with a text or media message. Think, for example, if you’d want to share the user’s location with every message, you can use the metadata field.
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 Map to it.
- Dart
Add Tags
To add a tag to a message you can assign value in.tags variable of the TextMessage Class. tags accepts a list of tags.
- Dart
sendMessage() method to send the text message to the recipient.
- Dart (User)
- Dart (group)
TextMessage class constructor takes the following parameters:
When a text message is sent successfully, the response will include a
TextMessage object which includes all information related to the sent message.
Response
Response
On Success — A
TextMessage object containing all details of the sent message:TextMessage Object:sender Object:receiver Object:Error
Error
Set Quoted Message
To set a quoted message for a message, use thesetQuotedMessageId and setQuotedMessage method of the TextMessage class. This method accepts the ID of the message to be quoted.
- Dart
sendMessage() method to send the text message to the recipient.
- Dart (User)
- Dart (Group)
TextMessage class constructor takes the following parameters:
When a text message is sent successfully, the response will include a
TextMessage object which includes all information related to the sent message.
Response
Response
On Success — A
TextMessage object containing all details of the sent quoted message:TextMessage Object:sender Object:receiver Object:Error
Error
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 Map to it.
- Dart
Add Caption(Text along with Media Message)
- Dart
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.
- Dart
Set Quoted Message
To quote a message in a media message, use thequotedMessageId property of the MediaMessage class.
- Dart
- 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 the sendMediaMessage() function.
- Dart (User)
- Dart (Group)
MediaMessage class constructor takes the following parameters:
Response
Response
On Success — A
MediaMessage object containing all details of the sent media message:MediaMessage Object:sender Object:receiver Object:attachment Object:Error
Error
- 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
Attachmentclass that is available in the MediaMessage class. For more information, you can refer to the below code snippet:
- Dart (User)
- Dart (Group)
MediaMessage object which includes all information related to the sent message.
Response
Response
On Success — A
MediaMessage object containing all details of the sent media message (via URL):MediaMessage Object:sender Object:receiver Object:attachment Object:Error
Error
caption field provided by the MediaMessage class. To get and set the caption you can use the .caption variable . As with text messages, the metadata field can be used with media messages as well. Any additional information can be passed along with the media message as a Map.
Custom Message
In other words, as a sender, how do I send a custom message like location co-ordinates? 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() methods takes an object of the CustomMessage which can be obtained using the below constructor.
- Dart
custom.
The CustomMessage class constructor takes the following parameters:
You can also use the subType field of the
CustomMessage class to set a specific type for the custom message. This can be achieved using the subtype field.
Add Metadata
To send custom data along with a custom message, you can use themetadata property and pass a Map to it.
- Dart
Add Tags
To add a tag to a message you can assign value in.tags variable of the CustomMessage Class. tags accepts a list of tags.
- Dart
Set Quoted Message
To quote a message in a custom message, use thequotedMessageId property of the CustomMessage class.
- Dart
CustomMessage class is ready you can send the custom message using the sendCustomMessage() method.
- User
- Group
CustomMessage class.
Response
Response
On Success — A
CustomMessage object containing all details of the sent custom message:CustomMessage Object:sender Object:receiver Object:Error
Error
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 useupdateConversation (boolean value) method of the Custom Message.
- User
- Group
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 conversationText method of Custom Message class.
- User
- Group
It is also possible to send interactive messages from CometChat , to know more click here
Next Steps
Receive Messages
Handle incoming messages in real-time
Edit Message
Modify sent messages after delivery
Interactive Messages
Send forms, cards, and interactive elements
Delete Message
Remove messages from conversations