Configuration
Tailor the chat to your needs by initializing it with your own custom options.
Contents
Overview
Configuration options object
Theme configuration
Layout configuration
Header configuration
Service desk configuration
Server configuration
Creating links to the web chat
Listening for errors
Overview
When you create a web chat integration, the watsonx Assistant UI gives you a small embed code to add to your website:
Example
<script>
window.watsonAssistantChatOptions = {
// A UUID like '1d7e34d5-3952-4b86-90eb-7c7232b9b540' included in the embed code provided in watsonx Assistant.
integrationID: 'YOUR_INTEGRATION_ID',
// Your assistants region e.g. 'us-south', 'us-east', 'jp-tok' 'au-syd', 'eu-gb', 'eu-de', etc.
region: 'YOUR_REGION',
// A UUID like '6435434b-b3e1-4f70-8eff-7149d43d938b' included in the embed code provided in watsonx Assistant.
serviceInstanceID: 'YOUR_SERVICE_INSTANCE_ID',
// The callback function that is called after the widget instance has been created.
onLoad: async (instance) => {
await instance.render();
}
};
setTimeout(function(){const t=document.createElement('script');t.src='https://web-chat.global.assistant.watson.appdomain.cloud/versions/' + (window.watsonAssistantChatOptions.clientVersion || 'latest') + '/WatsonAssistantChatEntry.js';document.head.appendChild(t);});
</script>
watsonAssistantChatOptions
define the web chat configuration options. By default, watsonx Assistant provides the embed code that configures only the integrationID
, serviceInstanceID
, and the region
parameters (enterprise plans also include subscriptionID
). These options also include an onLoad
callback that calls when the web chat's code loads and creates a new instance. You need to call render
on that instance to display the widget.
You can modify watsonAssistantChatOptions
with other parameters that control the immutable behavior of your web chat's instance.
If you need to run dynamic operations to generate your configuration for the web chat, or you are using the namespace
configuration property to allow multiple web chats on the page, you can omit window.watsonAssistantChatOptions
and instead pass a configuration object into window.loadWatsonAssistantChat()
when you are ready to load the web chat. You must adjust your code to load window.loadWatsonAssistantChat
.
Configuration options object
The options
object assigned to watsonAssistantChatOptions
supports the following parameters:
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
Core options | ||||
integrationID | String |
Required | Defines the integration ID of your web chat as a UUID (for example, 1d7e34d5-3952-4b86-90eb-7c7232b9b540 ). |
|
region | String |
Required | Specifies the data center where you create your integration (for example, us-south ). |
|
serviceInstanceID | String |
Required | Identifies the service instance ID of the assistant that hosts your web chat integration as a UUID (for example, 6435434b-b3e1-4f70-8eff-7149d43d938b ). |
|
subscriptionID | String |
Provides the subscription ID. Enterprise instances require this option, so include it in the code snippet when you create the web chat integration. If you do not use an enterprise instance, this ID remains absent. | ||
onLoad | Function |
Required | Runs the callback when you load and create the web chat instance. You must provide a function that calls render on the provided instance to display the widget. |
|
clientVersion | String |
Loads the latest web chat version by default. You can also specify a specific major, minor or patch version. Locking to a major version of web chat is the recommendation. See current web chat versions and change log to see current version information | ||
Theming and layout | ||||
element | Element |
Defines the containing DOM element where the web chat widget renders. The widget grows to the size of the specified DOM element and appears in the element's location on the page. By default, the widget generates its own element. If you specify your own element, you must provide your own launching mechanism and set showLauncher to false . If you use a custom element, change the styles of the element for the main web widget window to hide or show it. For custom animations, apply animation styles. For more information, see tutorial for using a custom element. |
||
layout | Object |
Controls the layout behavior of the web chat. For more information, see Layout configuration. | ||
openChatByDefault | Boolean |
false | Determines whether the chat window initially renders in an open state when your page loads. By default, the chat window remains closed. | |
showLauncher | Boolean |
true | Determines whether the chat launcher icon appears. If you set this option to false , your website code must call instance.openWindow() to open the chat window. Alternatively, use openChatByDefault and hideCloseButton to display a permanently open web chat. For more information, see tutorial for using a custom launcher. |
|
themeConfig | Object |
Controls the theming behavior of the web chat. For more information, see Theme options. | ||
Header | ||||
hideCloseButton Deprecated | Boolean |
false | Moved to Header config. Hides the UI control that closes the chat window. Use this feature with openChatByDefault if you want the web chat to stay open on your page, or if you provide your own DOM element to contain the web chat. | |
closePanelButtonConfig Deprecated | Object |
Changes the behavior of the close button when a user clicks it. For more information, see closePanelButtonConfig. | ||
showRestartButton Deprecated | Boolean |
false | Moved to Header config. Displays a restart button in the header. You cannot use this feature with showCloseAndRestartButton |
|
showCloseAndRestartButton Deprecated | Boolean |
false | Moved to Header config. Displays a close-and-restart button in the header. It adds an "X" button next to the close/minimize button. This button restarts the conversation that a user has with the bot and closes the web chat window. It also ends any conversation with a human agent. If the user re-opens the web chat, the bot conversation clears, and a new conversation begins. The user can still see the conversation history with an agent, but the user must start a new conversation if they want to chat with a human agent again. You cannot use this feature with showRestartButton . |
|
Human agents | ||||
serviceDesk | Object |
Controls the behavior of service desk integrations. For more information, see Service desk configuration. | ||
Security and identity | ||||
cspNonce | String |
Enable a Content-Security-Policy on your site that only permits elements with a defined nonce. You can provide the value and the widget applies it to the script and style elements that the widget generates. |
||
identityToken | JWT token |
Enable security features to require a JWT to authenticate and authorize requests from the web chat to watsonx Assistant. For billing purposes, it must include a sub claim to denote a userID. Optionally, leave this blank and only generate the JWT when the web chat asks for a new JWT via event. For more information, see web chat security. |
||
disableCustomElementMobileEnhancements | Boolean |
false | Disables mobile enhancements when using element to specify a custom element. The web chat improves the behavior of the widget when displaying in full-screen mode on a mobile device. It includes resizing the web chat when the keyboard opens and changes in the zoom level of the view. If you are using a custom element, this functionality can interfere with how your element renders or its layout. To disable them, use this flag. If you do not use a custom element, this flag has no effect. | |
disclaimer Beta | Object |
Accepts an object with two arguments. isOn accepts a boolean. If set to true , the web chat requires a user to accept your disclaimer before they can interact with your assistant. disclaimerHTML provides the disclaimer text (or full html) that a user must accept. The browser stores the disclaimer whether or not the user accepts it, The browser memory stores the disclaimer until the user closes the browser. |
||
pageLinkConfig | Object |
true | Pre-configures a set of page link IDs that the web chat recognizes when a user goes to your page with an ID included as a URL parameter. These IDs trigger different greeting messages, allowing you to generate links to the web chat that can start specific conversations. For more information, see Creating links to web chat. | |
debug | Boolean |
false | Enables extra console logging. | |
onError | Function |
Calls the callback when an error occurs within the web chat. Errors that occur when the web chat is loading and errors that occur later, such as errors that occur when the user tries to send a message to the assistant. For more information, see Listening for errors. | ||
namespace | String |
Load multiple web chats on the same page when needed, give them each a unique namespace to avoid conflicts. Instead of providing your configuration object in window.watsonAssistantChatOptions , pass the configuration object into window.loadWatsonAssistantChat() and load the web chat when you need it. Using this property also changes your default CSS selector for styling components inside the web chat. For more information, see namespaces. |
||
learningOptOut | Boolean |
false | Adds the X-Watson-Learning-Opt-Out header to all traffic to watsonx Assistant. | |
disablePDFViewer | Boolean |
Disables the internal web chat PDF viewer. If true, the web chat presents links to PDFs that open in the user's web browser instead of the web chat viewer. This option is useful if the server hosting the PDF documents does not support CORS which is required for using the web chat viewer. | ||
disableWindowTitleChanges | Boolean |
false | Changes the title of the window/document to inform users of unread messages received while the web chat is not visible. You can use this property to disable this functionality so the web chat does not make any changes to the window title. | |
enableFocusTrap | Boolean |
false | Activates a focus trap when web chat opens. It locks focus inside the web chat and the user cannot move focus outside the web chat until they close it. Additionally, a semi-transparent background is placed behind the web chat that prevents the user from interacting with other elements on the page. This property has no effect if you also use hideCloseButton . |
|
shouldTakeFocusIfOpensAutomatically | Boolean |
true | Moves focus to the input field automatically when the web chat opens upon page load. It applies when the chat is stored in an open state by session history or if you have openChatByDefault set to true . |
|
servers | Object |
Configures the server settings that control how the web chat communicates with its servers such as, setting up a proxy. For more information, see server configuration. |
Theme configuration
You can customize colors and fonts the web chat uses for rendering.
In the watsonx Assistant user interface, configure the theme in three key areas:
- Choose between light or dark mode for the web chat.
- Choose if you want to apply the Carbon for AI theme on top of that choice.
If you are using the web chat for an internal IBM use case, turn on the Carbon for AI theme. This theme is placed on top of your carbonTheme
choice. It disables your ability to update colors with the updateCSSVariables
instance method and ignores many other styling settings that you can make inside watsonx Assistant.
- You can customize the colors and fonts of the web chat in the watsonx Assistant user interface. Choose a
primary
,secondary
, andaction
color. Also, you can apply one of four Carbon themes by using thecarbonTheme
property:
- White
- Gray 10
- Gray 90
- Gray 100
The light themes include White and Gray 10, while Gray 90 and Gray 100 provide dark grays and blacks. You also have fine-grained control over individual properties with the updateCSSVariables
instance method.
For more information, see web chat configuration.
Warning: The web chat provides many hooks to amend and change content, and the web chat uses HTML, CSS, and JavaScript for its build. Avoid manipulating content outside the default configuration to prevent unintended issues when the web chat deploys new releases.
Parameter | Type | Default | Description |
---|---|---|---|
themeConfig.carbonTheme | String |
g10 | Use the carbonTheme option to theme your widget with a Carbon Theme as defined in the Carbon Design System. Accepted values are "white", "g10", "g90" or "g100". Defaults to "g10". You can override specific theming variables after setting a core theme. |
themeConfig.useAITheme | Boolean |
false | Add IBM Carbon for AI branding to the web chat. For internal IBM usage. |
Layout configuration
The web chat provides a layout configuration that allows you to modify the widget frame and content.
Parameter | Type | Default | Description |
---|---|---|---|
layout.showFrame | Boolean |
true | Indicates whether the web chat frame displays. It includes the border and box-shadow on the outside of the main window. |
layout.hasContentMaxWidth | Boolean |
false | Indicates whether the web chat content constrains to a max-width for wide web chat layouts. The max-width of the chat content is 627px. If you enable the AI theme, this option defaults to true . |
Example
For a fullscreen version of the web chat, you can use the following configuration:
<script>
window.watsonAssistantChatOptions = {
integrationID: 'YOUR_INTEGRATION_ID',
region: 'YOUR_REGION',
serviceInstanceID: 'YOUR_SERVICE_INSTANCE_ID',
element: myElementThatIsFullScreen,
themeConfig: {
corners: 'square',
},
layout: {
showFrame: false,
hasContentMaxWidth: true,
},
onLoad: async (instance) => {
await instance.render();
}
};
setTimeout(function(){const t=document.createElement('script');t.src='https://web-chat.global.assistant.watson.appdomain.cloud/versions/' + (window.watsonAssistantChatOptions.clientVersion || 'latest') + '/WatsonAssistantChatEntry.js';document.head.appendChild(t);});
</script>
Header configuration
This object has some general configuration settings used for controlling the behavior of the header.
Parameter | Type | Default | Description |
---|---|---|---|
headerConfig.minimizeButtonIconType | String |
'minimize' | Indicates what icon to use in the place of the minimize button in the header. The possible values are: minimize , close (X icon), side-panel-left and side-panel-right . |
headerConfig.hideMinimizeButton | Boolean |
false | Indicates whether to hide the UI control that closes the chat window. Use this feature along with openChatByDefault if you want the web chat to stay open on your page, or if you provided your own DOM element to contain the web chat. |
headerConfig.showRestartButton | Boolean |
false | Indicates whether or not the restart button displays in the header. You cannot use this feature with showCloseAndRestartButton |
headerConfig.showCloseAndRestartButton | Boolean |
false | Indicates whether or not the close-and-restart button displays in the header. It adds an additional "X" button next to the close/minimize button. This button restarts the conversation that a user has with the bot and closes the web chat window. It also ends any conversation with a human agent. If the user re-opens the web chat, the bot conversation clears, and a new conversation begins. The user can still see the conversation history with an agent, but the user must start a new conversation if they want to chat with a human agent again. You cannot use this feature with showRestartButton . |
Example
<script>
window.watsonAssistantChatOptions = {
integrationID: 'YOUR_INTEGRATION_ID',
region: 'YOUR_REGION',
serviceInstanceID: 'YOUR_SERVICE_INSTANCE_ID',
headerConfig: {
minimizeButtonIconType: 'side-panel-left',
},
onLoad: async (instance) => {
await instance.render();
}
};
setTimeout(function(){const t=document.createElement('script');t.src='https://web-chat.global.assistant.watson.appdomain.cloud/versions/' + (window.watsonAssistantChatOptions.clientVersion || 'latest') + '/WatsonAssistantChatEntry.js';document.head.appendChild(t);});
</script>
Service desk configuration
When the web chat configures a service desk integration, this object controls the options that the web chat provides for how it interacts with the integration. You can add this object to the top level configuration option under the serviceDesk
property.
Parameter | Type | Default | Description |
---|---|---|---|
serviceDesk.agentJoinTimeoutSeconds | Number |
(disabled) | The timeout value in seconds when the user is waiting for an agent to join after the user requests an agent. If no agents join the chat before this timeout, then the agent chat ends and the user receives an error message. If you do not define this value, then there is no timeout. |
serviceDesk.availabilityTimeoutSeconds | Number |
5 | The timeout value in seconds when determining agent availability. When a "Connect to agent" response is received, the system asks the service desk if any agents are available. If no response is received within the timeout window, the system returns "false" to indicate no agents are available. |
serviceDesk.disableAgentSessionHistory | Boolean |
false | Indicates whether the assistant stores a conversation between the user and a human agent in its session history. By default, when the user engages in a conversation with a human agent, all messages during that conversation are stored in session history so they can be retrieved if the user reloads the web chat. To opt-out of this behavior, set this value to true. When set to true, these messages are never sent to the assistant. |
serviceDesk.skipConnectAgentCard | Boolean |
false | Indicates whether the web chat auto-connects to an agent whenever it receives a "Connect to agent" response and agents are available. It mimics the user clicking the "request agent" button at the top of the chat window. The user sees the "agents available" text from the response. |
Example
<script>
window.watsonAssistantChatOptions = {
integrationID: 'YOUR_INTEGRATION_ID',
region: 'YOUR_REGION',
serviceInstanceID: 'YOUR_SERVICE_INSTANCE_ID',
serviceDesk: {
skipConnectAgentCard: true,
},
onLoad: async (instance) => {
await instance.render();
}
};
setTimeout(function(){const t=document.createElement('script');t.src='https://web-chat.global.assistant.watson.appdomain.cloud/versions/' + (window.watsonAssistantChatOptions.clientVersion || 'latest') + '/WatsonAssistantChatEntry.js';document.head.appendChild(t);});
</script>
Close panel button config Deprecated
You can modify the web chat minimize button look and behavior to enable custom closing behavior for the web chat in a panel-like layout by using a custom element.
When you click the button, it fires a closePanelButton:toggled event for you to hook into and implement your panel closing logic.
It is deprecated. Use headerConfig instead.
Parameter | Type | Default | Description |
---|---|---|---|
closePanelButtonConfig.is_on | Boolean |
false | Indicates whether the web chat uses the "close panel" button. It changes the minimize button icon to an icon that indicates closing a panel and prevents the web chat from minimizing. |
closePanelButtonConfig.closeIconDirection | String |
Indicates the direction that the button icon faces. Either 'left' or 'right' . The default value is automatically set to 'right' if the page direction is not rtl. If the page direction is rtl, the default value is 'left' . You can still override the default behavior by setting the value. |
Example
<script>
function handler() {
// Your panel closing logic.
}
window.watsonAssistantChatOptions = {
integrationID: 'YOUR_INTEGRATION_ID',
region: 'YOUR_REGION',
serviceInstanceID: 'YOUR_SERVICE_INSTANCE_ID',
closePanelButtonConfig: {
is_on: true,
},
onLoad: async (instance) => {
instance.on({ type: 'closePanelButton:toggled', handler: handler });
await instance.render();
}
};
setTimeout(function(){const t=document.createElement('script');t.src='https://web-chat.global.assistant.watson.appdomain.cloud/versions/' + (window.watsonAssistantChatOptions.clientVersion || 'latest') + '/WatsonAssistantChatEntry.js';document.head.appendChild(t);});
</script>
Server configuration
The main web chat configuration object has a servers
option object that controls how the web chat communicates with its server. The different options available in this object are documented below.
Note: These options do not work with the old "loadWatsonAssistantChat.js" form of the web chat embed script. Make sure that your script uses the "WatsonAssistantChatEntry.js" version. You can find it in the embed tab of the web chat configuration settings in watsonx Assistant.
Parameter | Type | Default | Description |
---|---|---|---|
servers.assistantURLPrefix | String |
The web chat uses this prefix when it communicates with watsonx Assistant. It modifies the calls that fetch the web chat configuration, session history, and sending messages. | |
servers.webChatScriptPrefix | String |
The web chat uses this prefix when it downloads extra JavaScript files that the web chat uses. These are static files that the content delivery network (CDN) hosts. |
Setting up a proxy
You can use the assistantURLPrefix
and webChatScriptPrefix
properties if you need to set up a proxy between your users' browsers and watsonx Assistant. The assistantURLPrefix
controls communication with the assistant and webChatScriptPrefix
controls communication with the CDN where it hosts the web chat JavaScript. You can set these values to the URL of your proxy (and you can add path information as well). If you use a proxy, the proxy forwards all requests below the path specified by this prefix to the original URL. The requests are forwarded without modification (including all non-proxy related headers). The content of the requests are considered opaque and can change without notice.
You can use any paths that you want in each prefix and you can use separate proxies for each if you need. However, you either need multiple proxies or a single proxy that can forward requests based on path in order to make sure that requests for the assistant go to the assistant and requests for the web chat scripts go to the web chat CDN.
For reference, the default value of assistantURLPrefix
is https://integrations.<region>.assistant.watson.appdomain.cloud
, where <region>
is the same as the region in your web chat embed code. The default value of webChatScriptPrefix
is https://web-chat.global.assistant.watson.appdomain.cloud
.
Example
<script>
window.watsonAssistantChatOptions = {
integrationID: 'YOUR_INTEGRATION_ID',
// Example region is us-east.
region: 'us-east',
serviceInstanceID: 'YOUR_SERVICE_INSTANCE_ID',
servers: {
assistantURLPrefix: 'https://proxy.privatecompany.com/assistant',
webChatScriptPrefix: 'https://proxy.privatecompany.com/webchat',
},
onLoad: async (instance) => {
async instance.render();
}
};
setTimeout(function(){const t=document.createElement('script');t.src='https://web-chat.global.assistant.watson.appdomain.cloud/versions/' + (window.watsonAssistantChatOptions.clientVersion || 'latest') + '/WatsonAssistantChatEntry.js';document.head.appendChild(t);});
</script>
With this example, the proxy at proxy.privatecompany.com
forwards all requests from /assistant/*
to https://integrations.<region>.assistant.watson.appdomain.cloud/*
and all requests from /webchat/*
to https://web-chat.global.assistant.watson.appdomain.cloud/*
.
Creating links to the web chat
If you want to create a link to the web chat that opens it and starts a conversation from a specific topic, you can use the pageLinkConfig
configuration option. Use this configuration if you want to send an email to your customers with a link for something like "Click here to update your account". This link takes the customer to your website, open the web chat, and begin the conversation with your "update account" conversation.
Pre-configure a set of link IDs that you can include in your external URLs. When the web chat recognizes one of these IDs, it automatically opens and sends a message to your assistant by using the text that you configured for that ID. Your skill needs to recognize this text and start the conversation. This text is not visible to the user.
Configuration
To use a pre-configured ID, add it to any link to your website that uses the web chat by using the URL parameter wa_lid
.
To define the IDs, use the pageLinkConfig
embed script configuration property, which has the following structure. You can use any text that you want for the IDs but we recommend that you use only numbers and letters in your link IDs since not all characters are allowed in URLs. And we recommend sticking to values that are not immediately obvious to your customers (e.g. make your link ID "abc123" instead of "update-account") to avoid customers trying to abuse or manipulate the values.
Then you can generate a link to your website that can look something like https://mywebsite.com/accounts?wa_lid=u35
.
Note: If links to your website already have ?
in them, you need to use &
instead: https://mywebsite.com/?page=accounts&wa_lid=u35
.
Property | Type | Description |
---|---|---|
pageLinkConfig.linkIDs | Object |
This object defines all the recognized link IDs. |
pageLinkConfig.linkIDs[id] | Object |
This value is an object that represents how the web chat responds when it recognizes the ID. |
pageLinkConfig.linkIDs[id].text | String |
This text is what your assistant recieves when it recognizes the ID. |
Example
<script>
window.watsonAssistantChatOptions = {
integrationID: 'YOUR_INTEGRATION_ID',
region: 'YOUR_REGION',
serviceInstanceID: 'YOUR_SERVICE_INSTANCE_ID',
pageLinkConfig: {
linkIDs: {
'u35': {
text: 'I would like to update my account'
},
'r23': {
text: 'I need to reset my password'
}
}
},
onLoad: async (instance) => {
await instance.render();
}
};
setTimeout(function(){const t=document.createElement('script');t.src='https://web-chat.global.assistant.watson.appdomain.cloud/versions/' + (window.watsonAssistantChatOptions.clientVersion || 'latest') + '/WatsonAssistantChatEntry.js';document.head.appendChild(t);});
</script>
Listening for errors
Your web chat configuration can include an onError
option that acts as a callback where the web chat calls when errors occur within the web chat. These errors can occur in the initialization phases of the web chat or they can occur later when your user is using the web chat. Below are the details of what data passes to this callback when different errors occur.
Error data
The onError
function is called with a single parameter that contains the following properties:
Property | Type | Description |
---|---|---|
errorType | String |
The type of error the system reports. |
message | String |
The text description of the error. |
errorCode | Number |
The code associated with the error. The value provided here depends on what error type the system reports. |
otherData | Anything |
The extra data that associates with the error. It can be a stack trace for example. |
Error types
Error type | Description |
---|---|
HYDRATION | Occurrs when the web chat tries to load but cannot load the necessary data to start. This error indicates a problem trying to fetch the welcome information and often appears with other errors. |
IDENTITY_TOKEN | Occurs when identity token configuration is incorrect. The web chat requests a new identity token by using the identityTokenExpired event, but no subscriber provides a token. This error indicates an error in the host web page, not the web chat. |
INITIAL_CONFIG | Occurs when the web chat fails to load the initial configuration data. When this error occurs, the launcher does not display, and the web chat does not load. The errorCode contains the HTTP response code from the request. |
INTEGRATION_ERROR | Occurs when there is a problem with the integration configuration. The only condition currently reported is the case where the integration returns a "Connect to agent" response but no service desk is configured that is capable of responding to it. |
MESSAGE_COMMUNICATION | Occurs when there was an error sending a message from the user to the assistant. This error fires after all the retry attempts fail and the web chat gives up. In this case, the errorCode contains the HTTP response code from the request. |
OPEN_CONFIG | Occurs when a user opens the web chat and the web chat requests to load extra configuration data for the integration. The error generates if the request fails. In this case, the errorCode contains the HTTP response code from the request. |