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.
Twilio Programmable Chat 1.0 brings additional controls on data synchronization to enhance performance as well as many other improvements. This guide will help you migrate your existing Chat applications to the new release 1.0.
Client initialization has been simplified to reflect most users typical usage of the system. All user channels (channels for which the current user is joined to or an owner of) will be subscribed to from client startup but only the members roster will be synchronized initially. This keeps client startup fast while still reflecting the latest activity immediately to the client.
UserInfo has been deprecated and replaced with two distinct classed,
UserDescriptor. Similar to
ChannelDescriptor class, a
UserDescriptor represents a snapshot of data in time that should be utilized directly after obtaining it but not retained since it will not be updated with new data over time.
User class adds a new concept to Programmable Chat, subscriptions. A Programmable Chat primitive is subscribed if it will receive updates from the server.
Channel objects at this time are always subscribed, and
ChannelDescriptor objects are not. Similarly,
UserDescriptor objects are not subscribed but a
User object may or may not be subscribed. When a
User is initially subscribed to on the client, you will receive the
Users are no longer implicitly subscribed to to improve performance on large instances. You can subscribe up to a maximum 100 of users at once after which your least recently subscribed User will be unsubscribed. Using either subscribed Users or User Descriptors appropriately is key to the performance of your application:
- Subscribed Users will immediately reflect changes made on other clients, such as Friendly Name and Attributes and will also have the most up-to-date reachability and online status information. Subscribed Users are best for live display of messages or recently contacted Users by the client.
- User Descriptors are a snapshot in time of that user’s status in the system. These snapshot objects are ideal for temporary lists of users within your user interface or for visualizing large numbers of users on a Channel where constant data synchronization is not key.
When you first obtain a
User object, it will be subscribed but there is a maximum 100 of
User objects which may be subscribed at a time in the Programmable Chat client. Once this limit is exceeded, the least recently subscribed
User object in memory will be unsubscribed. Several things happen when this occurs:
- The new
Client#event:userUnsubscribedevent will be raised to let you know the object is no longer receiving updates
isSubscribedproperty will start to return a false value for this
- Attempting to read data from from the unsubscribed
Userobject will return latest data known for it
- The new
Client#event:userSubscribedevent will be raised to let you know the new object is receiving updates
The number of Users you can concurrently subscribe to in a given instance of the Chat client is large enough that many implementation of Chat will not be affected by User objects being unsubscribed. This is something you should provide for in your code though, and ensure you are using
User objects when consistently updated representation of users is important and
UserDescriptors when displaying a temporary UI such as a membership list.
UserDescriptor class has all of the accessors of the deprecated
UserInfo object but none of the setters. It also has a function
subscribe() that will return a subscribed
User object has the full functionality of the old
UserInfo object along with a
isSubscribed property which should be checked to see if a
User object is still subscribed. To reflect updates there is
There is an
unsubscribe() function on this object which will remove the
User object from the subscription pool explicitly if you no longer need updates for it at this time.
There is a new function,
getSubscribedChannels() which will give you the list of currently subscribed and synchronized channels. This function replaces the deprecated
getPublicChannels() function has been renamed to
getPublicChannelDescriptors() for clarity on its returned objects and a new function,
getUserChannelDescriptors() has been added. The
getUserChannelDescriptors() returns paginated
ChannelDescriptor objects array with static information of all created or joined channels of currently logged in user.
Client#event:userInfoUpdated event has been removed together with
UserInfo class. Instead, new events are added:
To manipulate the new
User class instances new functions has been added to the
Userobject for given
identityand subscribes to it
getSubscribedUsers()returns array of all currently subscribed
getUserDescriptors() has been added to get the user descriptors for given channel members. Function returns paginated array of
ChannelDescriptor now is used to represent both public and user channels static(snapshot) information. To reflect this change additional properties are added:
userInfo property is removed together with
Member#event:userInfoUpdated event. Instead, two new convenience functions are added,
getUser() to obtain a
UserDescriptor and subscribed
User object respectively.