Quick Reference for AI Agents & Developers
Send a Typing Indicator
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. In order to send the typing indicator, you need to use the TypingIndicator class.
- Java (Strat Typing User)
- Kotlin (Strat Typing User)
- Java (Strat Typing Group)
- Kotlin (Strat Typing Group)
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. In order to send the typing indicator, you need to use the TypingIndicator class.
- Java (Strat Typing User)
- Kotlin (Strat Typing User)
- Java (Strat Typing Group)
- Kotlin (Strat Typing Group)
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
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.
- Java
- Kotlin
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 | UID of the receiver. This is the ID of the group or the user the typing indicator is being 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. CometChatConstants.RECEIVER_TYPE_USER 2. CometChatConstants.RECEIVER_TYPE_GROUP |
metadata | A JSONObject to provider additional data |
Best Practices
Debounce Typing Events
Debounce Typing Events
Don’t send typing indicators on every keystroke. Use a debounce mechanism (e.g., 300-500ms delay) to reduce API calls and improve performance.
Auto-Stop Typing After Timeout
Auto-Stop Typing After Timeout
Automatically call
endTyping() after 3-5 seconds of inactivity to handle cases where users stop typing without sending a message.Stop Typing on Message Send
Stop Typing on Message Send
Always call
endTyping() immediately after sending a message to clear the typing indicator for recipients.Handle Multiple Typers in Groups
Handle Multiple Typers in Groups
In group chats, display “User1, User2, and 3 others are typing…” to handle multiple simultaneous typers gracefully.
Use Metadata for Rich Indicators
Use Metadata for Rich Indicators
Use the metadata field to send additional context like “recording audio” or “uploading photo” for richer status indicators.
Troubleshooting
Typing Indicators Not Received
Typing Indicators Not Received
Symptom:
onTypingStarted() or onTypingEnded() not being called.Cause: Message listener not registered or removed prematurely.Solution: Ensure addMessageListener() is called before typing indicators are sent. Keep the listener active while the chat is open.Typing Indicator Stuck
Typing Indicator Stuck
Symptom: Typing indicator shows indefinitely without clearing.Cause:
endTyping() not called when user stops typing or leaves the chat.Solution: Call endTyping() when user sends a message, clears input, or navigates away. Implement auto-timeout after 3-5 seconds.Too Many Typing Events
Too Many Typing Events
Symptom: Performance issues or rate limiting due to excessive typing indicator calls.Cause: Sending typing indicators on every keystroke without debouncing.Solution: Implement debouncing to send typing indicators at most once every 300-500ms.