---
url: https://talkjs.com/docs/UI_Components/JavaScript/Classic/Classic_Data_API
title: 'Classic Data API'
minidoc-source: js
minidoc-lib: classic
---

This page documents the Classic Data API, a set of JavaScript classes used to synchronize user and conversation data.
New TalkJS integrations should manage data using the simpler and more powerful [JavaScript Data API](/JavaScript_Data_API/) instead.

## 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.
@classic
New TalkJS integrations should use UserRef via Session.user() instead. `UserRef` is part of the simpler and more powerful Data API. */
export declare class User  {
/** Create a TalkJS User
@param options - Use this overload 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. */
constructor(options: UserOptions);
/** Create a TalkJS User
@param id - Only use this overload 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. */
constructor(id: string|number);
/** Availability acts similarly to User.welcomeMessage but appears as a system message. */
readonly availabilityText?: string|null;
/** Please use User.role instead. */
readonly configuration?: string|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. */
readonly custom?: {
[name: string]: string|null;
}|null;
/** One or more email address belonging to the User. The email addresses will be used for Email Notifications if they are enabled. */
readonly email?: string|Array<string>|null;
/** The unique ID which is used to identify the user in TalkJS */
readonly id: string;
/** The locale field expects an IETF language tag. See the localization documentation. */
readonly locale?: string|null;
/** The User's name which will be displayed on the TalkJS UI */
readonly name: string;
/** 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). */
readonly phone?: string|Array<string>|null;
/** An optional URL to a photo which will be displayed as the user's avatar */
readonly photoUrl?: 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. */
readonly role?: string|null;
/** The default message a user sees when starting a chat with that person */
readonly welcomeMessage?: string|null;
}

## UserOptions
/** */
export interface UserOptions  {
/** 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.
Please use Conversation.welcomeMessages instead. */
availabilityText?: string|null;
/** Please use UserOptions.role instead. */
configuration?: string|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. */
custom?: {
[name: string]: string|null;
}|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. */
email?: string|Array<string>|null;
/** The unqiue ID which is used to identify the user in TalkJS */
id: string|number;
/** 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. */
locale?: string|null;
/** The User's name which will be displayed on the TalkJS UI */
name: string;
/** 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. */
phone?: string|Array<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. */
photoUrl?: 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. */
role?: 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.
Welcome messages are rendered in the UI as messages, but they are not real messages. This means they do not appear when you list messages using the REST API or JS Data API, and you cannot reply or react to them. */
welcomeMessage?: string|null;
}

