Constructor
new ConversationEngine()
Constructed and returned by Violet when a Voice Script initializes
Methods
(async) addFlowScriptEx(script, controllers, namespace)
Imports a given Conversation Flow Language Script, initializes the given
controllers (calls the initialize method if available) and makes the
controllers be accessible from the script.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
script |
string | the conversation script | |
controllers |
Object | map of name-value pairs consisting of multiple controllers | |
namespace |
string | node | namespace to be used if nodes in the script are not given an id |
- Default Value:
- namespace='node'
- Source:
addInputTypes(inputTypes)
Used to define parameters that can be expected from the user
Parameters:
Name | Type | Description |
---|---|---|
inputTypes |
Object | key:value pairs representing varName:typeName. Commonly supported values for typeName are: firstName, lastName, number, date, time, phoneNumber, and phrase. In addition, typeName can be an object for customSlots (with a values property) or for AMAZON.LITERAL (with a sampleValues property) |
Examples
basic usage
violet.addInputTypes({
'name': 'firstName',
});
violet.respondTo(['My name is [[name]]'],
(response) => {
response.say('I like the name [[name]]')
});
defining custom types
violet.addInputTypes({
'timeUnit': {
type: 'timeUnitType',
values: ['days', 'hours', 'minutes']
}
});
defining literals (while literals are open ended, it is recommended to use custom types for better recognition)
violet.addInputTypes({
'itemName': {
type: 'AMAZON.LITERAL',
sampleValues: ['Call Chris', 'Book an appointment']
}
});
addPhraseEquivalents()
Gives a set of equivalent phrases
Example
violet.addPhraseEquivalents([
['My name is', 'I call myself'],
]);
violet.respondTo(['My name is [[name]]'],
(response) => {
response.say('I like the name [[name]]')
});
defineGoal(goalDef)
Defines what should happen when a goal is triggered (by calling the
addGoal method). Goals allow for
the grouping of application and user responses.
Parameters:
Name | Type | Description | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
goalDef |
Object | goal definition
Properties
|
Examples
setting up goals to be triggered from a regular intent
violet.respondTo('What time does the [[airline]] flight arrive',
(response) => {
response.addGoal('flightArrivalTime');
});
violet.respondTo('What time does the flight arrive from [[city]]',
(response) => {
response.addGoal('flightArrivalTime');
});
when the user is asking for a flight arrival time and we want to check if dependencies have been provided
violet.defineGoal({
goal: 'flightArrivalTime',
resolve: (response) => {
if (!response.ensureGoalFilled('airline')
|| !response.ensureGoalFilled('city')
|| !response.ensureGoalFilled('flightDay') ) {
return false; // dependent goals not met
}
var airline = response.get('airline');
var city = response.get('city');
var flightDay = response.get('flightDay');
flightArrivalTimeSvc.query(airline, city, flightDay, (arrivalTime)=>{
response.say('Flight ' + airline + ' from ' + city + ' is expected to arrive ' + flightDay + ' at ' + arrivalTime);
});
return true;
}
});
when the user is asking for a flight arrival time and has not provided the airline name
violet.defineGoal({
goal: 'airline',
prompt: ['What airline', 'What airlines are you looking for the arrival time?'],
respondTo: [{
expecting: '[[airline]]',
resolve: (response) => {
response.set('airline', response.get('airline') );
}}]
});
when the user is asking for a flight arrival time and has not provided the originating city
violet.defineGoal({
goal: 'city',
prompt: ['What city do you want the flight to be arriving from'],
respondTo: [{
expecting: '[[city]]',
resolve: (response) => {
response.set('city', response.get('city') );
}}]
});
loadExpectings(expectingsPath)
Reads a file containing a list of expectings from the given path and adds
those options to the model.
Expectings are provided as key-value pairs with the keys representing ids
in the CFL script and the values representing options that the script could
expect from the user.
Parameters:
Name | Type | Description |
---|---|---|
expectingsPath |
string | path to the expectings file (consisting of a yaml based data) |
(async) loadFlowScriptEx(scriptPath, controllers, namespace)
Reads a Conversation Flow Language Script from the given path, imports the
script, initializes the given
controllers (calls the initialize method if available) and makes the
controllers be accessible from the script.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
scriptPath |
string | path to the conversation script | |
controllers |
Object | map of name-value pairs consisting of multiple controllers | |
namespace |
string | node | namespace to be used if nodes in the script are not given an id |
- Default Value:
- namespace='node'
- Source:
registerResponseDecorator()
Called by some Violet plugins (such as the store plugins) to decorate the Response
class when instantiated. The initResponse method on these objects are called
with the Response object as a parameter and are expected to return the decorated
response object.
respondTo(intentDef)
Declare how you are going to be responding to users
Parameters:
Name | Type | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
intentDef |
Object | intent definition
Properties
|
Examples
a basic example
violet.respondTo('Hello',
(response) => {
response.say('Hi');
});
using most of the parameters
violet.respondTo({
expecting: ['I live in [[city]]', 'My house is in [[city]]', 'We are renting in [[city]]'],
resolve: (response) => {
response.say('I like the city [[city]]')
}});
setCloseRequests(phrases)
Override the default phrases to close the session.
Parameters:
Name | Type | Description |
---|---|---|
phrases |
Array.<string> | response or array of potential responses |
setLaunchPhrases(phrases)
Override the default launch phrases. Parameter is used directly
with the response.say() function when a Platform launches this app
Parameters:
Name | Type | Description |
---|---|---|
phrases |
Array.<string> | response or array of potential responses |