Rate this page:

Message Consumption Horizon and Read Status

Programmable Chat has been deprecated and is no longer supported. Instead, we'll be focusing on the next generation of chat: Twilio Conversations. Find out more about the EOL process here.

If you're starting a new project, please visit the Conversations Docs to begin. If you've already built on Programmable Chat, please visit our Migration Guide to learn about how to switch.

Message Consumption Horizon for Programmable Chat allows a User's Message read status to synchronize across devices and endpoints. This is done by referencing the User's consumption or read to point within a Channel's Messages. The Consumption Horizon can be consumed in real time across all of a User's endpoints to ensure an accurate, synchronized representation to all clients for the User.

consumed status is also used to represent other Channel Members' Read Statuses and Consumption Points for Messages within a Channel.

Table of Contents

Consumption Horizon

A User's Consumption Horizon within a Channel is based on a lastConsumedMessageIndex. This references the index property of a Message. Each client SDK provides a method allowing the User to send a Consumption Report which supplies the User's last consumed Message index for the Channel.

// advance consumption horizon to arbitrary index
activeChannel.getMessages().then(function (messages) {
    if (messages.items.length > 10) {
        // let's say UI displayed first 5 messages out of many
        // and client wants to mark those as read ones
        var someMessageIndex = messages.items[4].index;
          .then(function () {
              // updated

Besides that, there are two helper methods for most common operations used in Consumption Horizon feature: marking all messages as read and marking them back unread. Respectively, they may be called as

// Mark all messages read
await activeChannel.setAllMessagesConsumed();


// Mark all messages unread
await activeChannel.setNoMessagesConsumed();

Note: Chat does not automatically set the Consumption Horizon. If you do not explicitly set this within your application, no Consumption Horizon will exist for a User within the Channel. Without a Consumption Horizon, your user's Consumption Horizon (read status) will not synchronize correctly across clients. If a user does not have a Consumption Horizon set on a channel, getting unconsumed messages will always return 0. If a member of a Channel has no consumption status, their last consumed index and timestamp will be null or 0 depending on the platform.

Note: Consumption report submissions from client endpoints are batched and not sent with every report submission API call. The batch sends are timer based and by default are submitted every 10 seconds. This interval time, in seconds, can be configured per Service instance via the REST API using the ConsumptionReportInterval property.

Note: It is possible to disable the Message Consumption Horizon feature entirely for a Service instance. This is done by configuring the Service instance resource using the REST API and setting the ReadStatusEnabled property to false. Setting this property to true enables the feature.

Message Read Status

By referencing other Members' Channel Consumption Horizon values, you can show how far a member has read within a channel. This allows for Channel implementations which show who has seen what Messages within the Channel.

// retrieve the list of members for the active channel
var members = activeChannel.getMembers();
// for each member, set up a listener for when the member is updated
members.then(function(currentMembers) {
    currentMembers.forEach(function(member) {
        // handle the read status information for this member
        // note this method would use the provided information to render
        // this to the user in some way.

To determine what content a Member has consumed, reference the Member's lastConsumedMessageIndex. It is also possible to show when a Member last set their Consumption Horizon by referencing their lastConsumptionTimestamp property. These properties are available to read statically from the Member instances.

These properties can also be used to show changes to Members' Consumption Horizons in real time by listening for the memberUpdated event on a channel instance.

// this code assumes you have a variable names activeChannel for
// the currently active channel in the UI
activeChannel.on('memberUpdated', function(event) {
     // note this method would use the provided information
     // to render this to the user in some way        

Note: Programmable Chat does not automatically set the Consumption Horizon. If the Consumption Horizon is not set for a User's Channel Messages, other Channel Members will not be able to know where that Member has read up to within a Channel.

Next: Reachability Indicator

Rate this page:

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 by visiting Twilio's Stack Overflow Collective or browsing the Twilio tag on Stack Overflow.

Loading Code Sample...

        Thank you for your feedback!

        Please select the reason(s) for your feedback. The additional information you provide helps us improve our documentation:

        Sending your feedback...
        🎉 Thank you for your feedback!
        Something went wrong. Please try again.

        Thanks for your feedback!