utilAPI

This object contains utility-related APIs.

hideChatButton 

This method hides the chat button.

By default, the chat button is always shown if no business hours are specified. If business hours are specified, the chat button is shown during business hours and hidden outside of business hours. To learn how to configure business hours, see Set Business Hours in Enhanced Chat.

This command can override the default behavior.

You can’t hide the chat button if the chat window is already showing. Also, this method doesn’t have session continuity. For example, after a refresh, the button returns to its initial state. If business hours are specified, this call overrides the current visibility only until the next business hours interval.

Note

Parameters 

None.

Example 

1embeddedservice_bootstrap.utilAPI.hideChatButton();

showChatButton 

This method shows the chat button.

By default, the chat button is always shown if no business hours are specified. If business hours are specified, the chat button is shown during business hours and hidden outside of business hours. To learn how to configure business hours, see Set Business Hours in Enhanced Chat.

This command can override the default behavior.

This method doesn’t have session continuity. For example, after a refresh, the button returns to its initial state. Also, if business hours are specified, this call overrides the current visibility only until the next business hours interval.

Note

Parameters 

None.

Example 

1embeddedservice_bootstrap.utilAPI.showChatButton();

launchChat 

This API launches the web chat client with the messaging conversation window maximized. See Launch Chat.

Parameters 

ParameterTypeDescription
shouldStartNewConversationBooleanOptional. Available only in Enhanced Web Chat v2 deployments. If set to true and the current conversation is in the ended state, calling launchChat starts a new conversation. If the current conversation is still open, this parameter is ignored. The default value is false.

Event Handlers 

Use the event handlers of this method to perform actions after the chat client launches.

Event HandlerDescription
thenRuns actions if the web chat client launches successfully.
catchRuns actions when the web chat client launch fails.
finallyRuns actions after the chat client launches successfully or not.

Example 

1embeddedservice_bootstrap.utilAPI
2  .launchChat()
3  .then(function (success) {
4    // Add actions to run after the chat client launches successfully.
5  })
6  .catch(function (error) {
7    // Add actions to run after the chat client launch fails.
8  })
9  .finally(function () {
10    // Add actions to run whether the chat client launches
11    // successfully or not.
12  });

Response 

This method returns a Promise object.

removeAllComponents 

This method removes all Enhanced Web Chat components from a page on your website. Call the clearSession method first to completely clean up both authenticated and unauthenticated conversations.

Parameters 

None.

Example 

example.js
1embeddedservice_bootstrap.userVerificationAPI.clearSession(true).then(() => {
2  embeddedservice_bootstrap.utilAPI.removeAllComponents()
3});

setSessionContext 

The setSessionContext method is only available through Enhanced Web Chat v2 deployments. For more information, see Enhanced Chat in Salesforce Help.

Important

This method enables you to pass information like the current page or a recent search to the agent.

Context Object 

The top-level object defines a single piece of contextual information. Read more about creating context variable fields in agent conversations.

Field NameTypeDescription
nameStringThe name of the context variable. Supported values: _AgentContext: context variable for Enhanced Chat v2.
valueValue[]An object containing the value and its data type. See the Value (Parent) object schema for details.

Value (Parent) 

This object acts as a wrapper, defining the type and containing the payload of the context variable.

Field NameTypeDescription
valueTypeStringThe data type of the value field. Supported values: StructuredValue: Indicates the value is a complex JSON object.
valueValue[]The payload containing the structured data. See the Value (Child) object schema for a breakdown of the payload.

Value (Child) 

This nested object contains the specific, structured data on the user’s current context. value must be an object, but there are no required variables.

Field NameTypeDescription
currentPageStringOptional. The web page URL of the page the chat user is currently viewing.
searchSearch[]Optional. An object containing details about a search the user performed. See the Search object schema.

Search 

This object provides details about a user’s search activity. All fields are optional and can be populated if the information is available.

Field NameTypeDescription
resultStringThe specific search item the user is currently on.
filtersArray of StringsA list of product or category filters applied to the search.
facetsArray of StringsThe categories or facets the user was browsing or searching within.

Example 

1embeddedservice_bootstrap.utilAPI.setSessionContext([
2  {
3    "name": "_AgentContext",
4    "value": {
5      "valueType": "StructuredValue",
6      "value": {
7        "currentPage": "",
8        "search": {
9          "result": "",
10          "filters": [
11            ""
12          ],
13          "facets": [
14            ""
15          ]
16        }
17      }
18    }
19  }
20])