Typing indicator
Typing indicators show users when someone is composing a message. This feature:
- Increases engagement - Users see activity in group chats
- Sets expectations - Users know when to expect a response in 1:1 conversations
Not available for public chats
Typing indicator is disabled in public chats. If you try implementing this feature in a public channel type, you'll get the Typing indicators are not supported in Public chats error.
Start typing
startTyping() activates the typing indicator on a channel.
The method uses a debounce mechanism: signals are sent at intervals rather than on every keystroke. The default timeout is 5000 ms (5 seconds), with a 1000 ms buffer to prevent rapid re-triggering.
Custom timeout
Set a custom timeout with the typingTimeout parameter during initialization.
Method signature
This method has the following signature:
1channel.startTyping(): Promise<any>
Input
This method doesn't take any parameters.
Output
| Type | Description |
|---|---|
Promise<any> | Returned object with a value of any type. |
Sample code
Start a typing indicator on the support channel.
1// reference the channel where you want to listen to typing signals
2const channel = await chat.getChannel("support")
3// invoke the "startTyping()" method
4await channel.startTyping()
Stop typing
stopTyping() deactivates a typing indicator on a given channel.
You can use this method in cases when you want to disable the typing indicator immediately - for example, when a user deletes a previously drafted message - without waiting for the typingTimeout to end.
Method signature
This method has the following signature:
1channel.stopTyping(): Promise<any>
Input
This method doesn't take any parameters.
Output
| Type | Description |
|---|---|
Promise<any> | Returned object with a value of any type. |
Sample code
Stop a typing indicator on the support channel.
1// reference the channel where you want to listen to typing signals
2const channel = await chat.getChannel("support")
3// invoke the "stopTyping()" method
4await channel.stopTyping()
Get typing events
getTyping() adds a signal events listener underneath to get all events of type typing. Run it once on a given channel to start listening to typing signals. You can also use it to get a list of typing user IDs. This method also returns a function you can invoke to stop receiving signal events and unsubscribe from the channel.
Method signature
getTyping() accepts a callback function as an argument. The Chat SDK invokes this callback whenever someone starts/stops typing. This function takes a single argument of the list of currently typing user IDs.
This method takes the following parameters:
1channel.getTyping(
2 callback: (
3 typingUserIds: string[]
4 ) => unknown
5): () => void
Input
| Parameter | Description |
|---|---|
callback *Type: n/a Default: n/a | Callback function passed as a parameter. It defines the custom behavior to be executed whenever someone starts/stops typing. |
→ typingUserIds *Type: string[]Default: n/a | Array with a list of all currently typing user IDs (id). |
Output
| Type | Description |
|---|---|
() => void | Function you can call to disconnect (unsubscribe) from the channel and stop receiving signal events. |
Sample code
Get a list of user IDs currently typing on the support channel.
1// reference the channel where you want to listen to typing signals
2const channel = await chat.getChannel("support")
3// invoke the "getTyping()" method
4channel.getTyping((data) => {
5 console.log("These channel members are currently typing: ", data)
6})
Other examples
Stop receiving signals on the support channel.
1const channel = await chat.getChannel("support")
2const stopUpdates = channel.getTyping(/* handle typing callback */)
3// after some time...
4stopUpdates()