AI Integration Quick Reference
AI Integration Quick Reference
- Register a listener with a unique ID using
addXListener() - Handle events in the callback methods
- Remove the listener with
removeXListener()when it’s no longer needed
- User Listener
- Group Listener
- Message Listener
- Call Listener
- AI Assistant Listener
- Ongoing Call Listener (Calls SDK)
User Listener
Receive online/offline presence events for users.| Method | Information |
|---|---|
| onUserOnline(user: CometChat.User) | This method is triggered when a user comes online and is available to chat. The details of the user can be obtained from the user object received as the method parameter. |
| onUserOffline(user: CometChat.User) | This method is triggered when a user goes offline. The details of the user can be obtained from the User object received as the parameter. |
UserListener:
- TypeScript
- JavaScript
- TypeScript
- JavaScript
Group Listener
Receive events when group members join, leave, are kicked/banned, or have their scope changed.| Method | Information |
|---|---|
| onGroupMemberJoined(action: CometChat.Action, joinedUser: CometChat.User, joinedGroup: CometChat.Group) | This method is triggered when a user joins any group. All the members present in the group will receive this event. |
| onGroupMemberLeft(action: CometChat.Action, leftUser: CometChat.User, leftGroup: CometChat.Group) | This method is triggered when a user who was a member of any group leaves the group. All the members of the group receive this event. |
| onGroupMemberKicked(action: CometChat.Action, kickedUser: CometChat.User, kickedBy: CometChat.User, kickedFrom: CometChat.Group) | This method is triggered when a user is kicked from a group. All the members including the user receive this event |
| onGroupMemberBanned(action: CometChat.Action, bannedUser: CometChat.User, bannedBy: CometChat.User, bannedFrom: CometChat.Group) | This method is triggered when a user is banned from a group. All the members including the user receive this event |
| onGroupMemberUnbanned(action: CometChat.Action, unbannedUser: CometChat.User, unbannedBy: CometChat.User, unbannedFrom: CometChat.Group) | This method is triggered when a user is banned from a group. All the members of the group receive this event. |
| onGroupMemberScopeChanged(action: CometChat.Action, changedUser: CometChat.User, newScope: string, oldScope: string, changedGroup: CometChat.Group) | This method is triggered when the scope of any Group Member has been changed. All the members that are a part of that group receive this event |
| onMemberAddedToGroup(action: CometChat.Action, userAdded: CometChat.User, addedBy: CometChat.User, addedTo: CometChat.Group) | This method is triggered when a user is added to any group. All the members including the user himself receive this event. |
GroupListener:
- TypeScript
- JavaScript
- TypeScript
- JavaScript
Message Listener
Receive events for incoming messages, typing indicators, read/delivery receipts, message edits/deletes, reactions, and moderation results.| Method | Information |
|---|---|
| onTextMessageReceived(message: CometChat.TextMessage) | This event is triggered when a Text Message is received. |
| onMediaMessageReceived(message: CometChat.MediaMessage) | This event is triggered when a Media Message is received. |
| onCustomMessageReceived(message: CometChat.CustomMessage) | This event is triggered when a Custom Message is received. |
| onTypingStarted(typingIndicator: CometChat.TypingIndicator) | This event is triggered when a user starts typing in a user/group conversation |
| onTypingEnded(typingIndicator: CometChat.TypingIndicator) | This event is triggered when a user stops typing in a user/group conversation. |
| onMessagesDelivered(messageReceipt: CometChat.MessageReceipt) | This event is triggered when a set of messages are marked as delivered for any particular conversation. |
| onMessagesRead(messageReceipt: CometChat.MessageReceipt) | This event is triggered when a set of messages are marked as read for any particular conversation. |
| onMessageEdited(message: CometChat.BaseMessage) | This method is triggered when a particular message has been edited in a user/group conversation. |
| onMessageDeleted(message: CometChat.BaseMessage) | This event is triggered when a particular message is deleted in a user/group conversation. |
| onTransientMessageReceived(receipt: CometChat.TransientMessage) | This event is triggered when a Transient Message is received. |
| onMessageReactionAdded(receipt: CometChat.ReactionEvent) | This event is triggered when a reaction is added to a message in a user/group conversation. |
| onMessageReactionRemoved(receipt: CometChat.ReactionEvent) | This event is triggered when a reaction is remove from a message in a user/group conversation. |
| onMessageModerated(message: CometChat.BaseMessage) | This event is triggered when a message sent by the logged-in user is successfully processed by moderation and receives either an approved or disapproved status. |
| onMessagesDeliveredToAll(receipt: CometChat.MessageReceipt) | This event is triggered when a group message is delivered to all members. Group conversations only. |
| onMessagesReadByAll(receipt: CometChat.MessageReceipt) | This event is triggered when a group message is read by all members. Group conversations only. |
| onAIAssistantMessageReceived(message: CometChat.AIAssistantMessage) | This event is triggered when a persisted AI assistant reply is received after an agent run completes. |
| onAIToolResultReceived(message: CometChat.AIToolResultMessage) | This event is triggered when a persisted AI tool result message is received after an agent run completes. |
| onAIToolArgumentsReceived(message: CometChat.AIToolArgumentMessage) | This event is triggered when a persisted AI tool argument message is received after an agent run completes. |
To add the MessageListener, you need to use the addMessageListener() method provided by the CometChat class. |
- TypeScript
- JavaScript
- TypeScript
- JavaScript
Call Listener
Receive events for incoming and outgoing call state changes.| Method | Information |
|---|---|
| onIncomingCallReceived(call: CometChat.Call) | This event is triggered when the logged-in user receives an incoming call. The details of the call can be obtained from the Call object received as the method parameter. |
| onOutgoingCallAccepted(call: CometChat.Call) | This event is triggered when the call initiated by the logged-in user is accepted by the recipient. The details of the call can be obtained from the Call object received as the method parameter. |
| onOutgoingCallRejected(call: CometChat.Call) | This event is triggered when the call initiated by the logged-in user is rejected by the recipient. The details of the call can be obtained from the Call object received as the method parameter |
| onIncomingCallCancelled(call: CometChat.Call) | This event is triggered when an incoming call is canceled by the initiator of the call. The details of the call can be obtained from the Call object received as the method parameter |
| onCallEndedMessageReceived(call: CometChat.Call) | This event is triggered when a call ends. The call object contains the final status and duration. |
CallListener:
- TypeScript
- JavaScript
- TypeScript
- JavaScript
AI Assistant Listener
TheAIAssistantListener provides real-time streaming events from AI Agent runs. These events are received as the agent processes a user’s message, before the final persisted messages arrive via the MessageListener.
| Method | Information |
|---|---|
| onAIAssistantEventReceived(event: CometChat.AIAssistantBaseEvent) | This event is triggered for each streaming event during an AI Agent run (run start, tool calls, text message streaming, run finished). See AIAssistantBaseEvent for the event structure. |
- TypeScript
- JavaScript
- TypeScript
- JavaScript
Ongoing Call Listener (Calls SDK)
TheOngoingCallListener provides real-time callbacks for active call session events. It is part of the CometChat Calls SDK (not the Chat SDK) and is used with CallSettingsBuilder.setCallListener() or CometChatCalls.addCallEventListener().
All three calling flows — Call Session, Standalone Calling, and Ringing — use the same OngoingCallListener.
Callbacks
| Callback | Parameter | Description |
|---|---|---|
onUserJoined(user) | user object | A remote participant joined the call |
onUserLeft(user) | user object | A remote participant left the call |
onUserListUpdated(userList) | Array of user objects | The participant list changed (join or leave) |
onCallEnded() | — | The call session terminated (1:1 calls only, fires for both participants) |
onCallEndButtonPressed() | — | The local user clicked the end call button |
onSessionTimeout() | — | The call was auto-terminated due to inactivity. v4.1.0+ |
onScreenShareStarted() | — | The local user started sharing their screen |
onScreenShareStopped() | — | The local user stopped sharing their screen |
onUserMuted(event) | event object | A participant’s mute state changed |
onCallSwitchedToVideo(event) | event object | An audio call was upgraded to video |
onMediaDeviceListUpdated(deviceList) | deviceList object | Available audio/video devices changed |
onRecordingStarted(event) | event object | A user started recording the call |
onRecordingStopped() | — | Recording was stopped |
onError(error) | CometChatCallsException | An error occurred during the call session |
Callback Parameter Shapes
user object (received by onUserJoined, onUserLeft):
| Property | Type | Description |
|---|---|---|
name | string | Display name of the user |
avatar | string | URL of the user’s avatar |
uid | string | UID of the user |
onUserListUpdated(userList) — receives an array of user objects with the same shape as above.
onUserMuted(event):
| Property | Type | Description |
|---|---|---|
event.muted.name | string | Name of the muted user |
event.muted.uid | string | UID of the muted user |
event.muted.isAudioMuted | boolean | Whether audio is muted |
event.muted.isVideoMuted | boolean | Whether video is muted |
event.mutedBy.name | string | Name of the user who muted |
event.mutedBy.uid | string | UID of the user who muted |
onCallSwitchedToVideo(event):
| Property | Type | Description |
|---|---|---|
event.sessionId | string | Session ID of the call |
event.initiator.name | string | Name of the user who initiated the switch |
event.initiator.uid | string | UID of the initiator |
event.responder.name | string | Name of the responder |
event.responder.uid | string | UID of the responder |
onMediaDeviceListUpdated(deviceList):
| Property | Type | Description |
|---|---|---|
deviceList.videoInputDevices | MediaDeviceInfo[] | Available cameras |
deviceList.audioInputDevices | MediaDeviceInfo[] | Available microphones |
deviceList.audioOutputDevices | MediaDeviceInfo[] | Available speakers/headphones |
onRecordingStarted(event):
| Property | Type | Description |
|---|---|---|
event.user.name | string | Name of the user who started recording |
event.user.uid | string | UID of the user who started recording |
onRecordingStopped(), onCallEnded(), onSessionTimeout(), onCallEndButtonPressed(), onScreenShareStarted(), onScreenShareStopped() — receive no arguments.
- TypeScript
- JavaScript
Login Listener
Receive events when the user’s authentication state changes — login success/failure and logout success/failure.| Method | Description |
|---|---|
loginSuccess(user) | User logged in successfully. Provides the User object. |
loginFailure(error) | Login failed. Provides a CometChatException. |
logoutSuccess() | User logged out successfully. |
logoutFailure(error) | Logout failed. Provides a CometChatException. |
- TypeScript
- JavaScript
Connection Listener
Receive events when the WebSocket connection state changes.| Method | Description |
|---|---|
onConnected() | SDK has an active connection to CometChat servers. |
inConnecting() | SDK is attempting to establish or re-establish a connection. |
onDisconnected() | SDK is disconnected due to network issues or other errors. |
onFeatureThrottled() | A feature has been throttled due to rate limiting. |
- TypeScript
- JavaScript
Next Steps
Receive Messages
Handle incoming messages in real-time
Typing Indicators
Show when users are typing
User Presence
Track online/offline status of users
Connection Status
Monitor SDK connection state changes