How to prevent None values in template utterance?

Hi,

So, I have this custom action, through which I want to return an utterance with the command dispatcher.utter_message(response=<template>, <var_name>=<var_value>.

The template I want to trigger has different utterances, which have different numbers of variables. For example, one is “I found no restaurants in the {area} area”, another one is “I found no restaurants in the {area} area with {price} price range”.

What I want is the system to understand that if I pass 1 variable it has to select an utterance with 1 variable, if a pass 2 variables it has to select an utterance with 2 and so on. Is that possible? What it does now is selecting random utterance from the template and placing None in the variables that are not passed. How can I solve this? (making a different template for every number of variables is unfeasible as I don’t know in advance how many a user can ask for).

Thank you, Tiziano

1 Like

Hey, the pythonic way is

if area and price:
    dispatcher.utter_message(...)
elif area:
    dispatcher.utter_message(...)
...

Ok but so I have to foresee all possible combination of variables? Isn’t there a way to condition the selection of the utterance in the template based on how many variables are set?