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 in its initial state, for example, 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.

To call this API, 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.