Trigger: message

Learn about the "message" trigger and how it can be used

The JSON structure for a message trigger is as follows:

{
    "trigger": "after_message",
    "data": {
        "id": "1",
        "conversationId": "superhero4_user_superhero5",
        "sender": "superhero5",
        "receiverType": "user", 
        "receiver": "superhero4",
        "category": "message",
        "type": "text",
        "data": {
            "text": "Hi Webhook Test",
            "entities": {
                "sender": {
                    "entity": {
                        "uid": "superhero5",
                        "name": "Cyclops",
                        "avatar": "https://data-us.cometchat.io/assets/images/avatars/cyclops.png",
                        "status": "offline",
                        "role": "default"
                    },
                    "entityType": "user"
                },
                "receiver": {
                    "entity": {
                        "uid": "superhero4",
                        "name": "Wolverine",
                        "avatar": "https://data-us.cometchat.io/assets/images/avatars/wolverine.png",
                        "status": "offline",
                        "role": "default"
                    },
                    "entityType": "user"
                }
            }
        },
        "sentAt": 1586435925,
        "updatedAt": 1586435925,
    },
    "appId": "167*****1529",
    "webhook": "send-message"
}

The message object has the properties described below:

id: messageObject.id
The id property contains the unique identifier of the message.

conversationId: messageObject.conversationId
The conversationId property indicates id of the conversation.

sender: messageObject.sender
The sender property contains UID of the sender.

receiverType: messageObject.receiverType
The receiverType property indicates whether the message is group message or user to user message.

ReceiverType

Description

user

The receiverType user indicates a user to user message.

group

The receiverType group indicates a group message.

receiver: messageObject.receiver
The receiver property contains UID of the user when receiverType = user or GUID of the group when receiverType = group

category: messageObject.category
The value for the category property can be:

Category

Description

message

The messages under the message category are the standard message sent via SDK.

action

The messages under the action category are system generated message and informs the SDK/UI that a certain actions are needed at SDK/UI. For example, a member has been added to a group.

call

The messages under the call category are also system generated messages specialized only for the call activities.

custom

The messages under the custom category are available for developer implementation. The developers can customize the data property for these messages as per their use case.

type: messageObject.type
The type property is the specialization of message under certain category.

Category

Type

message

text, image, audio, video, file

action

user, group, groupMember, call

call

audio, video, broadcast, screenshare, writeboard, whiteboard

custom

location,

data: messageObject.data

  • The data property contains the JSON object allowing it to be completely customizable for custom category. 
    
  • The property also contains immutable entities object that can contain user, group, messages and call objects. 
    
  • It can also contain metadata property to store additional information about the data.
    

sentAt: messageObject.sentAt
The sentAt property contains the unix timestamp at which the message was sent.

updatedAt(optional): messageObject.updatedAt
The updatedAt property contains the unix timestamp at which the message was updated. The value is maximum of all the timestamps in the messageObject .

editedAt(optional): messageObject.editedAt
The editedAt property contains the unix timestamp at which the message was last edited.

editedBy(optional): messageObject.editedBy
The editedBy property contains the UID of the user who recently edited the message.

deletedAt(optional): messageObject.deletedAt
The deletedAt property contains the unix timestamp at which the message was deleted.

deletedBy(optional): messageObject.deletedBy
The deletedBy property contains the UID of the user who had deleted the message.

deliveredAt: messageObject.deliveredAt
The deliveredAt property contains the unix timestamp at which the message was delivered to the receiver for receiverType = user.

readAt(optional): messageObject.readAt
The readAt property contains the unix timestamp at which the message was read by the receiver for receiverType = user. The property won't be present in the response if the message is not yet read by the receiver.

