Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to prompt for an entity with "yes" or "no" question in dialogflow?

I have an entity "employeeType" in Dialogflow with values as "Federal employee" and "Private Employee".

If the entity data is not obtained, I want to ask user a question "Are you a Federal Employee?" to which user can respond "yes" or "no".

However I am not finding a way to do it since such a question wont return the predefined values "Federal employee" or "Private Employee".

Any thoughts on ways to fix this?

like image 511
buddy Avatar asked Dec 29 '25 18:12

buddy


1 Answers

Here is my recommended approach:

  1. Make an intent which accepts employeeType entity but do not mark it as required
  2. Turn on the webhook for this intent, and do not put any fulfillment text
  3. In the webhook check parameter employeeType if it contains value or its empty
  4. If employeeType have value, just return a fulfillment text and proceed with your flow
  5. If employeeType is empty, then set output context emp-followup and put fulfillment text "Are you a Federal Employee?"
  6. Make a yes-follow-up intent and a no-follow-up intent for your intent with input context emp-followup and put fulfillment text in those to proceed with your flow

intent set up

conversation-1 conversation-2 conversation-3

Sample Code:

req = request.get_json()
    params = req.get('queryResult').get('parameters')
    if params['employeeType']:
        res = json.dumps({
            "fulfillmentText": "great! welcome sir."
        })
    else:
        res = json.dumps({
            "outputContexts": [
            {
                "name": "{}/contexts/emp-followup".format(req['session']),
                "lifespanCount": 2,
            },
        ],
            "fulfillmentText": "are you a federal employee"
        })
    return res

Hope it helps.

like image 184
sid8491 Avatar answered Jan 03 '26 12:01

sid8491



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!