2

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(?)

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

2 Answers2

3

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 );
Prisoner
  • 49,922
  • 7
  • 53
  • 105
  • 1
    i am new for this, to using `actions-on-google` should we use the key of dialogflow for authentication ?? – poppop Jul 06 '19 at 15:21
  • 1
    I'm not sure I understand your question. It sounds like you should [ask a new](https://stackoverflow.com/questions/ask) question, explaining what you're trying to do, and why you think you need to use the dialogflow key. – Prisoner Jul 06 '19 at 16:03
  • 1
    https://stackoverflow.com/questions/56915752/how-to-use-custom-payload-for-intent here – poppop Jul 06 '19 at 16:12
1

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

corylulu
  • 3,449
  • 1
  • 19
  • 35