interface Popup

A messaging UI for just a single conversation. There is no way for the user to switch between conversations (but you can change the active conversation through select). Create a Popup through Session.createPopup and then call mount to show it.
createHtmlPanel

HTML Panels allow you to place a HTML document in an iframe in your chats, just above the entry box.

destroy

Destroys the Popup

hide

Closes the Popup, but doesn't remove it from the DOM

mount

Mounts the Popup to the parent container

off

Used to stop listening to TalkJS events.

on("blur")

Triggers when the chat UI gets unfocused (i.e. the user clicks/taps anywhere outside it)

on("close")

Triggers when the popup is closed

on("focus")

Triggers when the chat UI gets focused (i.e. the user clicks/taps anywhere inside it)

on("open")

Triggers when the popup is opened

on("sendMessage")

Triggers when the user sends a message using the TalkJS UI

on("translationTriggered")

Triggers when the user toggles translation in a conversation

select

Switches the active conversation the conversation identified by conversation, which can be either a Conversation object or a TalkJS conversation id.

setMessageFilter

Used to control which messages are shown in the message list, depending on a type, origin or custom message attributes. See MessagePredicate for all available options.

setPresence

Sets metadata for the current session.

setTranslationEnabledDefault

Enable/disable translation by default. This setting is applied to any conversation for which you haven't set a specific value.

setTranslationEnabledForConversation

Enable or disable translation for a conversation.

show

Shows the Popup, previously hidden or mounted with a parameter show: false

toggleDesktopNotifications

Deprecated. Please use Session.setDesktopNotificationEnabled instead.

messageField
Encapsulates the message entry field tied to the currently selected conversation.

createHtmlPanel

popup.createHtmlPanel(options): Promise<HtmlPanel>

HTML Panels allow you to place a HTML document in an iframe in your chats, just above the entry box.

Using HTML Panels, you can extend TalkJS UIs to have anything from credit card payments to lead collection forms, or, for instance, to show the product details of a marketplace transaction between your users. See our HTMLPanels documentation for more info

Parameters

options

interface HtmlPanelOptions

conversation

optional
Either a Conversation object (as returned from getOrCreateConversation) or the id field of a conversation (which you may have stored in your database). If given the HTML panel called will only show up for that conversation.
height
number

optional
Optional, defaults to 300 (px).
show
boolean

optional
Optional, defaults to true. Set false if you don't want the HTML panel to be shown after createHtmlPanel is called. You can change the visibility of the HTML panels by calling .hide() or .show() on the HtmlPanel instance returned by createHtmlPanel's promise.
url
string
Required. URL you want to load inside the HTML panel. Url can be absolute ("https://www.example.com/register-form.html") or relative ("register-form.html"). We recommend using same origin pages to have better control of the page. Learn more about HTML Panels and same origin pages here.

Returns

Promise<HtmlPanel>

destroy

popup.destroy()

Destroys the Popup

Call this before removing the Popup container from the DOM.

Parameters

None.

Returns

void

hide

popup.hide()

Closes the Popup, but doesn't remove it from the DOM

Parameters

None.

Returns

void

mount

popup.mount(options): Promise<void>

Mounts the Popup to the parent container

Parameters

options
{     show?: boolean }

optional

Returns

Promise<void>

off

This method has 6 overloads:
popup.off(eventType, handler)

Used to stop listening to TalkJS events.

Stops listening for the _open_ event

Parameters

eventType
"open"
handler
(event: OpenEvent) => void

The handler function must be the same handler function that was passed to on("open")

Returns

void
popup.off(eventType, handler)

Used to stop listening to TalkJS events.

Stops listening for the _close_ event

Parameters

eventType
"close"
handler
(event: CloseEvent) => void

The handler function must be the same handler function that was passed to on("close")

Returns

void
popup.off(eventType, handler)

Used to stop listening to TalkJS events.

Stops listening for the _sendMessage_ event

Parameters

eventType
"sendMessage"
handler
(event: SendMessageEvent) => void

The handler function must be the same handler function that was passed to on("sendMessage")

Returns

void
popup.off(eventType, handler)

Used to stop listening to TalkJS events.

Stops listening for the _focus_ event

Parameters

eventType
"focus"
handler
() => void

The handler function must be the same handler function that was passed to on("focus")

Returns

void
popup.off(eventType, handler)

Used to stop listening to TalkJS events.

Stops listening for the _blur_ event

Parameters

eventType
"blur"
handler
() => void

The handler function must be the same handler function that was passed to on("blur")

Returns

void
popup.off(eventType, handler)

Used to stop listening to TalkJS events.

Stops listening for the _translationToggled_ event

Parameters

eventType
"translationToggled"
handler
() => void

The handler function must be the same handler function that was passed to on("translationToggled")

Returns

void

on("blur")

popup.on(eventType, handler)

Triggers when the chat UI gets unfocused (i.e. the user clicks/taps anywhere outside it)

