Subscribe to an event
Updated
sprChat('subscribeToUpdate')
This is our common notifier API which can be used to either receive proactive updates from the application about the current state or listen to the status of the previously fired SDK requests. For example, it can be used to listen to the success or failure notification of a “sendExternalEvent” SDK request. It can also notify when the chat changes its availability status (if availability conditions are specified in the builder causing the chat to change state dynamically).
Parameters:
(every parameter is optional unless marked *):
Name | Typescript type | Description | Default Value |
topic* | string | Update to listen to. Explanation of each topic can be found below in the examples. | - |
subscriber* |
| Callback that will be invoked when a matching update is available. Callback gets a “request” object only when this notifier is for the response of an SDK invocation. It contains all the params that were passed when making the SDK call. It also gets a “response” object containing “data” whose structure depends on the topic. You can find the structure for each topic in the examples below. “response” can also carry “error” which are pre-defined set of errors. You can find the error list below as well. | - |
Examples
Listens to live chat service availability (which can change on the basis of conditions defined in the builder)
function onAvailabilityChange({ response: { data: { isChatVisible } }}) { |
Listens to the unread notification count across all the conversations
function onUnreadCountChanged({ response: { data: { count } }}) { |
Listens to the external events triggered by bot/rule for the brand to handle where the type and externalParams have been defined in the bot/rule itself.
function onExternalEvent({ response: { data }}) { |
Listens to the load signal of live chat
function onLoadCompleted({ response: { error }}) { |
Listens to the telemetry/analytics events.
function onEventTriggered({ response: { data }}) { eventType: "CONVERSATION_WINDOW_OPENED"| "CONVERSATION_WINDOW_CLOSED"| "CONVERSATION_EXPORTED"| "CONVERSATION_DELETED"| "CONVERSATION_CLOSED"| "CONVERSATIONS_DELETED"| "CONVERSATIONS_CLOSED"| "NEW_CONVERSATION_CREATED"| "EXISTING_CONVERSATION_OPENED"| "TRIGGER_VISIBLE"| "BUTTON_CLICKED"| "AGENT_ASSIGNED"| "VIDEO_CALL_OUTGOING_STARTING"| "AUDIO_CALL_OUTGOING_STARTING"| "VIDEO_CALL_CARD_CTA_CLICKED"| "AUDIO_CALL_CARD_CTA_CLICKED"| "VIDEO_CALL_LAUNCH_CLICKED"| "AUDIO_CALL_LAUNCH_CLICKED"| "VIDEO_CALL_LAUNCHED"| "AUDIO_CALL_LAUNCHED"| "CONVERSATION_BACK_PRESSED"| "CONVERSATION_LIST_BACK_PRESSED"| "SURVEY_BACK_PRESSED"| "VIDEO_CALL_JOIN_CTA_CLICKED"| "VIDEO_CALL_JOIN_BACK_CTA_CLICKED"| "AUDIO_CALL_JOIN_CTA_CLICKED"| "AUDIO_CALL_JOIN_BACK_CTA_CLICKED"| "VIDEO_CALL_END_CLICKED"| "AUDIO_CALL_END_CLICKED"| "INFO_CARD_OPENED"| "INFO_CARD_CLOSED"| "USER_PROFILE_UPDATED"| "WIDGET_MAXIMIZED"| "WIDGET_MINIMIZED"| "PROACTIVE_PROMPT_TRIGGERED"| "PROACTIVE_PROMPT_ENGAGED"| "PROACTIVE_PROMPT_CLOSED"| "SEND_BUTTON_CLICKED"| "ATTACHMENT_BUTTON_CLICKED"| "PAGE_OPENED", additional?: { conversationId?: string } } |
Listens to see if the requested new conversation was created or not when window.sprChat(‘openNewConversation’) was fired.
const sdkPayload = { window.sprChat('openNewConversation', sdkPayload); function onNewConversation({ request, data?: { conversationId }, error?: 'LIMIT_REACHED' }) { // request is same as sdkPayload |
Listens to see if the message was published or not when window.sprChat(‘sendExternalEvent’) was fired.
const sdkPayload = { |