{
                    "id": "40",
                    "conversationId": "group_supergroup",
                    "sender": "superhero1",
                    "receiverType": "group",
                    "receiver": "supergroup",
                    "category": "action",
                    "type": "groupMember",
                    "data": {
                        "action": "added",
                        "entities": {
                            "by": {
                                "entity": {
                                    "uid": "superhero1",
                                    "name": "Iron Man",
                                    "avatar": "https://data-eu.cometchat.io/assets/images/avatars/ironman.png",
                                    "status": "offline",
                                    "role": "default"
                                },
                                "entityType": "user"
                            },
                            "for": {
                                "entity": {
                                    "guid": "supergroup",
                                    "name": "Comic Heros' Hangout",
                                    "icon": "https://data-eu.cometchat.io/assets/images/avatars/supergroup.png",
                                    "type": "public",
                                    "scope": "admin",
                                    "joinedAt": 1583729303,
                                    "hasJoined": true,
                                    "createdAt": 1583729303,
                                    "owner": "superhero1"
                                },
                                "entityType": "group"
                            },
                            "on": {
                                "entity": {
                                    "uid": "superhero6",
                                    "name": "superhero6",
                                    "status": "offline",
                                    "role": "default"
                                },
                                "entityType": "user"
                            }
                        }
                    },
                    "sentAt": 1586589951,
                    "updatedAt": 1586589951
}

Action Messages are basically System generated messages intended to notify users about certain actions being performed.
Most of the properties of Action Message are similar to that of Message Object. The properties that differ in both these objects are mentioned below.

category: The category of action message is "action".

type: The type property defines the type of action message. It can either be groupMember, message or call.

action: The action property contains the action performed either on a user, group or message object.

by: The by property within entities contains the User object i.e the user who initiated the action.

for: The for property can be either user or group object depending on what the action is performed.
For example. if we are adding member to a group, the for property contains group object.
If we are editing a message, the for property contains the user object of user to whom the message was sent.

on: The on property refers to the entity on which the action is performed. It can contain message, user or group member object.

The table mentioned below denotes the mapping of actions that are available for type.

Type

Action

call

initiated, ongoing, busy, unanswered, cancelled, ended, rejected.

groupMember

kicked, banned, unbanned, joined, left, scopeChanged, added

message

edited, deleted

{
        "id": "2",
        "conversationId": "superhero1_user_superhero2",
        "sender": "superhero1",
        "receiverType": "user",
        "receiver": "superhero2",
        "category": "custom",
        "type": "location",
        "data": {
            "customData": {
                "latitude": 0.5,
                "longitude": 0.5
            },
            "entities": {
                "sender": {
                    "entity": {
                        "uid": "superhero1",
                        "name": "Iron Man",
                        "avatar": "https://data-us.cometchat.io/assets/images/avatars/ironman.png",
                        "status": "offline",
                        "role": "default"
                    },
                    "entityType": "user"
                },
                "receiver": {
                    "entity": {
                        "uid": "superhero2",
                        "name": "Captain America",
                        "avatar": "https://data-us.cometchat.io/assets/images/avatars/captainamerica.png",
                        "status": "offline",
                        "role": "default"
                    },
                    "entityType": "user"
                }
            }
        },
        "sentAt": 1587031676,
        "updatedAt": 1587031676,
        "receipts": {
            "data": []
        }
    }

CometChat allows you to send custom messages which are neither text nor media messages.
The messages under the custom category are available for developer implementation.
You can use the type field to set a specific type for the custom message.

Most of the properties of Custom Message are similar to that of Message Object. The properties that differ in both these objects are mentioned below.

category: The category of custom message is "custom".

type: The type of custom message can be any user defined type. (for example type can be location)

customData: The customData property must be present within the data attribute. Accordingly the custom values can be set within customData property.

Sample Response Structure for user, group, groupMember object are as follows -

{
            "uid": "superhero1",
            "name": "superhero1",
            "status": "offline",
            "avatar":"https://data-us.cometchat.io/assets/images/avatars/cyclops.png",
            "role": "default",
            "lastActiveAt": 1583774220,
            "createdAt": 1583732116
 }

uid: UserObject.uid
The uid property denotes the unique identifier of an user.

status: UserObject.status
The status property displays the realtime presence of the user. It can be - available, busy, away, offline.

avatar(optional): UserObject.avatar
The avatar property displays the profile picture associated with an user.

role: UserObject.role
The role property can be used for segregating users based on role. By default system assigns default role while creating user.

lastActiveAt(optional):UserObject.lastActiveAt
The lastActiveAt property holds the timestamp of the time when the user was last online. This can be used to display the Last seen of the user.

{
            "guid": "supergroup",
            "name": "supergroup",
            "type": "public",
            "scope": "admin",
            "joinedAt": 1583730502,
            "hasJoined": true,
            "createdAt": 1583730502,
            "owner": "superhero1"
}

guid: GroupObject.guid
The guid property denotes the unique identifier of a group.

name: GroupObject.name
The name property denotes the name associated with the group.

