Search code examples
if-statementdialogflow-esapi-ai

Dialogflow: Respond based on values and other conditional responses


I have $dinetype variable obtained from the user.

enter image description here

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?

enter image description here

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?


Solution

  • 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.