Reputation: 8889
I have $dinetype
variable obtained from the user.
But I would like to give response based on what value has been set in $dinetype
variable. In addition to giving responses, I also need to set relevant context. How do I do this in DialogFlow?
if($Dinetype=='dineout')
ask ('which restaurant would you like to go to?')
set_context ('awaiting-restaurant')
if($Dinetype=='takeaway')
ask ('When would you like to take away?')
set_context ('awaiting-takeaway-time')
Is it programmable at all? Or is it possible to achieve something equivalent to the above in the UI?
Upvotes: 15
Views: 16131
Reputation: 1
I found a solution to my similar problem using composite entities, which may or may not be overkill for your agent. The value assigned to a parameter associated with the (composite) entity will contain a JSON structure, if a synonym in that entity was matched. Using the "Dot" notation, you can assign the matched sub-entity's property (similar to the reference value of a normal entity) to another parameter in the Actions and Parameters section. You can have one parameter for each sub-entity and hence, you can evaluate these parameters in your response section to select each response variants:
$Parameter_A ResponseA
$Parameter_B ResonseB
....
etc.
Clunky but works. Just have to be careful to reference the property exactly as it is defined in the composite entity.
Upvotes: -1
Reputation: 3499
Edit: A much easier way has been added to handle this issue directly in Dialogflow
After creating an intent, you can add follow-up intents now.
Intents -> Create Intent >
[Response=Prompt For Conditional Response]
Intents -> Add Follow-up Intent -> Custom/Yes/No
Then set the training praise to a matching entity you want to conditionally respond to
Late reply, but maybe someone will find this useful.
If the conditional response only needs to reference a single parameter value, then I figured out what you can do is utilize the Entity's "Reference Value" as the response you want to give for a particular set of Synonyms.
So you'd have an entity that looked like this:
Then, setup your intent like this, with a response of
$Dinetype
:Then the end result will look like this:
And you can make whatever follow-up intent you need from there.
Down-side is
Dinetype
won't be as reusable. But I still think it beats writing a fulfillment webhook every time you need a simple conditional response.
Upvotes: 23
Reputation: 50701
You can't do this in the Response section directly. The Response section is meant for fairly simple responses that don't require significant logic to process. Although you can use parameters in the response, you can't give a different response based on the value of the parameter. So you can set a response to something like
I think $Dinetype is great food.
but not
{{#if $Dinetype == "Thai"}}I think Thai food is too hot{{/if}}
or anything like that
However, you can add code that sends conditional responses and contexts by implementing a Fulfillment webhook. Although you can't do this for each Intent as part of the Intent editor screen, the Fulfillment screen includes a built-in code editor.
Upvotes: 8