Add the #DF24 Developer Keynote to your agenda. Join us in-person on 9/18 at 2:30 p.m. PT or on Salesforce+ at 5 p.m. PT for the must-see session built just for developers.

Event Listeners

Set up notifications when certain Messaging for In-App and Web events are triggered. Use window.addEventListener to register a handler for a standard client event.

Event NameEvent DetailsScenario
onEmbeddedMessagingReady{}Fires when the Salesforce JavaScript API for Messaging is ready to use. At this point, you can make calls such as userVerificationAPI.setIdentityToken and setHiddenPrechatFields. To let you know that the API is ready for calls, this method is called in the following situations.
  • Whenever a new page with the web client is loaded.
  • For anonymous conversations: after the conversation has ended and the user closes the chat window.
onEmbeddedMessagingButtonClicked{}Fires the first time the chat button is clicked by the end user.
onEmbeddedMessagingWindowMaximized{}Fires when the messaging conversation window is maximized.
onEmbeddedMessagingWindowMinimized{}Fires when the messaging conversation window is minimized.
onEmbeddedMessagingConversationCreated{conversationId: "id"}Fires when a messaging conversation starts. This event only applies to the browser tab where the conversation was created.
onEmbeddedMessagingConversationOpened{}Fires when a messaging conversation is loaded into a browser tab, whether it moved to a new browser tab or was loaded in the browser tab where the conversation started.
onEmbeddedMessagingConversationRouted{ SSE PAYLOAD }Fires when a messaging conversation is routed or manually transferred from one internal recipient to another, such as from a bot to an agent. This event also fires if the routing or manual transfer is unsuccessful.
onEmbeddedMessagingConversationParticipantChanged{ SSE PAYLOAD }Fires when a new internal user, such as a bot or an agent, joins a conversation. Or, when an existing internal user leaves a conversation.
onEmbeddedMessagingPreChatLoaded{prechatDisplay:"Conversation"/"Session"}Fires when the pre-chat form is displayed to the end user.
onEmbeddedMessagingPreChatSubmitted{prechatDisplay:"Conversation"/"Session"}Fires when the end user submits the pre-chat form.
onEmbeddedMessageSent{ SSE PAYLOAD }Fires when an agent, a bot, or an end user sends a message. The message can be typed manually or sent in the form of a messaging component. This event also fires when an end user clicks on a messaging component, resulting in a second messaging component being sent.
onEmbeddedMessageDelivered{ SSE PAYLOAD }Fires when an end user receives a delivery receipt. Delivery receipts must be enabled in Setup.
onEmbeddedMessageRead{ SSE PAYLOAD }Fires when an end user receives a read receipt. Read receipts must be enabled in Setup.
onEmbeddedMessagingTranscriptRequested{ conversationId: "id" }Fires when an end user requests a transcript of their messaging conversation history.
onEmbeddedMessagingTranscriptRequestFailed{ conversationId: "id" }Fires when the transcript request fails.
onEmbeddedMessagingTranscriptDownloadSuccessful{ conversationId: "id"}Fires when the messaging conversation transcript is successfully downloaded.
onEmbeddedMessagingConversationClosed{ SSE PAYLOAD }Fires when an end user closes the messaging conversation.
onEmbeddedMessagingIdentityTokenExpired{}The client dispatches the onEmbeddedMessagingIdentityTokenExpired event when you interact with the client after both the Salesforce authorization token and identity token have expired. If the Salesforce authorization token expires, but the identity token is still valid, the client generates a new Salesforce authorization token and keeps the session active without sending the onEmbeddedMessagingIdentityTokenExpired event. If you want to continue the session but the identity token has expired, you can renew the token and send it to the client using the setIdentityToken method in the event handler. The messaging session and user data are cleared automatically if you don't respond within 30 seconds of the onEmbeddedMessagingIdentityTokenExpired event being dispatched. If you want to clear the session before the 30 seconds have expired explicitly, you can call the clearSession method.

Learn more about server-sent event (SSE) payloads in Server-Sent Events.

The following code is an example of how these events can be used in your Messaging for Web code snippet.