Session
Constructor | Creates a TalkJS Session. |
clearPushRegistrations | Unregisters all the mobile devices for the user. |
createChatbox | Creates a Chatbox UI. |
createInbox | Creates an Inbox UI |
createPopup | Creates a Popup UI. |
destroy | Disconnects all websockets, removes all UIs, and invalidates this session. |
getChatboxes | Returns a list of all active Chatbox objects linked to this session. |
getInboxes | Returns a list of all active Inbox objects linked to this session. |
getOrCreateConversation | A method used to either fetch or create a conversation. |
getPopups | Returns a list of all active Popup objects linked to this session. |
hasValidCredentials | Verifies whether the |
onDesktopNotificationClicked | Listen for when a user clicks a desktop notification. |
onMessage | Triggered when a message is sent in a conversation the current user is in. |
setDesktopNotificationEnabled | Sets desktop notification on or off. |
setPushRegistration | Registers a single mobile device, as one user can be connected to multiple mobile devices. |
syncThemeForLocalDev | Used to configure TalkJS to use a theme hosted on the same location as your application for development. |
unsetPushRegistration | Unregisters a single mobile device, as one user can be connected to multiple mobile devices. |
getOrStartConversation Deprecated | |
off Deprecated | Used to stop listening to specific TalkJS session events. |
on Deprecated | Listens for an event |
registerDevice Deprecated | |
unregisterDevice Deprecated |
Your TalkJS AppId
that can be found your TalkJS dashboard.
unreads
: UnreadsHolds information about unread conversations. Lets your app be notified when the active user receives a new message.
new Session(options)
Parameters
options
: SessionOptionsinterface SessionOptions
me
: UserA User
object that identifies the currently active user. The user is uniquely identified by their id; all other fields (name, photo, etc) are overwritten in the TalkJS database each time they change, unless the user has been created with the alternate constructor.
If you use Identity verification make sure you generate and use a signature.
session.clearPushRegistrations(): Promise<void>
Related methods: setPushRegistration unsetPushRegistration
Note that you must ensure that the user exists in the TalkJS database before you call this method. The simplest way to do that is to call it after you mount a chatbox, inbox or popup.
Parameters
Returns
session.createChatbox(options): Chatbox
The Chatbox is a slimmer version of the Inbox. It shows a single conversation, without means to switch between conversations. In order to select a conversation inside a Chatbox you need to call Chatbox.select.
Example:
const chatbox = session.createChatbox();chatbox.select(conversation);
You typically want to call Chatbox.mount after creating the Chatbox to make it visible on your app.
Call createChatbox
on any page you want to show a chatbox of a single conversation.
Note: A deprecated two-parameter form of this method, createChatbox(selectedConversation, options)
, also exists. This form will keep being supported but we recommend not using it new codebases. Instead, call Chatbox.select immediately after mount
.
Parameters
options (optional)
: ChatboxOptionsOptional, Use these to finetune the behavior of the Chatbox.
interface ChatboxOptions
Enables capturing Chatbox.onKeyup events.
Note: Setting this to true also disables any non-standard keyboard shortcuts in TalkJS.
At the time of writing, the only such shortcut is that when captureKeyboardEvents
is disabled, TalkJS will auto-focus the message field if the user starts typing but no input field is focused.
Controls the text direction (for supporting right-to-left languages such as Arabic and Hebrew). TalkJS tries to determine the appropriate text direction from the parent page, but if that does not work or you want to explicitly control it, you can override it here. Defaults to "rtl".
messageField (optional)
: MessageFieldOptionsSettings that affect the behavior of the message field
messageFilter (optional)
: MessagePredicateUsed to control which messages are shown in the message list, depending on a type, origin or custom message attributes.
*Note*: Messages are only filtered in the message list. The inbox UI's conversation feed will always show the last message sent to the conversation, regardless of the message filter set.
See MessagePredicate for all available options.
You can also modify the filter on the fly using Chatbox.setMessageFilter.
presence (optional)
: UserPresenceSets metadata for the current session.
- visible
manually sets the information about the visibility of TalkJS. This is useful when TalkJS is hidden with CSS. TalkJS will assume that UIs marked visible: false
cannot be seen, and thus messages arriving on this UI will not be marked as read until you set visible
to true again.
- custom
is an additional parameter to store the custom fields, that you may want to use in the REST API call.
Used to control if the Chat Header is displayed in the UI. Defaults to true.
Set this to true
to show a translation toggle in all conversations. Set this to "auto"
to show a translation toggle in conversations where there are participants with different locales. This setting defaults to false
, meaning that no toggles will be shown. In order to use this, you must be on the Growth plan, and set a Google Translate API key in the dashboard.
Overrides the theme used for this chat UI.
This only works with themes created in the Theme Editor.
If you omit this field, the UI uses the theme that is selected in the current user's role.
thirdparties (optional)
: ThirdPartyOptionsTalkJS leverages iframe
s behind the scenes and therefore not all services that you use in your app will work out of the box. This option adds support for a number of services to help you use them. Let us know if you're missing any.
translateConversations (optional)
: boolean | "auto" | string[] | ConversationBuilder[]TalkJS can translate conversations to the current user's locale using Google Translate. This option specifies which conversations should be translated in this UI. You can pass a boolean to enable/disable translation for all conversations, "auto" to enable translation on conversations where users have different locales, or you can pass an array of ConversationBuilders or conversation Ids to be translated. This feature is only available on the Growth plan and above. Make sure you add your Google Translate API key in the dashboard.
Controls what text appears in the chat subtitle, right below the chat title. No subtitle is displayed when the conversation has no subject set or when set to null
. Defaults to "subject"
.
(also see chatTitleMode and InboxOptions.feedConversationTitleMode)
Deprecated.
This field only has effect if you use a Legacy Theme, or an older custom theme which does not have a ChatHeader component. If you do not, edit the ChatHeader component in the theme editor instead.
Controls what text appears in the chat title, in the header above the messages. Defaults to "participants"
.
(also see chatSubtitleMode and InboxOptions.feedConversationTitleMode)
Deprecated.
This field only has effect if you use a Legacy Theme, or an older custom theme which does not have a ChatHeader component. If you do not, edit the ChatHeader component in the theme editor instead.
Sets the message input box to the given text. You can use this to suggest a certain initial message to be sent. The user can still edit it before hitting "send".
Deprecated.
We recommend using MessageField.setText before mounting the chatbox to precisely control when message suggestions are shown.
Returns
session.createInbox(options): Inbox
The Inbox is TalkJS's most versatile component. It combines a Chatbox with a panel showing a a list of conversations where the user is a participant. After creating an Inbox, you need to Inbox.mount it to make it visible in your app.
Call createInbox
on the messaging page of your app.
Parameters
options (optional)
: InboxOptionsOptional. Use these to finetune the behavior of the Inbox.
interface InboxOptions
Enables capturing Chatbox.onKeyup events.
Note: Setting this to true also disables any non-standard keyboard shortcuts in TalkJS.
At the time of writing, the only such shortcut is that when captureKeyboardEvents
is disabled, TalkJS will auto-focus the message field if the user starts typing but no input field is focused.
Controls the text direction (for supporting right-to-left languages such as Arabic and Hebrew). TalkJS tries to determine the appropriate text direction from the parent page, but if that does not work or you want to explicitly control it, you can override it here. Defaults to "rtl".
feedFilter (optional)
: ConversationPredicateUsed to control which conversations are shown in the conversation feed, depending on access level, custom conversation attributes or message read status.
See ConversationPredicate for all available options.
You can also modify the filter on the fly using Inbox.setFeedFilter.
messageField (optional)
: MessageFieldOptionsSettings that affect the behavior of the message field
messageFilter (optional)
: MessagePredicateUsed to control which messages are shown in the message list, depending on a type, origin or custom message attributes.
*Note*: Messages are only filtered in the message list. The inbox UI's conversation feed will always show the last message sent to the conversation, regardless of the message filter set.
See MessagePredicate for all available options.
You can also modify the filter on the fly using Inbox.setMessageFilter.
presence (optional)
: UserPresenceSets metadata for the current session.
- visible
manually sets the information about the visibility of TalkJS. This is useful when TalkJS is hidden with CSS. TalkJS will assume that UIs marked visible: false
cannot be seen, and thus messages arriving on this UI will not be marked as read until you set visible
to true again.
- custom
is an additional parameter to store the custom fields, that you may want to use in the REST API call.
selected (optional)
: Conversation | ConversationBuilder | string | nullMakes the inbox start up with the given Conversation. Can be passed a value of the type ConversationBuilder (returned by getOrCreateConversation) or the string value of the conversation id. Conversation can be deselected on startup by passing a null value. Passing undefined means that the last conversation (or "no chats yet page") will be displayed.
Used to control if the Chat Header is displayed in the UI. Defaults to true.
Controls if the feed header containing the toggle to enable desktop notifications is shown. Defaults to true.
Whether to show a "Back" button at the top of the chat screen on mobile devices.
Set this to true
to show a translation toggle in all conversations. Set this to "auto"
to show a translation toggle in conversations where there are participants with different locales. This setting defaults to false
, meaning that no toggles will be shown. In order to use this, you must be on the Growth plan, and set a Google Translate API key in the dashboard.
Overrides the theme used for this chat UI.
This only works with themes created in the Theme Editor.
If you omit this field, the UI uses the theme that is selected in the current user's role.
thirdparties (optional)
: ThirdPartyOptionsTalkJS leverages iframe
s behind the scenes and therefore not all services that you use in your app will work out of the box. This option adds support for a number of services to help you use them. Let us know if you're missing any.
translateConversations (optional)
: boolean | "auto" | string[] | ConversationBuilder[]TalkJS can translate conversations to the current user's locale using Google Translate. This option specifies which conversations should be translated in this UI. You can pass a boolean to enable/disable translation for all conversations, "auto" to enable translation on conversations where users have different locales, or you can pass an array of ConversationBuilders or conversation Ids to be translated. This feature is only available on the Growth plan and above. Make sure you add your Google Translate API key in the dashboard.
Controls whether the user navigating between conversation should count as steps in the browser history. Defaults to true, which means that if the user clicks the browser's back button, they go back to the previous conversation (if any).
Controls what text appears in the chat subtitle, right below the chat title. No subtitle is displayed when the conversation has no subject set or when set to null
. Defaults to "subject"
.
(also see chatTitleMode and feedConversationTitleMode)
Deprecated.
This field only has effect if you use a Legacy Theme, or an older custom theme which does not have a ChatHeader component. If you do not, edit the ChatHeader component in the theme editor instead.
Controls what text appears in the chat title, in the header above the messages. Defaults to "participants"
.
(also see chatSubtitleMode and feedConversationTitleMode)
Deprecated.
This field only has effect if you use a Legacy Theme, or an older custom theme which does not have a ChatHeader component. If you do not, edit the ChatHeader component in the theme editor instead.
Controls how a chat is displayed in the feed of chats.
Note: when set to "subject"
but a conversation has no subject set, then TalkJS falls back to "participants"
.
When not set, defaults to "auto"
, which means that in group conversations that have a subject set, the subject is displayed and otherwise the participants.
(also see chatSubtitleMode and chatTitleMode)
Deprecated.
This field only has effect if you use a Legacy Theme, or an older custom theme which does not have a ConversationListItem component. If you do not, edit the ChatHeader component in the theme editor instead.
Sets the message input box to the given text. You can use this to suggest a certain initial message to be sent. The user can still edit it before hitting "send".
Deprecated.
We recommend using MessageField.setText before mounting the chatbox to precisely control when message suggestions are shown.
Returns
session.createPopup(options): Popup
The Popup is a positioned box containing a conversation. It shows a single conversation, without means to switch between conversations. In order to select a conversation inside a Popup you need to call the Popup.select.
Example:
const popup = session.createPopup();popup.select(conversation);
You typically want to call Popup.mount after creating the popup to make it visible on your app.
Call createPopup
on any page you want to show a popup of a single conversation.
Note: A deprecated two-parameter form of this method, createChatbox(selectedConversation, options)
, also exists. This form will keep being supported but we recommend not using it new codebases. Instead, call Chatbox.select immediately after mount
. In order to have a popup on each site you need to call createPopup
on any page you want to show a popup with the conversation.
Parameters
options (optional)
: PopupOptionsOptional, Use these to finetune the behavior of the Popup.
interface PopupOptions
Enables capturing Chatbox.onKeyup events.
Note: Setting this to true also disables any non-standard keyboard shortcuts in TalkJS.
At the time of writing, the only such shortcut is that when captureKeyboardEvents
is disabled, TalkJS will auto-focus the message field if the user starts typing but no input field is focused.
Controls the text direction (for supporting right-to-left languages such as Arabic and Hebrew). TalkJS tries to determine the appropriate text direction from the parent page, but if that does not work or you want to explicitly control it, you can override it here. Defaults to "rtl".
If enabled, the Popup will reopen every time the user navigates to another page. This way, a conversation can continue while the user browses around. Set to false
to disable this behavior.
Defaults to false.
Specifies whether to show a round launcher and/or close button beneath the popup in the right bottom corner of the page.
"close-only"
: show a close button beneath the popup, but don't show a launch button
"always"
: show a launch button when the popup is closed, show a close button when it is visible
"never"
: never show a launcher
Note: if you choose "never"
you may want to override the positioning of the popup as well. Just tune the __talkjs_popup
class in your CSS.
Ignored on mobile, where the popup fills the entire screen so the value is effectively "never"
.
Defaults to "always"
.
messageField (optional)
: MessageFieldOptionsSettings that affect the behavior of the message field
messageFilter (optional)
: MessagePredicateUsed to control which messages are shown in the message list, depending on a type, origin or custom message attributes.
*Note*: Messages are only filtered in the message list. The inbox UI's conversation feed will always show the last message sent to the conversation, regardless of the message filter set.
See MessagePredicate for all available options.
You can also modify the filter on the fly using Popup.setMessageFilter.
presence (optional)
: UserPresenceSets metadata for the current session.
- visible
manually sets the information about the visibility of TalkJS. This is useful when TalkJS is hidden with CSS. TalkJS will assume that UIs marked visible: false
cannot be seen, and thus messages arriving on this UI will not be marked as read until you set visible
to true again.
- custom
is an additional parameter to store the custom fields, that you may want to use in the REST API call.
Used to control if the Chat Header is displayed in the UI. Defaults to true.
Whether to show the "x" icon in the popup header to close the popup. "auto", which is the default value means true
on mobile and to false
on desktop.
Set this to true
to show a translation toggle in all conversations. Set this to "auto"
to show a translation toggle in conversations where there are participants with different locales. This setting defaults to false
, meaning that no toggles will be shown. In order to use this, you must be on the Growth plan, and set a Google Translate API key in the dashboard.
Overrides the theme used for this chat UI.
This only works with themes created in the Theme Editor.
If you omit this field, the UI uses the theme that is selected in the current user's role.
thirdparties (optional)
: ThirdPartyOptionsTalkJS leverages iframe
s behind the scenes and therefore not all services that you use in your app will work out of the box. This option adds support for a number of services to help you use them. Let us know if you're missing any.
translateConversations (optional)
: boolean | "auto" | string[] | ConversationBuilder[]TalkJS can translate conversations to the current user's locale using Google Translate. This option specifies which conversations should be translated in this UI. You can pass a boolean to enable/disable translation for all conversations, "auto" to enable translation on conversations where users have different locales, or you can pass an array of ConversationBuilders or conversation Ids to be translated. This feature is only available on the Growth plan and above. Make sure you add your Google Translate API key in the dashboard.
Controls what text appears in the chat subtitle, right below the chat title. No subtitle is displayed when the conversation has no subject set or when set to null
. Defaults to "subject"
.
(also see chatTitleMode and InboxOptions.feedConversationTitleMode)
Deprecated.
This field only has effect if you use a Legacy Theme, or an older custom theme which does not have a ChatHeader component. If you do not, edit the ChatHeader component in the theme editor instead.
Controls what text appears in the chat title, in the header above the messages. Defaults to "participants"
.
(also see chatSubtitleMode and InboxOptions.feedConversationTitleMode)
Deprecated.
This field only has effect if you use a Legacy Theme, or an older custom theme which does not have a ChatHeader component. If you do not, edit the ChatHeader component in the theme editor instead.
Sets the message input box to the given text. You can use this to suggest a certain initial message to be sent. The user can still edit it before hitting "send".
Deprecated.
We recommend using MessageField.setText before mounting the chatbox to precisely control when message suggestions are shown.
Returns
session.destroy()
You cannot use any objects that were created in this session after you destroy it.
If you want to use TalkJS after having called destroy()
you must instantiate a new Talk.Session instance.
Parameters
Returns
session.getChatboxes(): Chatbox[]
Only includes chatboxes that are still mounted in the DOM. So if you call createChatbox()
but later remove its container element (or an ancestor of the container), then the Chatbox
object will have been made invalid and is therefore not included in the results.
Parameters
Returns
session.getInboxes(): Inbox[]
Only includes inboxes that are still mounted in the DOM. So if you call createInbox()
but later remove its container element (or an ancestor of the container), then the Inbox
object will have been made invalid and is therefore not included in the results.
Parameters
Returns
session.getOrCreateConversation(conversationId): ConversationBuilder
Returns a ConversationBuilder
object that encapsulates a conversation between me
(given in the constructor) and zero or more other participants
. Use ConversationBuilder.setParticipant and ConversationBuilder.setAttributes on the returned object to further set up your conversation.
Parameters
conversationId
: stringA unique identifier for this conversation, such as a channel name or topic ID. Any user with access to this ID can join this conversation. Read about how to choose a good conversation ID for your use case. If you want to make a simple one-on-one conversation, consider using oneOnOneId to generate one.
Returns
session.getPopups(): Popup[]
Includes popups actively created using createPopup, and also popups created on page load, if PopupOptions.keepOpen was set to true
on an earlier page.
Only includes popups that are still mounted in the DOM. So if you call createPopup()
but later remove its container element (or an ancestor of the container), then the Popup
object will have been made invalid and is therefore not included in the results.
Parameters
Returns
session.hasValidCredentials(): Promise<boolean>
appId
is valid.Returns a Promise of a boolean, never rejects.
Parameters
Returns
session.onDesktopNotificationClicked(handler): Subscription
A "desktopNotificationClicked"
event is fired every time a user clicks on a desktop notification generated by TalkJS.
When a user clicks on a notification, these things will happen:
1. The browser tab will be selected (note, this works in most browsers but cannot be guaranteed);
2. If you provided one or more "desktopNotificationClicked" handlers, they will be invoked in order;
3. If you did not, then the currently active inbox (if any) will jump to the conversation corresponding to the notification.
See also setDesktopNotificationEnabled
Parameters
handler
: (message: Message) => voidReturns
session.onMessage(handler): Subscription
A "message"
event is fired every time a message is sent or received by the current user (even if no TalkJS UI is visible). Your handler
function is passed a Message object with some information about each message and its conversation.
Note that this event does not get triggered for conversations where the current user is a guest. It only applies to users who were added as participants.
Parameters
handler
: (message: Message) => voidReturns
session.setDesktopNotificationEnabled(isEnabled, { alertOnFailure }): Promise<void>
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.
When desktop notifications are enabled for the first time, the browser will show a prompt to ask the user for permission. The call will only succeed if the user accepts it.
We recommend only calling this function in response to user action, so users know that they can expect a permission prompt. This significantly increases the percentage of users that click "Allow".
Notably, we strongly recommend that you do not call this function immediately when the page loads, because many browsers auto block notifications when permission is requested on page load. This is likely a measure to prevent overly aggressive news sites from being able to spam past visitors.
Parameters
isEnabled
: booleanWhether notifications should be enabled.
{ alertOnFailure } (optional)
: { alertOnFailure?: boolean }Returns
a promise that'll resolve if the change succeeds, but rejects if anything goes wrong. If anything goes wrong, the promise will be rejected with a TalkError, which has a code
property. Possible values for it are:
- Talk.ErrorCode.NOTIFICATIONS_PERMISSION_DENIED
: The browser or the user didn't grant you permission to send notifications.
- Talk.ErrorCode.NOTIFICATIONS_NOT_SUPPORTED
: The browser doesn't support desktop notifications.
session.setPushRegistration({provider: "fcm" | "apns";pushRegistrationId: string;}): Promise<void>
Related methods: unsetPushRegistration clearPushRegistrations
Note that you must ensure that the user exists in the TalkJS database before you call this method. The simplest way to do that is to call it after you mount a chatbox, inbox or popup.
Parameters
{ provider, pushRegistrationId, }
: { provider: "fcm" | "apns" pushRegistrationId: string }Returns
session.syncThemeForLocalDev(path)
Tells TalkJS to use a theme hosted on the same location as your application (e.g. localhost:8000/). e.g. Call talkSession.syncThemeForLocalDev("/assets/css/talkjs-theme.css")
just before you call createInbox
or createChatbox
. TalkJS will then use the specified file instead of using a theme created in the dashboard.
Parameters
path
: stringThe path to the theme's CSS file
Returns
session.unsetPushRegistration({provider: "fcm" | "apns";pushRegistrationId: string;}): Promise<void>
Related methods: setPushRegistration clearPushRegistrations
Note that you must ensure that the user exists in the TalkJS database before you call this method. The simplest way to do that is to call it after you mount a chatbox, inbox or popup.
Parameters
{ provider, pushRegistrationId, }
: { provider: "fcm" | "apns" pushRegistrationId: string }Returns
The following methods remain supported for backward compatibility reasons. In new projects, we recommend that you use the suggested alternatives instead.
getOrStartConversation Deprecated | |
off Deprecated | Used to stop listening to specific TalkJS session events. |
on Deprecated | Listens for an event |
registerDevice Deprecated | |
unregisterDevice Deprecated |
session.getOrStartConversation(other, options): Conversation
Deprecated. This method will keep being supported, but for new projects, we recommend that you use getOrCreateConversation. Returns a Conversation
object that encapsulates a conversation between me
(given in the constructor) and other
.
Parameters
other
: UserA User
object that identifies the person to converse with. The user is uniquely identified by their id; all other fields (name, photo etc) are overwritten in the TalkJS database each time they change.
options (optional)
: GetOrStartOptionsAOptions used for getOrStartConversation
interface GetOrStartOptionsA
Additional parameter to store the custom fields, that you want to use in the email template. E.g. custom.specialToken
Only used if topicId
is given: a human-readable subject of the conversation. Supports formatted links in a Markdown-style syntax, e.g. Beautiful <https://yoursite.com/booking/18644|home by the sea>!
. URLs and email addresses are made clickable, and emojis made to work cross-platform.
Returns
session.getOrStartConversation(conversationId, options): Conversation
Deprecated. This method will keep being supported, but for new projects, we recommend that you use getOrCreateConversation. Returns a Conversation
object that encapsulates a conversation between me
(given in the constructor) and zero or more other participants
.
Parameters
conversationId
: stringA unique identifier for this conversation. Any user with access to this ID can join this conversation.
options (optional)
: GetOrStartOptionsBOptions used for getOrStartConversation
interface GetOrStartOptionsB
Additional parameter to store the custom fields, that you want to use in the email template. E.g. custom.specialToken
participants
: Array<User>Only used if topicId
is given: a human-readable subject of the conversation. Supports formatted links in a Markdown-style syntax, e.g. Beautiful <https://yoursite.com/booking/18644|home by the sea>!
. URLs and email addresses are made clickable, and emojis made to work cross-platform.
Returns
session.off("message", handler)
Call this with the same eventType
and handler
to stop receiving events.
Deprecated. Please use the Subscription.unsubscribe method on the object returned by onMessage instead.
Parameters
eventType
: "message"handler
: (message: Message) => voidReturns
session.off("desktopNotificationClicked", handler)
Call this with the same eventType
and handler
to stop receiving events.
Deprecated. Please use the Subscription.unsubscribe method on the object returned by onDesktopNotificationClicked instead.
Parameters
eventType
: "desktopNotificationClicked"handler
: (event: DesktopNotificationClickedEvent) => voidReturns
session.on("message", handler)
A "message"
event is fired every time a message is sent or received by the current user (even if no TalkJS UI is visible). Your handler
function is passed a Message object with some information about each message and its conversation.
Note that this event does not get triggered for conversations where the current user is a guest. It only applies to users who were added as participants.
Related method: off
Deprecated. Please use onMessage instead.
Parameters
eventType
: "message"handler
: (message: Message) => voidReturns
session.on("desktopNotificationClicked", handler)
A "desktopNotificationClicked"
event is fired every time a user clicks on a desktop notification generated by TalkJS.
When a user clicks on a notification, these things will happen:
1. The browser tab will be selected (note, this works in most browsers but cannot be guaranteed);
2. If you provided one or more "desktopNotificationClicked" handlers, they will be invoked in order;
3. If you did not, then the currently active inbox (if any) will jump to the conversation corresponding to the notification.
See also setDesktopNotificationEnabled and off
Deprecated. Please use onDesktopNotificationClicked instead.
Parameters
eventType
: "desktopNotificationClicked"handler
: (event: DesktopNotificationClickedEvent) => voidReturns
session.registerDevice({platform: "ios" | "android";pushRegistrationId: string;}): Promise<void>
Related method: Session.unregisterDevice
Note that you must ensure that the user exists in the TalkJS database before you call this method. The simplest way to do that is to call it after you mount a chatbox, inbox or popup.
Deprecated. This method will keep being supported, but for new projects, we recommend that you use setPushRegistration. Registers mobile device, one user can be connected to one mobile device.
Parameters
{ platform, pushRegistrationId, }
: { platform: "ios" | "android" pushRegistrationId: string }Returns
session.unregisterDevice(): Promise<void>
Related method: Session.registerDevice
Deprecated. This method will keep being supported, but for new projects, we recommend that you use unsetPushRegistration or clearPushRegistrations. Unregisters mobile device, one user can be connected to one mobile device.
Parameters
Returns
onChange | Triggered when the list of unread conversations changes. |
off Deprecated | Call this with the same |
on Deprecated | A "change" event is fired on startup right after TalkJS loads, as well as every time the amount of unread conversations changed. The |
unreads.onChange(handler): Subscription
A "change" event is fired on startup right after TalkJS loads, as well as every time the amount of unread conversations changed. The handler
is invoked with an array of objects with limited information about each conversation, see UnreadConversation.
Note that conversations where the user is a guest do not keep track of unread messages. This is only done for users who are added as participants.
Parameters
handler
: (messages: UnreadConversation[]) => voidReturns
The following methods remain supported for backward compatibility reasons. In new projects, we recommend that you use the suggested alternatives instead.
off Deprecated | Call this with the same |
on Deprecated | A "change" event is fired on startup right after TalkJS loads, as well as every time the amount of unread conversations changed. The |
unreads.off("change", handler)
eventType
and handler
that you used for on
to stop receiving events.Related methods: on
Deprecated. Please use the Subscription.unsubscribe method on the object returned by onChange instead.
Parameters
eventType
: "change"handler
: (messages: UnreadConversation[]) => voidReturns
unreads.on("change", handler)
handler
is invoked with an array of objects with limited information about each conversation, see UnreadConversation.Note that conversations where the user is a guest do not keep track of unread messages. This is only done for users who are added as participants.
Related methods: off
Deprecated. Please use onChange instead.
Parameters
eventType
: "change"handler
: (messages: UnreadConversation[]) => voidReturns
lastMessage
: MessageContains the last Message for an unread conversation.
interface Message
Only given if the message's type
equals "media"
. An object with the URL and filesize (in bytes) of the given file.
conversation
: ConversationDataContains the ConversationData that the message belongs to.
custom
: CustomDataCustom metadata that is stored with the conversation
Only given if the message's type
equals "location"
. An array of two numbers which represent the longitude and latitude of this location, respectively. Only given if this message is a shared location.
Example:
[51.481083, -3.178306]
Determines how this message was sent: respectively, Via a web browser (or mobile Webview), via the REST API, via reply-to-email, or using the import API.
Only given if the message's type
equals "media"
. An object with the URL and filesize (in bytes) of the given file.
conversation
: ConversationDataContains the ConversationData that the message belongs to.
interface ConversationData
custom
: CustomDataContains custom metadata for the conversation if it was set using ConversationBuilder.custom.
Contains the URL of a photo was set using ConversationBuilder.subject.
Contains the conversation subject if it was set using ConversationBuilder.subject.
One or more welcome messages that will display to the user as a SystemMessage
custom
: CustomDataCustom metadata that is stored with the conversation
interface CustomData
Any number of key/value pairs of your choosing to be stored along with the associated resource. You can use custom data for all kinds of purposes, such as customizing a user's email notification text, transmitting contextual user data, or making email login tokens.
Both the key and the value must be strings; arbitrarily deeply nested JSON is not supported. Example:
{"country":"nl", "itemId": "720"}
Only given if the message's type
equals "location"
. An array of two numbers which represent the longitude and latitude of this location, respectively. Only given if this message is a shared location.
Example:
[51.481083, -3.178306]
Determines how this message was sent: respectively, Via a web browser (or mobile Webview), via the REST API, via reply-to-email, or using the import API.
Specifies if if the message is media (file), text or a shared location