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
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.
_12// advance consumption horizon to arbitrary index_12activeChannel.getMessages().then(function (messages) {_12 if (messages.items.length > 10) {_12 // let's say UI displayed first 5 messages out of many_12 // and client wants to mark those as read ones_12 var someMessageIndex = messages.items[4].index;_12 activeChannel.updateLastConsumedMessageIndex(someMessageIndex)_12 .then(function () {_12 // updated_12 });_12 }_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
_10// Mark all messages read_10await activeChannel.setAllMessagesConsumed();
and
_10// Mark all messages unread_10await 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.
_15// retrieve the list of members for the active channel_15var members = activeChannel.getMembers();_15// for each member, set up a listener for when the member is updated_15members.then(function(currentMembers) {_15 currentMembers.forEach(function(member) {_15 // handle the read status information for this member_15 // note this method would use the provided information to render_15 // this to the user in some way._15 updateMemberMessageReadStatus(_15 member.identity, _15 member.lastConsumedMessageIndex, _15 member.lastConsumptionTimestamp_15 );_15 });_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.
_10// this code assumes you have a variable names activeChannel for_10// the currently active channel in the UI_10activeChannel.on('memberUpdated', function(event) {_10 // note this method would use the provided information_10 // to render this to the user in some way_10 updateMemberMessageReadStatus(event.member.identity, _10 event.member.lastConsumedMessageIndex, _10 event.member.lastConsumptionTimestamp);_10});
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