Reputation: 21
I have a list of specific entities, how do I set an individual response for each one? or a list to responses for specific entities?
I was thinking maybe it could be achieved through the Google assistant custom payload(?)
Upvotes: 2
Views: 2884
Reputation: 3499
Late response, but maybe someone will find this answer useful if you prefer not having to use fulfillment webhooks and you only need to utilize one parameter.
https://stackoverflow.com/a/55926775/1011956
Upvotes: 1
Reputation: 50741
Your question is somewhat vague, but it sounds like you will have a parameter in an Intent set to some value, those values coming from a custom Entity type, and you want a different response for each value.
You can't handle this through the Response section of the Intent - you need to use a fulfillment webhook.
If you're using the actions-on-google library (which you suggest you might be using), and the parameter was named val
, then the code fragment might look something like this:
app.intent('choose.value', (conv, {val}) => {
switch( val ){
case 'red':
agent.add('I like red too!');
break;
case 'blue':
agent.add('Blue is pretty cool!');
break;
default:
agent.add(`Not sure what to say about ${val}.`);
}
})
If you are using the dialogflow-fulfillment library, it would be something like:
var chooseVal = function( agent ){
var val = agent.parameters.val;
switch( val ){
case 'red':
conv.ask('I like red too!');
break;
case 'blue':
conv.ask('Blue is pretty cool!');
break;
default:
conv.ask(`Not sure what to say about ${val}.`);
}
}
If you are using multivocal, you can add a builder that sets the Outent
environment setting based on the color, and set the responses for the Outent and the Intent in the configuration:
new Multivocal.Config.Simple({
Local: {
en: {
Response: {
"Outent.red": [
"I like red too!",
"Red is nifty."
],
"Outent.blue": [
"Blue is pretty cool!",
"I really groove blue"
],
"Intent.choose.value": [
"Not sure what to say about {{Parameter.val}}"
]
}
}
}
});
var outentBuilder = function( env ){
env.Outent = `Outent.${env.Parameter.val}`;
return Promise.resolve( env );
};
Multivocal.addBuilder( outentBuilder );
Upvotes: 3