> ## Documentation Index
> Fetch the complete documentation index at: https://cometchat-22654f5b-docs-platform-docs-release.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# All Real Time Listeners

CometChat provides 4 listeners viz.

1. [UserListener](#user-listener)
2. [GroupListener](#group-listener)
3. [MessageListener](#message-listener)
4. [CallListener](#call-listener)

## User Listener

The `UserListener` class provides you with live events related to users. Below are the callback methods provided by the `UserListener` class.

| Method                     | Information                                                                                                                                                                |
| -------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `onUserOnline(User 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 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.                                 |

To add the `UserListener`, you need to use the `addUserListener()` method provided by the `CometChat` class.

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    CometChat.addUserListener(UNIQUE_LISTENER_ID, new CometChat.UserListener() {
      @Override
        public void onUserOnline(User user) {

      }

      @Override
        public void onUserOffline(User user) {

      }
    });
    ```
  </Tab>
</Tabs>

where `UNIQUE_LISTENER_ID` is the unique identifier for the listener. Please make sure that no two listeners are added with the same listener id as this could lead to unexpected behavior resulting in loss of events.

Once the activity/fragment where the `UserListener` is declared is not in use, you need to remove the listener using the `removeUserListener()` method which takes the id of the listener to be removed as the parameter. We suggest you call this method in the `onPause()` method of the activity/fragment.

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    CometChat.removeUserListener(UNIQUE_LISTENER_ID)
    ```
  </Tab>
</Tabs>

## Group Listener

The `GroupListener` class provides you with all the real-time events related to groups. Below are the callback methods provided by the `GroupListener` class.

| Method                                                                                                                                    | Information                                                                                                                                    |
| ----------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------- |
| `onGroupMemberJoined(Action action, User joinedUser, Group joinedGroup)`                                                                  | This method is triggered when a user joins any group. All the members present in the group will receive this event.                            |
| `onGroupMemberLeft(Action action, User leftUser, Group leftGroup)`                                                                        | 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 action, User kickedUser, User kickedBy, Group kickedFrom)`                                                    | This method is triggered when a user is kicked from a group. All the members including the user receive this event                             |
| `onGroupMemberBanned(Action action, User bannedUser, User bannedBy, Group bannedFrom)`                                                    | This method is triggered when a user is banned from a group. All the members including the user receive this event                             |
| `onGroupMemberUnbanned(Action action, User unbannedUser, User unbannedBy, Group unbannedFrom)`                                            | This method is triggered when a user is banned from a group. All the members of the group receive this event.                                  |
| `onGroupMemberScopeChanged(Action action, User updatedBy, User updatedUser, String scopeChangedTo, String scopeChangedFrom, Group 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 action, User addedby, User userAdded, Group addedTo)`                                                        | This method is triggered when a user is added to any group. All the members including the user himself receive this event.                     |

To add the `GroupListener`, you need to use the `addGroupListener()` method provided by the `CometChat` class.

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    CometChat.addGroupListener("UNIQUE_ID", new CometChat.GroupListener() {
      @Override
      public void onGroupMemberJoined(Action action, User joinedUser, Group joinedGroup) {
      }

      @Override
      public void onGroupMemberLeft(Action action, User leftUser, Group leftGroup) {
      }

      @Override
      public void onGroupMemberKicked(Action action, User kickedUser, User kickedBy, Group kickedFrom) {
      }

      @Override
      public void onGroupMemberBanned(Action action, User bannedUser, User bannedBy, Group bannedFrom) {
      }

      @Override
      public void onGroupMemberUnbanned(Action action, User unbannedUser, User unbannedBy, Group unbannedFrom) {
      }

      @Override
      public void onGroupMemberScopeChanged(Action action, User updatedBy, User updatedUser, String scopeChangedTo, String scopeChangedFrom, Group group) {
      }

      @Override
      public void onMemberAddedToGroup(Action action, User addedby, User userAdded, Group addedTo) {
      }
    });
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin theme={null}
    CometChat.addGroupListener("UNIQUE_ID", object : CometChat.GroupListener() {
      override fun onGroupMemberJoined(action: Action, joinedUser: User, joinedGroup: Group) {
      }

      override fun onGroupMemberLeft(action: Action, leftUser: User, leftGroup: Group) {
      }

      override fun onGroupMemberKicked(action: Action, kickedUser: User, kickedBy: User, kickedFrom: Group) {
      }

      override fun onGroupMemberBanned(action: Action, bannedUser: User, bannedBy: User, bannedFrom: Group) {
      }

      override fun onGroupMemberUnbanned(action: Action, unbannedUser: User, unbannedBy: User, unbannedFrom: Group) {
      }

      override fun onGroupMemberScopeChanged(action: Action, updatedBy: User, updatedUser: User, scopeChangedTo: String, scopeChangedFrom: String, group: Group) {
      }

      override fun onMemberAddedToGroup(action: Action, addedby: User, userAdded: User, addedTo: Group) {
      }
    })
    ```
  </Tab>
</Tabs>

where `UNIQUE_LISTENER_ID` is the unique identifier for the listener. Please make sure that no two listeners are added with the same listener id as this could lead to unexpected behavior resulting in loss of events.

Once the activity/fragment where the `GroupListener` is declared is not in use, you need to remove the listener using the `removeGroupListener()` method which takes the id of the listener to be removed as the parameter. We suggest you call this method in the `onPause()` method of the activity/fragment.

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    CometChat.removeGroupListener(UNIQUE_LISTENER_ID);
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin theme={null}
    CometChat.removeGroupListener(UNIQUE_LISTENER_ID)
    ```
  </Tab>
</Tabs>

## Message Listener

The `MessageListener` class provides you with live events related to messages. Below are the callback methods provided by the `MessageListener` class.

| Method                                                          | Information                                                                                             |
| --------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------- |
| `onTextMessageReceived(TextMessage message)`                    | This event is triggered when a Text Message is received.                                                |
| `onMediaMessageReceived(MediaMessage message)`                  | This event is triggered when a Media Message is received.                                               |
| `onCustomMessageReceived(CustomMessage message)`                | This event is triggered when a Custom Message is received.                                              |
| `onTypingStarted(TypingIndicator typingIndicator)`              | This event is triggered when a user starts typing in a user/group conversation                          |
| `onTypingEnded(TypingIndicator typingIndicator)`                | This event is triggered when a user stops typing in a user/group conversation.                          |
| `onMessagesDelivered(MessageReceipt messageReceipt)`            | This event is triggered when a set of messages are marked as delivered for any particular conversation. |
| `onMessagesRead(MessageReceipt messageReceipt)`                 | This event is triggered when a set of messages are marked as read for any particular conversation.      |
| `onMessageEdited(BaseMessage message)`                          | This method is triggered when a particular message has been edited in a user/group conversation.        |
| `onMessageDeleted(BaseMessage message)`                         | This event is triggered when a particular message is deleted in a user/group conversation.              |
| `onInteractiveMessageReceived(InteractiveMessage message)`      | This event is triggered when an Interactive Message is received.                                        |
| `onInteractionGoalCompleted(InteractionReceipt receipt)`        | This event is triggered when an interaction Goal is achieved.                                           |
| `onTransientMessageReceived(TransientMessage transientMessage)` | This event is triggered when a Transient Message is received.                                           |
| `onMessageReactionAdded(ReactionEvent reactionEvent)`           | This event is triggered when a reaction is added to a message in a user/group conversation.             |
| `onMessageReactionRemoved(ReactionEvent reactionEvent)`         | This event is triggered when a reaction is remove from a message in a user/group conversation.          |

To add the `MessageListener`, you need to use the `addMessageListener()` method provided by the `CometChat` class.

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    CometChat.addMessageListener(UNIQUE_LISTENER_ID, new CometChat.MessageListener() {
      @Override
      public void onTextMessageReceived(TextMessage message) {

      }

      @Override
      public void onMediaMessageReceived(MediaMessage message) {

      }

      @Override
      public void onCustomMessageReceived(CustomMessage message) {

      }

      @Override
      public void onTypingStarted(TypingIndicator typingIndicator) {

      }

      @Override
      public void onTypingEnded(TypingIndicator typingIndicator) {

      }

      @Override
      public void onMessagesDelivered(MessageReceipt messageReceipt) {

      }

      @Override
      public void onMessagesRead(MessageReceipt messageReceipt) {

      }

      @Override
      public void onMessageEdited(BaseMessage message) {

      }

      @Override
      public void onMessageDeleted(BaseMessage message) {

      }

      @Override
      public void onInteractiveMessageReceived(InteractiveMessage interactiveMessage) {

      }

      @Override
      public void onInteractionGoalCompleted(InteractionReceipt interactionReceipt) {

      }


      @Override
      public void onTransientMessageReceived(TransientMessage transientMessage) {

      }

      @Override
      public void onMessageReactionAdded(ReactionEvent reactionEvent) {

      }

      @Override
      public void onMessageReactionRemoved(ReactionEvent reactionEvent) {

      }
    });
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin theme={null}
    CometChat.addMessageListener(UNIQUE_LISTENER_ID, object : CometChat.MessageListener() {
      override fun onTextMessageReceived(message: TextMessage) {
      }

      override fun onMediaMessageReceived(message: MediaMessage) {
      }

      override fun onCustomMessageReceived(message: CustomMessage) {
      }

      override fun onTypingStarted(typingIndicator: TypingIndicator) {
      }

      override fun onTypingEnded(typingIndicator: TypingIndicator) {
      }

      override fun onMessagesDelivered(messageReceipt: MessageReceipt) {
      }

      override fun onMessagesRead(messageReceipt: MessageReceipt) {
      }

      override fun onMessageEdited(message: BaseMessage) {
      }

      override fun onMessageDeleted(message: BaseMessage) {
      }

      override fun onInteractiveMessageReceived(interactiveMessage: InteractiveMessage) {
      }

      override fun onInteractionGoalCompleted(interactionReceipt: InteractionReceipt) {
      }

      override fun onTransientMessageReceived(transientMessage: TransientMessage) {
      }

      override fun onMessageReactionAdded(reactionEvent: ReactionEvent) {
      }

      override fun onMessageReactionRemoved(reactionEvent: ReactionEvent) {
      }
    })
    ```
  </Tab>
</Tabs>

where `UNIQUE_LISTENER_ID` is the unique identifier for the listener. Please make sure that no two listeners are added with the same listener id as this could lead to unexpected behavior resulting in loss of events.

Once the activity/fragment where the `MessageListener` is declared is not in use, you need to remove the listener using the `removeMessageListener()` method which takes the id of the listener to be removed as the parameter. We suggest you call this method in the `onPause()` method of the activity/fragment.

## Call Listener

The `CallListener` class provides you with live events related to calls. Below are the callback methods provided by the `CallListener` class.

| Method                               | Information                                                                                                                                                                                        |
| ------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `onIncomingCallReceived(Call 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 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 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 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              |

To add the `CallListener`, you need to use the `addCallListener()` method provided by the `CometChat` class.

<Tabs>
  <Tab title="Java">
    ```java theme={null}
    CometChat.addCallListener(UNIQUE_LISTENER_ID, new CometChat.CallListener() {
      @Override
      public void onIncomingCallReceived(Call call) {

      }

      @Override
      public void onOutgoingCallAccepted(Call call) {

      }

      @Override
      public void onOutgoingCallRejected(Call call) {

      }

      @Override
      public void onIncomingCallCancelled(Call call) {

      }
    });
    ```
  </Tab>

  <Tab title="Kotlin">
    ```kotlin theme={null}
    CometChat.addCallListener(UNIQUE_LISTENER_ID, object : CometChat.CallListener() {
      override fun onIncomingCallReceived(call: Call) {

      }

      override fun onOutgoingCallAccepted(call: Call) {

      }

      override fun onOutgoingCallRejected(call: Call) {

      }

      override fun onIncomingCallCancelled(call: Call) {

      }
    })
    ```
  </Tab>
</Tabs>

Where `UNIQUE_LISTENER_ID` is the unique identifier for the listener. Make sure that no two listeners are added with the same listener ID as this could lead to unexpected behavior resulting in loss of events.

Once the activity/fragment where the `MessageListener` is declared is not in use, you need to remove the listener using the `removeMessageListener()` method which takes the id of the listener to be removed as the parameter. We suggest you call this method in the `onPause()` method of the activity/fragment.
