1

I am using Python and the Dialogflow V2 API. I would like to know how to reprompt an intent until a condition is met using Python Flask as the fulfillment. I am filling slots and then running an SQL query to verify the user's identity. If the query returns false (there is no identity that exists in the database), then I would like to rerun the intent until the condition is met (userId is found).

I have tried looking at the JS documentation, but cannot find any Python documentation for accomplishing the feat.

The Grindfather
  • 152
  • 2
  • 3
  • 12
  • Hm. I think I might have a solution but don't know how to implement it. Is there a way to trigger a fallback intent if a query run in the previous intent does not satisfy a condition? EX: userId is not found in the database after a user gives their name. – The Grindfather Dec 29 '18 at 23:57

1 Answers1

1

In the fulfillment, if condition is false, just reply with the same question like Sorry this username does not exist, please enter the username again.

if not username:
    res = json.dumps({
        "fulfillmentText": "Sorry this username does not exist, please enter the username again."
    })

If you have some input context for the intent as well, then you need to set he context from the fulfillment as well.

req = request.get_json()
if not username:
    res = json.dumps({
        "outputContexts": [
            {
                "name": "{}/contexts/ask-username".format(req['session']),
                "lifespanCount": 1,
            },
        ],
            "fulfillmentText": "Sorry this username does not exist, please enter the username again."
        })

EDIT:
To reset a parameter value, include the parameter in the output context as well in the webhook, and set #context.parameter as the default value of parameter in dialogflow console.
Documentation for setting default value of entity from context.

 "outputContexts": [
        {
            "name": "projects/${PROJECT_ID}/agent/sessions/${SESSION_ID}/contexts/ask-username",
            "lifespanCount": 1,
            "parameters": {
                "foo": ""
            }
        }
    ]

default value

Hope it helps.

sid8491
  • 6,622
  • 6
  • 38
  • 64
  • Thanks @sid8491 Is there a way to "go back"/clear a slot and get the next response from the user if the condition is not yet met? Similar to Rasa NLU's [UserUtteranceReverted()](https://rasa.com/docs/core/_modules/rasa_core/events/#UserUtteranceReverted)? – The Grindfather Dec 29 '18 at 23:12
  • @JAWS007 yes, you can include the slot in the output context and set their value to NULL, in the intent set default value of slot to `#context.slot` – sid8491 Dec 30 '18 at 06:40
  • Awesome @sid8491. Is there perhaps some documentation for this? Thanks. – The Grindfather Dec 31 '18 at 04:55