Add the application to the Virtual Agent
Add the application to the Virtual Agent
If you implemented the Virtual Agent in your ServiceNow instance, you can integrate Coveo for ServiceNow in the Virtual Agent to return relevant matching items.
Workflow example
As an end user engages with the Virtual Agent to solve an issue, the following takes place:
-
The Virtual Agent asks the end user for a brief description of their issue.
-
The end user enters a short text.
-
Coveo receives the query and extracts the most important keywords.
-
The Virtual Agent returns
OK, here are some resources that might help.
. -
Coveo returns search results that are relevant to the issue described by the end user and displays the results in the Virtual Agent discussion panel.
-
The end user clicks the result that seems most relevant to their current issue.
Integrate Coveo for ServiceNow in the Virtual Agent
-
If you haven’t done so yet, activate the Virtual Agent plugin in your ServiceNow instance.
-
Use the application picker, or the application list menu on the ServiceNow banner frame, to switch the application scope to the Coveo application, which is listed as AI-Powered Search & Recommendations by Coveo.
-
Create a new Virtual Agent topic in which to integrate Coveo, or duplicate an existing topic to use as a base.
NoteYou must create or duplicate the Virtual Agent topic in the AI-Powered Search & Recommendations by Coveo application scope.
-
Navigate to Collaboration > Virtual Agent > Designer.
-
In the Virtual Agent Designer, click the topic that you created or duplicated for use with Coveo.
-
Click the Flow tab.
-
Add a Text User Input component to the topic flow. This component lets a user enter a short description of their issue.
-
Specify the following Text User Input component properties:
-
Under User Input Properties, for the Name field, enter
short_description
. -
In the Prompt field, enter the text that you want to display as the initial prompt to the user, such as
How can I help you?
.
-
-
Optionally, add a Text Bot Response component to the topic flow below the User Input component. This text appears after a user enters an issue description and is used to introduce the results returned by Coveo.
-
Specify the following Text Bot Response component properties:
-
Under Response Properties, enter a Name such as
bot_response
. -
Enter a Response Message such as
OK, here are some resources that might help.
.
-
-
Add a Script Output Bot Response component to the topic flow either below the Text Bot Response if you added one, or below the Text User Input. This component initializes Coveo search in your Virtual Agent topic.
-
Specify the following Script Output Bot Response component properties:
-
Under Response Properties, enter a Name such as
coveo_output
. -
In the Script Output Type list, select Multi-Part.
-
Under Script Response Message, paste the following:
(function execute() { var va = new CoveoVirtualAgent(); va.init("Portal", "VirtualAgent"); return va.getFormattedResults(String(vaInputs.short_description)); })()
-
-
Click Save.
-
Optionally, you can customize your integration. For example, you can specify a
scope
andcomponent
naming convention, which is useful when configuring query pipelines and query filters and associating them with your integration, or you can customize how search results appear in your Virtual Agent. -
To maximize the relevance of search results returned by Coveo in your Virtual Agent, in the Coveo Administration Console:
-
Associate your model with the desired query pipeline, and while doing so, check the Comply with Intelligent Term Detection (ITD) box.
Configure your query pipeline
Once you’ve added Coveo for ServiceNow to your Virtual Agent, you must link your integration to a query pipeline in your Coveo organization.
-
In the Coveo Administration Console, on the Query Pipelines (platform-ca | platform-eu | platform-au) page:
-
If you want to use an existing pipeline, select it, and then click More > Edit in the Action bar.
-
Create a new pipeline for the Virtual Agent to use.
-
-
In the Add/Edit a Query Pipeline (platform-ca | platform-eu | platform-au) panel, create a condition enforcing a specific search hub (
Search hub is
) for the pipeline that points to your Virtual Agent. With such a condition, your pipeline will be used for all queries originating from the Virtual Agent.If your pipeline already has a condition, ensure to include the existing condition in your new one with an
OR
operator.ExampleYour pipeline has the following condition:
Search Hub is Portal_MyWidget
. You want to link the Virtual Agent to this pipeline, so your new condition isSearch Hub is Portal_MyWidget OR Search Hub is Portal_VirtualAgent
. With this condition, your pipeline will be used for all queries originating from either the specified widget or the Virtual Agent.The filter value to enter for the condition depends on your Virtual Agent configuration:
-
If you didn’t provide
scope
andcomponent
values in theinit
function, enterServiceNow
. -
If you provided
scope
andcomponent
values, enter them in the following format:scope_component
.ExampleFor a Virtual Agent with a
Portal
scope and aVirtualAgent
component, your condition value should bePortal_VirtualAgent
. Your complete pipeline condition is thereforeSearch Hub is Portal_VirtualAgent
.
-
Customization
By default, Coveo for ServiceNow returns simple results in the Virtual Agent. Only the title and an excerpt are displayed in the Virtual Agent discussion panel.
If you want to customize how the results appear, you can pass a CoveoVirtualAgentResultsRenderer
instance with a custom template as an optional third argument when calling the init
function method on your CoveoVirtualAgent
instance.
To set a custom template on a CoveoVirtualAgentResultsRenderer
instance, use the setTemplate
method.
The following script contains a custom result template at line 3.
The resultRenderer
function is then passed as a parameter for the Virtual Agent.
(function execute() {
var resultRenderer = new CoveoVirtualAgentResultsRenderer();
var template = ++++'<div><a href="{{clickUri}}" onclick="{{logClickEvent}}"></a>{{raw.author}} - {{title}}</div>'++;
resultRenderer.setTemplate(template);
var va = new CoveoVirtualAgent();
va.init("CustomerServicePortal or ITPortal or HRPortal", "Virtual Agent", resultRenderer);
return va.getFormattedResults(String(vaInputs.short_description));
})()
To customize your Virtual Agent integration
-
Access the Script Output bot-response component of the Virtual Agent topic in which you integrated Coveo.
-
Modify the Script Response Message as required. Refer to the Reference section for the list of objects and functions.
Reference
CoveoVirtualAgent (object type)
The CoveoVirtualAgent
object can forward requests to the Coveo Search and Usage Analytics APIs using input from the ServiceNow Virtual Agent environment (see the short_description
user input mentioned under Integrate Coveo for ServiceNow in the Virtual Agent).
init (function)
The init
function initializes the CoveoVirtualAgent
, granting it the ability to execute search requests and log usage analytics events.
Parameters:
-
scope
(string, optional): The scope under which you want to categorize the function. This parameter work similarly to the Scope widget option. -
component
(string, optional): The component under which you want to categorize the function. This parameter work similarly to the Component widget option. -
resultRenderer
(function, optional): To customize how the search results appear in the Virtual Agent, this function passes aCoveoVirtualAgentResultsRenderer
instance that uses your custom HTML result template. If you don’t provide this parameter, the default template is used.
getFormattedResults (function)
The getFormattedResults
executes a query, therefore calling getSearchResults
, and returns a MultiPartOutMsg
to be displayed in the Virtual Agent.
The query results are also saved in the Virtual Agent for more use (see Virtual Agent Scripts).
For example, you could reuse the initial end user input in a script later in the conversation.
Parameters:
-
userQuery
(string): The basic query expression (q
) to send to the Search API. Normally, this will be set to the text entered in theshort_description
user input (see Integrate Coveo for ServiceNow In the Virtual Agent). -
context
(string): Additional context to add to the query. This information is useful for Coveo ML ART and usage analytics reporting purposes (see Custom Context).
getSearchResults (function)
The getSearchResults
function executes a query and sends a search event to Coveo Analytics, and then returns the results from the query.
Parameters:
-
userQuery
(string): The basic query expression (q
) to send to the Search API. Normally, this will be set to the text entered in theshort_description
user input (see Integrate Coveo for ServiceNow In the Virtual Agent). -
context
(string): Additional context to add to the query. This information is useful for Coveo ML ART and usage analytics reporting purposes (see Custom Context).
getRenderer (function)
The getRenderer
function returns the resultRenderer
.
getVisitorId (function)
The getVisitorId
function returns the visitor ID, which is the unique identifier of the tracked end user as stored in the Coveo cookie.
setVisitorId (function)
The setVisitorId
function saves the visitor ID for future use.
Parameter:
visitorId
(string): The visitor ID.
CoveoVirtualAgentResultsRenderer (object type)
The CoveoVirtualAgentResultsRenderer
object type formats results from a Coveo search so that they can be displayed in the Virtual Agent.
This behavior can be customized through the use of various methods (setTemplate
, setNumberOfResults
, etc.).
You can pass an instance of this object in the desired state as an optional third parameter when calling the init
function of a CoveoVirtualAgent
instance.
From an object-oriented perspective, CoveoVirtualAgentResultsRenderer
can be seen as a class whose public interface is documented below.
setTemplate (function)
The setTemplate
function accepts a single parameter: the HTML result template to use when rendering the results.
Parameter:
template
(string): The template to use to display query results.
This template may include Mustache syntax to display dynamic query result field values (for example, {{raw.myfield}}
).
Important: Ensure that your custom result template includes a result link, that is, an a
tag whose href
attribute is set to {{clickUri}}
and whose onclick
attribute is set to {{logClickEvent}}
.
Executing the logClickEvent
function is essential to gather the data that will be analyzed by Coveo Machine Learning.
setNoResultsTemplate (function)
The setNoResultsTemplate
function sets the HTML template to use when no results are returned.
Parameter:
template
(string): The template to use when a query produces no results.
setNumberOfResults (function)
The setNumberOfResults
function sets the maximum number of results to display in the Virtual Agent.
If the query yields a number of results that’s greater than this number, the number of results displayed is limited to the specified numberOfResults
.
Parameter:
numberOfResults
(integer): The maximum number of results to display for the query.
createResultsMsg (function)
The createResultsMsg
function creates a new MultiPartOutMsg
containing the results to display in the Virtual Agent.
This function is required when using a custom result renderer.
Parameters:
-
results
(object): The query results (see Query response properties). This information is passed byCoveoVirtualAgent
. -
params
(object): The context of the renderer, that is, information on how the results were retrieved. This information is passed byCoveoVirtualAgent
.
What’s next?
Configure query filters to ensure that the Coveo for ServiceNow components you configured in your public-facing and internal portals only return items from appropriate subsets of your Coveo organization's indexed content.