Common templates and sounds
Templates are designed to specify the content displayed in notifications on the user’s device for different events. Templates incorporateplaceholders, which reference specific pieces of information determined by properties from the event.
For example, New message event has the following structure:
data.entities.sender.name, so the placeholder for the sender’s name will be {{message.data.entities.sender.name}}. This placeholder is substituted within the template with the actual name of the sender aka the substitution value.
As an administrator, you can configure:
- Default templates - Use these templates to display previews by leveraging the information contained in the event.
- Privacy templates - Employ these templates to present generic content in the notification.
Privacy setting
Dashboard configuration
Configure which template will be used for displaying the content of the notifications displayed on user’s devices. The available preferences are:- Use default template - Enforces the use of default templates for all the users.
- Use privacy template - Enforces the use of privacy templates for all the users.
- Use default templates with user privacy override (Default) - Uses default templates by default, but allows the users to enable privacy to hide the previews.
Client-side implementation
1. Fetch privacy setting The methodCometChatNotifications.fetchPreferences() retrieves the notification preferences saved by the user as an instance of NotificationPreferences class. If the user has not configured any preferences, the default preferences defined by the CometChat administrator via the dashboard will be utilized.
- JavaScript
- Android
- iOS
- Flutter
CometChatNotifications.updatePreferences() method is used to update a user’s notification preferences. The “override” toggle defined in the dashboard is crucial when updating preferences. If any preference is non-overridable, the method doesn’t generate an error; it instead returns the NotificationPreferences object with the updated values where overrides are allowed.
This functionality can be beneficial for temporarily superseding certain user preferences to ensure notifications for a specific event are delivered. Nonetheless, it is advisable to use this approach temporarily to avoid confusing users with unexpected changes to their notification settings.
It is unnecessary to specify all values; only set and save the preferences that have been changed.
- JavaScript
- Android
- iOS
- Flutter
Text message templates
| Template for | Default template values | Privacy template values |
|---|---|---|
| Title (One-on-one) | {{message.data.entities.sender.entity.name}} | {{message.data.entities.sender.entity.name}} |
| Title (Group) | {{message.data.entities.sender.entity.name}}@{{message.data.entities.receiver.entity.name}} | {{message.data.entities.sender.entity.name}}@{{message.data.entities.receiver.entity.name}} |
| Body | {{message.data.text}} | New message |
Media message templates
| Template for | Default template values | Privacy template values |
|---|---|---|
| Title (One-on-one) | {{message.data.entities.sender.entity.name}} | {{message.data.entities.sender.entity.name}} |
| Title (Group) | {{message.data.entities.sender.entity.name}}@{{message.data.entities.receiver.entity.name}} | {{message.data.entities.sender.entity.name}}@{{message.data.entities.receiver.entity.name}} |
| Body for Image | 📷 Has sent an image | New image message |
| Body for Audio | 🔈 Has sent an audio | New audio message |
| Body for Video | 🎥 Has sent a video | New video message |
| Body for File | 📄 Has sent a file | New file message |
Custom message templates
| Template for | Default template values | Privacy template values |
|---|---|---|
| Title (One-on-one) | {{message.data.entities.sender.entity.name}} | {{message.data.entities.sender.entity.name}} |
| Title (Group) | {{message.data.entities.sender.entity.name}}@{{message.data.entities.receiver.entity.name}} | {{message.data.entities.sender.entity.name}}@{{message.data.entities.receiver.entity.name}} |
| Body | {{message.data.text}} | {{message.data.text}} |
| Body (Fallback) | New message | New message |
{{message.data.text}} in the aforementioned scenario evaluates to null or undefined, the “Body (Fallback)” value will be utilized.
Ideally, the “Body (Fallback)” value should not contain any placeholders to prevent additional resolution failures.
Interactive form templates
| Template for | Default template values | Privacy template values |
|---|---|---|
| Title (One-on-one) | {{message.data.entities.sender.entity.name}} | {{message.data.entities.sender.entity.name}} |
| Title (Group) | {{message.data.entities.sender.entity.name}}@{{message.data.entities.receiver.entity.name}} | {{message.data.entities.sender.entity.name}}@{{message.data.entities.receiver.entity.name}} |
| Body | {{data.interactiveData.title}} | New message |
Interactive card templates
| Template for | Default template values | Privacy template values |
|---|---|---|
| Title (One-on-one) | {{message.data.entities.sender.entity.name}} | {{message.data.entities.sender.entity.name}} |
| Title (Group) | {{message.data.entities.sender.entity.name}}@{{message.data.entities.receiver.entity.name}} | {{message.data.entities.sender.entity.name}}@{{message.data.entities.receiver.entity.name}} |
| Body | {{data.interactiveData.title}} | New message |
Interactive scheduler templates
| Template for | Default template values | Privacy template values |
|---|---|---|
| Title (One-on-one) | {{message.data.entities.sender.entity.name}} | {{message.data.entities.sender.entity.name}} |
| Title (Group) | {{message.data.entities.sender.entity.name}}@{{message.data.entities.receiver.entity.name}} | {{message.data.entities.sender.entity.name}}@{{message.data.entities.receiver.entity.name}} |
| Body | New invite | New invite |
Custom Interactive message templates
| Template for | Default template values | Privacy template values |
|---|---|---|
| Title (One-on-one) | {{message.data.entities.sender.entity.name}} | {{message.data.entities.sender.entity.name}} |
| Title (Group) | {{message.data.entities.sender.entity.name}}@{{message.data.entities.receiver.entity.name}} | {{message.data.entities.sender.entity.name}}@{{message.data.entities.receiver.entity.name}} |
| Body | New message | New message |
Sounds
The sound files must be included within the app’s bundle. These values are set within the notification payload as values of the “sound” field. Sound for Call Notifications: Specify the name of the sound file you wish to play for call notifications. Sound for Chat Notifications: Specify the name of the sound file you wish to play for chat notifications.| Field | Default |
|---|---|
| Calls | default |
| Sounds | default |