type: GroupObject.type
The type property contains the group type. Possible values for type can be public, password, private.

scope: GroupObject.scope
The scope property contains the user's scope in that group. Possible values for scope are:
admin, moderator, participant. The default value of scope for any member is participant.

joinedAt(optional): GroupObject.joinedAt
The joinedAt property contains the Unix timestamp at which the user joins a group.

hasJoined(optional): GroupObject.hasJoined
The hasJoined property contains the boolean value indicating the user has joined the group or not. It is set to true if user has joined the group or else false.

owner: GroupObject.owner
The owner property contains the UID of the user who created the group.

{
            "uid": "superhero1",
            "name": "Iron Man",
            "avatar": "https://data-eu.cometchat.io/assets/images/avatars/ironman.png",
            "status": "offline",
            "role": "default",
            "scope": "participant",
            "joinedAt": 1585993789,
            "isBanned": true
}

isBanned(optional) property will be set to true in group member object if the member is banned from the group.

{
"data": {
        "id": "1",
        "conversationId": "superhero1_user_superhero2",
        "sender": "superhero1",
        "receiverType": "user",
        "receiver": "superhero2",
        "category": "call",
        "type": "audio",
        "data": {
            "action": "initiated",
            "entities": {
                "by": {
                    "entity": {
                        "uid": "superhero1",
                        "name": "Iron Man",
                        "avatar": "https://data-us.cometchat.io/assets/images/avatars/ironman.png",
                        "status": "offline",
                        "role": "default"
                    },
                    "entityType": "user"
                },
                "for": {
                    "entity": {
                        "uid": "superhero2",
                        "name": "Captain America",
                        "avatar": "https://data-us.cometchat.io/assets/images/avatars/captainamerica.png",
                        "status": "offline",
                        "role": "default"
                    },
                    "entityType": "user"
                },
                "on": {
                    "entity": {
                        "sessionid": "1587031145c3e15c3bc03cb1e6097a14e5c728a8bf69478951",
                        "sender": "superhero1",
                        "receiverType": "user",
                        "receiver": "superhero2",
                        "status": "initiated",
                        "type": "audio",
                        "data": {
                            "entities": {
                                "sender": {
                                    "entity": {
                                        "uid": "superhero1",
                                        "name": "Iron Man",
                                        "avatar": "https://data-us.cometchat.io/assets/images/avatars/ironman.png",
                                        "status": "offline",
                                        "role": "default"
                                    },
                                    "entityType": "user"
                                },
                                "receiver": {
                                    "entity": {
                                        "uid": "superhero2",
                                        "name": "Captain America",
                                        "avatar": "https://data-us.cometchat.io/assets/images/avatars/captainamerica.png",
                                        "status": "offline",
                                        "role": "default"
                                    },
                                    "entityType": "user"
                                }
                            }
                        },
                        "initiatedAt": 1587031145,
                        "joinedAt": 1587031145
                    },
                    "entityType": "call"
                }
            }
        },
        "sentAt": 1587031145,
        "updatedAt": 1587031145,
        "receipts": {
            "data": []
        }
    }
}

The messages under the call category are also system generated messages specialized only for the call activities.

id: callObject.id
The id property contains the unique identifier of the message.

conversationId: callObject.conversationId
The conversationId property indicates id of the conversation.

sender: callObject.sender
The sender property contains UID of the sender.

receiverType: callObject.receiverType
The receiverType property indicates whether the message is group message or user to user message.

receiver: callObject.receiver
The receiver property contains UID of the user when receiverType = user or GUID of the group when receiverType = group

category: The category of call must be "call".

type: The type property defines the type of call message. It can either be audio or video.

action: The action that is being performed in the call. It can have any of the following values - initiated, ongoing, busy, unanswered, cancelled, ended, rejected.

by: The by property within entities contains the User object i.e the user who initiated the action.

for: The for property can be either user or group object depending on what the action is performed.
For example.
If we are calling a user, the for property contains the user object of user to whom the call was made.

on: The on property refers to the entity on which the action is performed. It contains the call object.

sessionid: The sessionid property is the unique identifier of the call.

status: The status property refers to the current active status of the call. It can have one of the following values - initiated, ongoing, busy, unanswered, cancelled, ended, rejected.

intiatedAt: The initiatedAt property contains the Unix timestamp at which the call was initiated.


Did this page help you?