Event Listeners

These events can be accessed from the addEventListener method for the window.

This event is dispatched when the Salesforce JavaScript API for Messaging is ready to use. At this point, you can make calls such as 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 user-verified conversations: after the user logs out (userVerificationAPI.clearSession is called) and the API is ready for another conversation.
  • For anonymous conversations: after the conversation has ended and the user closes the chat window.

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.