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.
1// advance consumption horizon to arbitrary index2activeChannel.getMessages().then(function (messages) {3if (messages.items.length > 10) {4// let's say UI displayed first 5 messages out of many5// and client wants to mark those as read ones6var someMessageIndex = messages.items[4].index;7activeChannel.updateLastConsumedMessageIndex(someMessageIndex)8.then(function () {9// updated10});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 read2await activeChannel.setAllMessagesConsumed();
and
1// Mark all messages unread2await 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 channel2var members = activeChannel.getMembers();3// for each member, set up a listener for when the member is updated4members.then(function(currentMembers) {5currentMembers.forEach(function(member) {6// handle the read status information for this member7// note this method would use the provided information to render8// this to the user in some way.9updateMemberMessageReadStatus(10member.identity,11member.lastConsumedMessageIndex,12member.lastConsumptionTimestamp13);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 for2// the currently active channel in the UI3activeChannel.on('memberUpdated', function(event) {4// note this method would use the provided information5// to render this to the user in some way6updateMemberMessageReadStatus(event.member.identity,7event.member.lastConsumedMessageIndex,8event.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