Typing Indicator

The Programmable Chat Typing Indicator feature enables typing signals to be sent for Members from their client endpoints when they are typing within a Channel.

These signals are then sent to all other connected Members of the Channel, allowing for UI features to be implemented, such as showing "User is typing" style messages or indicators for Channel Members. Typing is always within the context of a Channel and a Member.

The Typing Indicator feature follows a producer/consumer model, with the Chat SDKs exposing API methods to set when the User is typing in a Channel. This is signaled via Chat in real time to other Members of the Channel, where events are fired for the typing event.

Table of contents:

Sending Typing Indicator

The Chat Typing Indicator is always in relation to a Channel - allowing Typing to be correctly indicated within the Channel where the Member is typing.

Note: The Typing Indicator signal is not automatically sent by Chat. The Typing Indicator must be explicitly sent using the relevant SDK API methods.

Note: To optimise network traffic, Chat client endpoints will only send a Typing signal once every 5 seconds by default, even if the Typing API command is called more frequently. The send threshold value can be configured for a Service instance by setting the TypingIndicatorTimeout property of the Services resource. Note that reducing this value will cause more network traffic to be generated by client endpoints calling the Typing API.

To send the Typing Indicator, the following code can be used:

Loading Code Samples...
Language
// intercept the keydown event
inputBox.on('keydown', function(e) {
  // if the RETURN/ENTER key is pressed, send the message
  if (e.keyCode === 13) {
    sendButton.click();
  } else {
    // else send the Typing Indicator signal
    activeChannel.typing();
  }
});
Sending the Typing Indicator

Consuming Typing Indicator

In order to display the Typing Indicator when other Members are typing within a Channel, the Typing Indicator Events must be consumed and processed on the clients. This is done by listening for the relevant Typing Indicator events/callbacks and processing these appropriately.

Note: The Typing Indicator signal is not automatically sent by Programmable Chat. Typing events will not be received if the Member does not send them explicitly (see the previous section).

Here is an example of listening for the Typing event and then processing this to display a "typing" message for the relevant Member:

//set up the listener for the typing started Channel event
activeChannel.on('typingStarted', function(member) {
    //process the member to show typing
    updateTypingIndicator(member, true);
});

//set  the listener for the typing ended Channel event
activeChannel.on('typingEnded', function(member) {
    //process the member to stop showing typing
    updateTypingIndicator(member, false);
});

Next: Message Consumption Horizon

Need some help?

We all do sometimes; code is hard. Get help now from our support team, or lean on the wisdom of the crowd browsing the Twilio tag on Stack Overflow.

1 / 1
Loading Code Samples...
// intercept the keydown event
inputBox.on('keydown', function(e) {
  // if the RETURN/ENTER key is pressed, send the message
  if (e.keyCode === 13) {
    sendButton.click();
  } else {
    // else send the Typing Indicator signal
    activeChannel.typing();
  }
});