## ConversationBuilder
/** A Conversation Builder represents a conversation that is about to be created, fetched, or updated. You can use this object to set up or modify a conversation before showing it.
To create a ConversationBuilder, call Session.getOrCreateConversation.
Note: any changes you make here will not be sent to TalkJS immediately. Instead, instantiate a TalkJS UI using methods such as Session.createInbox.
@classic
New TalkJS integrations should use ConversationRef via Session.conversation() instead. `ConversationRef` is part of the simpler and more powerful Data API. */
export interface ConversationBuilder  {
/** Allows custom conversation metadata to be stored in the form `{ [name: string]: string }`
Set any property to `null` to delete the existing value (if any). When omitted or `undefined`, the existing value remains unchanged. */
custom?: {
[name: string]: string|null;
}|null;
/** Removes the current user from this conversation.
@returns A promise that resolves with true upon success (indicating that the user has been removed from this conversation), or false when the user did not have the appropriate permissions, as defined on the "Chat UI" page in the TalkJS dashboard). The promise may reject in case of an unexpected error.
@classic
The Data API equivalent of `leave` is ParticipantRef.delete:
```ts
session.conversation(convId).participant(session.currentUser).delete();
``` */
leave(): Promise<boolean>;
/** An optional URL to a photo which will be shown as the photo for the conversation.
Set to `null` to delete the existing value (if any). When omitted or `undefined`, the existing value remains unchanged. */
photoUrl?: string|null;
/** Sends a text message in a given conversation.
@param text - The message body that is to be sent.
@classic
The Data API equivalent of `sendMessage` is ConversationRef.send:
```ts
session.conversation(convId).send("Hello");
```
It can also send formatted messages, file attachments, and map locations. */
sendMessage(text: string, options?: SendMessageOptions): Promise<void>;
/** Used to set certain attributes for a specific conversation
Setting the conversation subject
```ts
conversation.setAttributes({subject: "Booking question"});
```
Setting the `custom.sold` and `custom.itemId` properties
```ts
conversation.setAttributes({custom:
{
sold: "true",
itemId: "720"
}
});
```
If the conversation has any pre-existing custom properties, they will not be removed unless you set them to null.
@classic
The Data API equivalent of `setAttributes` is ConversationRef.set:
```ts
session.conversation(convId).set({ subject: "Booking question" });
``` */
setAttributes(attributes: ConversationAttributes): void;
/** Sets a participant of the conversation.
This method is idempotent and can be called multiple times.
@param user - A `User` object that identifies the person who is a participant of the conversation. The user is uniquely identified by their id; all other fields (name, photo etc) are overwritten in the TalkJS database each time they change.
@param settings - An optional setting of participation, can be an initial `access` right or if user should be notified.
@classic
The Data API equivalent of `setParticipant` is ParticipantRef.set:
```ts
session.conversation(convId).participant(userId).set({ notify: false });
``` */
setParticipant(user: User, settings?: Partial<ParticipationSettings>): void;
/** An optional conversation subject which will be displayed in the chat header.
Set to `null` to delete the existing value (if any). When omitted or `undefined`, the existing value remains unchanged. */
subject?: string|null;
/** Messages which are sent at the beginning of a chat. In this case the messages will appear as system messages.
Set to `null` to delete the existing value (if any). When omitted or `undefined`, the existing value remains unchanged.
Welcome messages are rendered in the UI as messages, but they are not real messages. This means they do not appear when you list messages using the REST API or JS Data API, and you cannot reply or react to them. */
welcomeMessages?: Array<string>|null;
}

## SendMessageOptions
/** */
export interface SendMessageOptions  {
/** An object with any custom data that you may wish to associate with this message. The custom data is sent back to you via webhooks and the REST API.
Set any property to `null` to delete the existing value (if any). When omitted or `undefined`, the existing value remains unchanged. */
custom?: CustomData;
}

## ConversationAttributes
/** Conversation attributes that can be set using ConversationBuilder.setAttributes */
export interface ConversationAttributes  {
/** Custom metadata that is stored with the conversation
Set any property to `null` to delete the existing value (if any). When omitted or `undefined`, the existing value remains unchanged. */
custom?: {
[key: string]: string|null;
}|null;
/** The URL of a photo to be used for this conversation in the TalkJS UI in case there are more than 2 participants (TalkJS shows the photo of the other participant in a 1-on-1 conversation)
Set to `null` to delete the existing value (if any). When omitted or `undefined`, the existing value remains unchanged. */
photoUrl?: string|null;
/** A human-readable subject of the conversation. Supports formatted links in a Markdown-style syntax, e.g. `Beautiful<https://example.com/booking/18644|home by the sea>!`. URLs and email addresses are made clickable, and emojis made to work cross-platform.
Set to `null` to delete the existing value (if any). When omitted or `undefined`, the existing value remains unchanged. */
subject?: string|null;
/** Messages which are sent at the beginning of a chat. In this case the messages will appear as system messages.
Set to `null` to delete the existing value (if any). When omitted or `undefined`, the existing value remains unchanged.
Welcome messages are rendered in the UI as messages, but they are not real messages. This means they do not appear when you list messages using the REST API or JS Data API, and you cannot reply or react to them. */
welcomeMessages?: Array<string>|null;
}