Users
A user is someone who can send and receive messages. Usually, they will map directly to the accounts in your website or app. However, you can also create users to act as bots or for AI agents.
userRef.subscribe(onSnapshot): UserSubscription
Parameters
Returns
userRef.subscribeOnline(onSnapshot): UserOnlineSubscription
Parameters
Returns
A snapshot of a user's attributes at a given moment in time.
Users also have private information, such as email addresses and phone numbers, but these are only exposed on the
The unique ID that is used to identify the user in TalkJS
The user's name, which is displayed on the TalkJS UI
Custom metadata you have set on the user
TalkJS supports multiple sets of settings for users, called "roles". Roles allow you to change the behavior of TalkJS for different users. You have full control over which user gets which configuration.
An For more information, see:
When locale is null, the app's default locale will be used
An optional URL to a photo that is displayed as the user's avatar
The default message a person sees when starting a chat with this user
The current state of the subscription
An object with the following fields:
type is one of "pending", "active", "unsubscribed", or "error".
When type is "active", includes latestSnapshot: UserSnapshot | null. It is the current state of the user, or null if they don't exist.
When type is "error", includes the error: Error field. It is a JS Error object explaining what caused the subscription to be terminated.
Resolves when the subscription starts receiving updates from the server.
Resolves when the subscription permanently stops receiving updates from the server.
This is either because you unsubscribed or because the subscription encountered an unrecoverable error.
Unsubscribe from this resource and stop receiving updates.
If the subscription is already in the "unsubscribed" or "error" state, this is a no-op.
A snapshot of a user's online status at a given moment in time.
Snapshots are immutable and we try to reuse them when possible. You should only re-render your UI when oldSnapshot !== newSnapshot.
The user this snapshot relates to
Whether the user is connected right now
Users are considered connected whenever they have an active websocket connection to the TalkJS servers. In practice, this means:
People using the {@link https://talkjs.com/docs/Reference/JavaScript_Data_API/ | JS Data API} are considered connected if they are subscribed to something, or if they sent a request in the last few seconds. Creating a TalkSession is not enough to appear connected.
People using {@link https://talkjs.com/docs/Reference/Components/ | Components}, are considered connected if they have a UI open.
People using the {@link https://talkjs.com/docs/Reference/JavaScript_Chat_SDK/ | JavaScript SDK}, {@link https://talkjs.com/docs/Reference/React_SDK/Installation/ | React SDK}, {@link https://talkjs.com/docs/Reference/React_Native_SDK/Installation/ | React Native SDK}, or {@link https://talkjs.com/docs/Reference/Flutter_SDK/Installation/ | Flutter SDK} are considered connected whenever they have an active Session object.
A subscription to the online status of a user
Get a UserOnlineSubscription by calling {@link UserRef.subscribeOnline}.
Remember to .unsubscribe the subscription once you are done with it.
The current state of the subscription
An object with the following fields:
type is one of "pending", "active", "unsubscribed", or "error".
When type is "active", includes latestSnapshot: UserOnlineSnapshot | null null means the user does not exist.
When type is "error", includes the error field. It is a JS Error object explaining what caused the subscription to be terminated.
Resolves when the subscription starts receiving updates from the server.
Wait for this promise if you want to perform some action as soon as the subscription is active.
The promise rejects if the subscription is terminated before it connects.
Resolves when the subscription permanently stops receiving updates from the server.
This is either because you unsubscribed or because the subscription encountered an unrecoverable error.
Unsubscribe from this resource and stop receiving updates.
If the subscription is already in the "unsubscribed" or "error" state, this is a no-op.