Popup
Thursday, January 28, 2021 1:51 AMinterface 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.Methods
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 by the user. |
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 by the user. |
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. |
setHighlightedWords | The TalkJS search feature includes the ability to highlight certain words in messages. Call this method to highlight certain words without having the user invoke the search feature. Call again with an empty array to disable highlighting. Note: like the search feature, this option only works in TalkJS Premium and up. Also see ChatboxOptions.highlightedWords |
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 |
toggleDesktopNotifications | Deprecated. Please use Session.setDesktopNotificationEnabled instead. |
Properties
messageField | Encapsulates the message entry field tied to the currently selected conversation. |
Method Details
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
|
Returns
Promise<HtmlPanel>destroy
popup.destroy()
Destroys the Popup
Call this before removing the Popup container from the DOM.
Parameters
Returns
voidhide
popup.hide()
Closes the Popup, but doesn't remove it from the DOM
Parameters
Returns
voidmount
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 |
Returns
voidpopup.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 |
Returns
voidpopup.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 |
Returns
voidpopup.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 |
Returns
voidpopup.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 |
Returns
voidpopup.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 |
Returns
voidon("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
voidon("close")
popup.on(eventType, handler)
Triggers when the popup is closed by the user.
Only gets triggered when the user performs an action to close the popup, eg when they click the "X" on the launcher or, if enabled, in the popup header. This event is not triggered when you call hide or destroy.
Parameters
eventType"close" | |
handler(event: CloseEvent) => void |
Returns
voidon("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
voidon("open")
popup.on(eventType, handler)
Triggers when the popup is opened by the user.
Only gets triggered when the user performs an action to open the popup. This event is not triggered when you call show or when you mount it with the {show: true}
option.
Parameters
eventType"open" | |
handler(event: OpenEvent) => void |
Returns
voidon("sendMessage")
popup.on(eventType, handler)
Triggers when the user sends a message using the TalkJS UI
Parameters
eventType"sendMessage" | |
handler(event: SendMessageEvent) => void |
Returns
voidon("translationTriggered")
popup.on(eventType, handler)
Triggers when the user toggles translation in a conversation
Parameters
eventType"translationToggled" | |
handler(event: TranslationToggledEvent) => void |
Returns
voidselect
popup.select(conversation)
Switches the active conversation the conversation.
conversation
can be either a ConversationBuilder object or a TalkJS conversation id. Passing null
means that the conversation will be de-selected in the UI and the message list will disappear. Passing undefined
means that the last conversation (or "no chats yet" page if there are no other conversations) will be rendered in the message list component.
Parameters
conversationstring
| Conversation
| ConversationBuilder
| null
| undefined |
Returns
voidsetHighlightedWords
popup.setHighlightedWords(words)
The TalkJS search feature includes the ability to highlight certain words in messages. Call this method to highlight certain words without having the user invoke the search feature. Call again with an empty array to disable highlighting. Note: like the search feature, this option only works in TalkJS Premium and up. Also see ChatboxOptions.highlightedWords
Parameters
wordsstring[] |
Returns
voidsetMessageFilter
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
|
Returns
voidsetPresence
popup.setPresence({ visible, custom })
Sets metadata for the current session.
Parameters
{ visible, custom }{
visible?: boolean
custom?: {
[key: string]: string
}
} |
Returns
voidsetTranslationEnabledDefault
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
enabledboolean | "auto" | Whether conversations should be translated by default or not. Pass "auto" to enable translation for conversations with users with different locales. |
Returns
voidsetTranslationEnabledForConversation
popup.setTranslationEnabledForConversation(conversation, enabled)
Enable or disable translation for a conversation.
Parameters
conversationstring | ConversationBuilder | The conversation for which this hsould be be set. If not specified, the setting will be applied to the currently selected conversation. |
enabledboolean | Whether translation should be enabled |
Returns
voidshow
popup.show()
Shows the Popup, previously hidden or mounted with a parameter
show: false
Parameters
Returns
voidtoggleDesktopNotifications
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
isEnabledboolean |