Launch Chat in Messaging for Web
Call Launch Chat API to programmatically launch the web chat client, which loads all the necessary dependencies and bootstraps. The API is a JavaScript API for the Messaging for Web client. You can replace the default chat button with a custom chat button or your own web experience that calls the Launch Chat API to launch the chat client.
When Launch Chat API launches the chat client, the client opens as a maximized window in its initial state. For example, the client opens as a pre-chat dialog if prechat is configured in setup or a chat state otherwise. The initial state depends on how you configured the messaging deployment. If you minimized the window and called the API again, the API again maximizes the messaging conversation window.
To call this API, add an event listener for the onEmbeddedMessagingReady
event and use the utilAPI.launchChat()
method. Here’s an example code for a Messaging for Web client. To find out how to get to the Code Snippet page that contains the code to initialize the Messaging for Web client, see Introduction.
Use the event handlers in the utilAPI.launchChat()
method to perform actions after the chat launches.
then
event handler—If the client launches successfully, you can use this handler to, for example, hide the chat invitation or custom button.catch
event handler—If there’s an error launching the client, you can use this handler to, for example, display an error message.finally
event handler—The method runs this handler after the client launches successfully or not. Use this handler to run any clean-up actions.
For more details, see the Messaging for Web reference documentation.