ConversationBuilder

interface 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. Note: any changes you make here will not be sent to TalkJS immediately. Instead, instantiate a TalkJS UI using methods such as Session​.createInbox.

Method Overview

leave

Removes the current user from this conversation.

sendMessage

Sends a text message in a given conversation.

setAttributes

Used to set certain attributes for a specific conversation

setParticipant

Sets a participant of the conversation.

Properties

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

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.

photoUrl (optional)
: string | null

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.

subject (optional)
: string | null

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.

welcomeMessages (optional)
: Array<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.

leave

1conversationBuilder.leave(): Promise<boolean>
Removes the current user from this conversation.

Parameters

None.

Returns

Promise<boolean>

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.

sendMessage

1conversationBuilder.sendMessage(text, options): Promise<void>
Sends a text message in a given conversation.

Parameters

text
: string

The message body that is to be sent.

options (optional)
: SendMessageOptions
interface SendMessageOptions
custom (optional)
: CustomData

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.

Returns

Promise<void>

setAttributes

1conversationBuilder.setAttributes(attributes)
Used to set certain attributes for a specific conversation

For example:

1conversation.setAttributes({subject: "Booking question"});
2conversation.setAttributes({custom:
3 {
4 sold: "true",
5 itemId: "720"
6 }
7});

Parameters

interface ConversationAttributes

Conversation attributes that can be set using ConversationBuilder​.setAttributes

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

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.

photoUrl (optional)
: string | 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.

subject (optional)
: 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.

welcomeMessages (optional)
: Array<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.

Returns

void

setParticipant

1conversationBuilder.setParticipant(user, settings)
Sets a participant of the conversation.

This method is idempotent and can be called multiple times.

Parameters

user
: 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.

settings (optional)
: Partial<ParticipationSettings>

An optional setting of participation, can be an initial access right or if user should be notified.

interface ParticipationSettings

Specifies access and notification settings for a given user's participation to a given conversation. Used in ConversationBuilder​.setParticipant.

access (optional)
: "Read" | "ReadWrite"

Specifies the participant's access permission for a conversation. See ConversationBuilder​.setParticipant

When omitted or undefined, the existing value remains unchanged.

notify (optional)
: boolean | "MentionsOnly"

Specifies the participants's notification settings. See ConversationBuilder​.setParticipant

When omitted or undefined, the existing value remains unchanged.

Returns

void