Parameters

eventType
"blur"
handler
(event: BlurEvent) => void

Returns

void

on("close")

popup.on(eventType, handler)

Triggers when the popup is closed

Parameters

eventType
"close"
handler
(event: CloseEvent) => void

Returns

void

on("focus")

popup.on(eventType, handler)

Triggers when the chat UI gets focused (i.e. the user clicks/taps anywhere inside it)

Parameters

eventType
"focus"
handler
(event: FocusEvent) => void

Returns

void

on("open")

popup.on(eventType, handler)

Triggers when the popup is opened

Parameters

eventType
"open"
handler
(event: OpenEvent) => void

Returns

void

on("sendMessage")

popup.on(eventType, handler)

Triggers when the user sends a message using the TalkJS UI

Parameters

eventType
"sendMessage"
handler
(event: SendMessageEvent) => void

Returns

void

on("translationTriggered")

popup.on(eventType, handler)

Triggers when the user toggles translation in a conversation

Parameters

eventType
"translationToggled"
handler
(event: TranslationToggledEvent) => void

Returns

void

select

popup.select(conversation)

Switches the active conversation the conversation identified by conversation, which can be either a Conversation object or a TalkJS conversation id.

Parameters

conversation

Returns

void

setMessageFilter

popup.setMessageFilter(filter)

Used to control which messages are shown in the message list, depending on a type, origin or custom message attributes. See MessagePredicate for all available options.

Parameters

filter

interface MessagePredicate

custom
{     [key: string]: CustomFieldPredicate }

optional
Only select messages that have particular custom fields set to particular values.

Every key must correspond to a key in the custom message data that you have set. It is not necessary for all messages to have these keys.

Each value must be one of the following:

A string, equal to "exists" or "!exists"

A 2-element array of [operator, operand] structure. The operand must be either a string or an array of strings (for the oneOf operators). Valid operators are: "==", "!=", "oneOf", and "!oneOf".

Examples, assuming you have set a category custom field on your messages:

// Only show messages that have no category set:
{ custom: { category: "!exists" } }

// Only show messages of that have the category "shoes" { custom: { category: ["==", "shoes"] } }

// Only show messages that have the 'topic' either "inquiry" or "reservation" { custom: { topic: ["oneOf", ["inquiry", "reservation"] ] } }

// Only show messages about shoes that are marked visible. // this assumes you also have a custom field called visibility { custom: { category: ["==", "shoes"], visibility: ["==", "visible" ] } }

origin
FieldPredicate<"web" | "rest" | "email" | "import">

optional
Only show messages that were sent by users (web), through the REST API (rest), via reply-to-email (email) or via the import REST API (import). For example:
// Don't show messages that were sent via the REST API
{ origin: ["!=", "rest"] }
sender
{     id?: FieldPredicate<string>     custom?: {         [key: string]: CustomFieldPredicate     }     locale?: FieldPredicate<string>     role?: FieldPredicate<string> }

optional
Only show messages that are sent by a sender that has all of the given properties For example:
// Only show messages sent by users with the role of 'admin' and if the user ID is 1.
{sender: {role: ["==", "admin"], id: ["==", "1"]}}
type
FieldPredicate<"UserMessage" | "SystemMessage">

optional
Only show messages of a given type, for example:
{type: ["==", "SystemMessage"]}

Returns

void

setPresence

popup.setPresence({ visible, custom })

Sets metadata for the current session.

Parameters

{ visible, custom }
{     visible?: boolean     custom?: {         [key: string]: string     } }

Returns

void

setTranslationEnabledDefault

popup.setTranslationEnabledDefault(enabled)

Enable/disable translation by default. This setting is applied to any conversation for which you haven't set a specific value.

Parameters

enabled
boolean | "auto"

Whether conversations should be translated by default or not. Pass "auto" to enable translation for conversations with users with different locales.

Returns

void

setTranslationEnabledForConversation

popup.setTranslationEnabledForConversation(conversation, enabled)

Enable or disable translation for a conversation.

Parameters

conversation

The conversation for which this hsould be be set. If not specified, the setting will be applied to the currently selected conversation.

enabled
boolean

Whether translation should be enabled

Returns

void

show

popup.show()

Shows the Popup, previously hidden or mounted with a parameter show: false

Parameters

None.

Returns

void

toggleDesktopNotifications

popup.toggleDesktopNotifications(isEnabled)

Please use Session.setDesktopNotificationEnabled instead.

This method will keep being supported, but for new projects, we recommend that you use Session.setDesktopNotificationEnabled.

Sets desktop notification on or off. Has the same effect as toggling the "Desktop notification" toggle in the TalkJS Inbox UI. Use this function to replicate that toggle elsewhere in your UI if you're using TalkJS in a mode that doesn't show this toggle.

Deprecated.

Parameters

isEnabled
boolean

Returns

void