Skip to contentSkip to navigationSkip to topbar
On this page

Message Consumption Horizon and Read Status


(error)

Danger

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(link takes you to an external page).

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

consumption-horizon page anchor

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.

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

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

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

and

1
// Mark all messages unread
2
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.


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.

1
// retrieve the list of members for the active channel
2
var members = activeChannel.getMembers();
3
// for each member, set up a listener for when the member is updated
4
members.then(function(currentMembers) {
5
currentMembers.forEach(function(member) {
6
// handle the read status information for this member
7
// note this method would use the provided information to render
8
// this to the user in some way.
9
updateMemberMessageReadStatus(
10
member.identity,
11
member.lastConsumedMessageIndex,
12
member.lastConsumptionTimestamp
13
);
14
});
15
});

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.

1
// this code assumes you have a variable names activeChannel for
2
// the currently active channel in the UI
3
activeChannel.on('memberUpdated', function(event) {
4
// note this method would use the provided information
5
// to render this to the user in some way
6
updateMemberMessageReadStatus(event.member.identity,
7
event.member.lastConsumedMessageIndex,
8
event.member.lastConsumptionTimestamp);
9
});

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

Need some help?

Terms of service

Copyright © 2024 Twilio Inc.