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.
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, User
and 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 Client#event:userSubscribed
event.
Users are no longer implicitly subscribed 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:
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:
Client#event:userUnsubscribed
event will be raised to let you know the object is no longer receiving updatesisSubscribed
property will start to return a false value for this User
instanceUser
object will return latest data known for itClient#event:userSubscribed
event will be raised to let you know the new object is receiving updatesThe 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 UserDescriptor
s when displaying a temporary UI such as a membership list.
The new 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.
The new 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 User#event:updated
.
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 getUserChannels()
function.
The 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.
The Client#event:userInfoUpdated
event has been removed together with UserInfo
class. Instead, new events are added: Client#event:userSubscribed
, Client#event:userUnsubscribed
and Client#event:userUpdated
.
To manipulate the new UserDescriptor
and User
class instances new functions has been added to the Client
class:
getUserDescriptor(identity)
returns UserDescriptor
for given identity
getUser(identity)
returns User
object for given identity
and subscribes to itgetSubscribedUsers()
returns array of all currently subscribed Users
New function, getUserDescriptors()
has been added to get the user descriptors for given channel members. Function returns paginated array of UserDescriptor
.
ChannelDescriptor
now is used to represent both public and user channels static(snapshot) information. To reflect this change additional properties are added: isPrivate
, lastConsumedMessageIndex
, status
, type
.
userInfo
property is removed together with Member#event:userInfoUpdated
event. Instead, two new convenience functions are added, getUserDescriptor()
and getUser()
to obtain a UserDescriptor
and subscribed User
object respectively.