User

class User

A user of your app. TalkJS uses the id to uniquely identify this user. All other fields of a User are allowed to vary over time and the TalkJS database will update its fields accordingly.

Method Overview

Constructor

Create a TalkJS User

Properties

availabilityText
: string | null

Availability acts similarly to welcomeMessage but appears as a system message.

custom
: { [name: string]: string | null } | null

Allows you to set custom metadata for the User

email
: string | Array<string> | null

One or more email address belonging to the User. The email addresses will be used for Email Notifications if they are enabled.

id
: string

The unique ID which is used to identify the user in TalkJS

locale
: string | null

The locale field expects an IETF language tag. See the localization documentation.

name
: string

The User's name which will be displayed on the TalkJS UI

phone
: string | Array<string> | null

One or more phone numbers belonging to the User. The phone number will be used for SMS Notifications (this feature requires standard plan and up).

photoUrl
: string | null

An optional URL to a photo which will be displayed as the user's avatar

role
: string | null

TalkJS supports multiple sets of settings, called "roles". These allow you to change the behavior of TalkJS for different users. You have full control over which user gets which configuration.

welcomeMessage
: string | null

The default message a user sees when starting a chat with that person

Deprecated configuration
: string | null

Deprecated. Please use role instead.

Constructor (1)

new User(options)

Create a TalkJS User

Use this constructor to create or update user data. The user is synchronized with the TalkJS backend if they are the current user in a session. If they are not the current user, and they are part of an existing conversation, they will be synchronized when the UI is mounted.

The fields id, name and email are required. A warning will be emitted if role is not specified.

Set email to null if you want to use TalkJS without email fallback.

Parameters

options
: UserOptions
interface UserOptions

id
: string | number

The unqiue ID which is used to identify the user in TalkJS

name
: string

The User's name which will be displayed on the TalkJS UI

custom (optional)
: { [name: string]: string | null } | null

Allows you to set custom metadata for the User

Set any property to null to delete the existing value (if any). When omitted or undefined, the existing value remains unchanged.

email (optional)
: string | Array<string> | null

One or more email address belonging to the User. The email addresses will be used for Email Notifications if they are enabled.

Set to null to delete the existing value(s) (if any). When omitted or undefined, the existing value(s) remain unchanged.

locale (optional)
: string | null

The locale field expects an IETF language tag. See the localization documentation.

Set to null to delete the existing value (if any). When omitted or undefined, the existing value remains unchanged.

phone (optional)
: string | Array<string> | null

One or more phone numbers belonging to the User. The phone number will be used for SMS Notifications (this feature requires standard plan and up).

Set to null to delete the existing value(s) (if any). When omitted or undefined, the existing value(s) remain unchanged.

photoUrl (optional)
: string | null

An optional URL to a photo which will be displayed as the user's avatar

Set to null to delete the existing value (if any). When omitted or undefined, the existing value remains unchanged.

role (optional)
: string | null

TalkJS supports multiple sets of settings, called "roles". These allow you to change the behavior of TalkJS for different users. You have full control over which user gets which configuration.

Set to null to delete the existing value (if any). When omitted or undefined, the existing value remains unchanged.

welcomeMessage (optional)
: string | null

The default message a user sees when starting a chat with that person

Set to null to delete the existing value (if any). When omitted or undefined, the existing value remains unchanged.

Deprecated availabilityText (optional)
: string | null

Availability acts similarly to User​.welcomeMessage but appears as a system message.

Set to null to delete the existing value (if any). When omitted or undefined, the existing value remains unchanged.

Deprecated. Please use Conversation​.welcomeMessages instead.

Deprecated configuration (optional)
: string | null

Deprecated. Please use role instead.

Constructor (2)

new User(id)

Create a TalkJS User

Only use this constructor if you're sure that a user by the given id already exists in TalkJS (for instance, because you synchronized it via the REST API). Otherwise use the new User(options: object): constructor instead.

Parameters

id
: string | number