Quick Reference — Send and listen for typing indicators:
Send a Typing Indicator
In other words, as a sender, how do I let the recipient(s) know that I’m typing?Start Typing
You can use thestartTyping() method to inform the receiver that the logged-in user has started typing. The receiver will receive this information in the onTypingStarted() method of the MessageListener class. To send the typing indicator, you need to use the TypingIndicator class.
- To User
- To Group
- TypeScript (User)
- TypeScript (Group)
Response
Response
startTyping called — the typing indicator object sent to the receiver:
| Parameter | Type | Description | Sample Value |
|---|---|---|---|
receiverId | string | Receiver’s unique identifier | "cometchat-uid-6" |
receiverType | string | Type of receiver | "user" |
Stop Typing
You can use theendTyping() method to inform the receiver that the logged-in user has stopped typing. The receiver will receive this information in the onTypingEnded() method of the MessageListener class. To send the typing indicator, you need to use the TypingIndicator class.
- To User
- To Group
- TypeScript (User)
- TypeScript (Group)
Response
Response
endTyping called — the typing indicator object sent to the receiver:
| Parameter | Type | Description | Sample Value |
|---|---|---|---|
receiverId | string | Receiver’s unique identifier | "cometchat-uid-6" |
receiverType | string | Type of receiver | "user" |
Custom DataYou can use the
metadata field of the TypingIndicator class to pass additional data along with the typing indicators. The metadata field is a JSONObject and can be set using the setMetadata() method of the TypingIndicator class. This data will be received at the receiver end and can be obtained using the getMetadata() method.Real-time Typing Indicators
In other words, as a recipient, how do I know when someone is typing? You will receive the typing indicators in theonTypingStarted() and the onTypingEnded() method of the registered MessageListener class.
- JavaScript
- TypeScript
Response
Response
onTypingStarted — received when a user starts typing:TypingIndicator Object:
onTypingEnded — received when a user stops typing:TypingIndicator Object:
| Parameter | Type | Description | Sample Value |
|---|---|---|---|
receiverId | string | Receiver’s unique identifier | "cometchat-uid-7" |
receiverType | string | Type of receiver | "user" |
sender | object | User who is typing | See below ↓ |
sender Object:| Parameter | Type | Description | Sample Value |
|---|---|---|---|
uid | string | User’s unique identifier | "cometchat-uid-6" |
name | string | User’s display name | "Ronald Jerry" |
avatar | string | URL to user’s avatar | "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-6.webp" |
status | string | User’s online status | "online" |
role | string | User’s role | "default" |
hasBlockedMe | boolean | Whether user has blocked current user | false |
blockedByMe | boolean | Whether current user blocked this user | false |
deactivatedAt | number | Deactivation timestamp (0 if active) | 0 |
tags | array | User tags | [] |
onTypingEnded — received when a user stops typing:TypingIndicator Object:
| Parameter | Type | Description | Sample Value |
|---|---|---|---|
receiverId | string | Receiver’s unique identifier | "cometchat-uid-7" |
receiverType | string | Type of receiver | "user" |
sender | object | User who stopped typing | See below ↓ |
sender Object:| Parameter | Type | Description | Sample Value |
|---|---|---|---|
uid | string | User’s unique identifier | "cometchat-uid-6" |
name | string | User’s display name | "Ronald Jerry" |
avatar | string | URL to user’s avatar | "https://assets.cometchat.io/sampleapp/v2/users/cometchat-uid-6.webp" |
status | string | User’s online status | "online" |
role | string | User’s role | "default" |
hasBlockedMe | boolean | Whether user has blocked current user | false |
blockedByMe | boolean | Whether current user blocked this user | false |
deactivatedAt | number | Deactivation timestamp (0 if active) | 0 |
tags | array | User tags | [] |
TypingIndicator class consists of the below parameters:
| Parameter | Information |
|---|---|
| sender | An object of the User class holding all the information related to the sender of the typing indicator. |
| receiverId | Unique Id of the receiver. This can be the Id of the group or the user the typing indicator is sent to. |
| receiverType | This parameter indicates if the typing indicator is to be sent to a user or a group. The possible values are: 1. CometChat.RECEIVER_TYPE.USER 2. CometChat.RECEIVER_TYPE.GROUP |
| metadata | A JSONObject to provide additional data. |
Best Practices
Best Practices
- Debounce start typing calls — Avoid calling
startTyping()on every keystroke. Instead, debounce the call so it fires once when the user begins typing and doesn’t repeat until after a short pause. - Call endTyping() explicitly — Always call
endTyping()when the user clears the input field, sends a message, or navigates away from the chat screen. - Use unique listener IDs — Each screen or component that registers a
MessageListenershould use a distinctlistenerIdto avoid conflicts. - Handle metadata sparingly — Only attach
metadatato typing indicators when you have a concrete use case (e.g., indicating which thread the user is typing in).
Troubleshooting
Troubleshooting
- Typing indicator not appearing for the recipient — Verify that the recipient has registered a
MessageListenerwithonTypingStartedandonTypingEndedcallbacks before the sender starts typing. - Typing indicator stuck in “typing” state — Ensure
endTyping()is called when the user stops typing or sends a message. CometChat automatically times out typing indicators after a short period, but explicitly ending them provides a better user experience. - Listener not firing — Confirm that the
listenerIdused inaddMessageListeneris unique and that the listener has not been removed prematurely. - Indicators not working in groups — Make sure you are using
CometChat.RECEIVER_TYPE.GROUPwith the correct group ID (GUID), not a user ID.