Slot filling using webhook in Dialogflow CX

I got this question about the Learn Dialogflow CX course

I am using slot filling to collect some data, example name, subjects,marks. After collecting data I need to do some logic to them. where should i enable the webhook to get all the parameters that i have collected in cx? 

Let us take the example of the Slot filling Dialogflow CX quickstart template.

Calling the webhook after slot filling is complete

We already have a conditional route which checks to see if all page params have been collected.

And when you click on this condition, you can see the details of the condition route

If you click on the “Enable Webhook” toggle for this condition route, the webhook will only be called after all the params have been collected.

Calling the webhook before slot filling is complete

You can also call the webhook before slot filling is complete.

For this, you need to add a new condition route which checks to see if a parameter has been filled.

This is the full definition of the condition route

Debugging tip

When you use ngrok to debug your webhook, I recommend dumping the json into a file. This way, you can also inspect the full JSON object which is sent to the webhook.

@app.route('/webhook', methods=['POST'])
def hello_webhook():
    req = request.get_json(silent=True, force=True)
    with open('data.json', 'w', encoding='utf-8') as f:
        json.dump(req, f, ensure_ascii=False, indent=4)
    return {
        'fulfillmentText': 'Hello from webhook'
    }

This is the JSON object sent to the webhook after the partial slot (fromCity) is filled

{
    "detectIntentResponseId": "ef525705-c953-4fe3-b3e3-d4cd85448ce6",
    "pageInfo": {
        "currentPage": "projects/*/locations/global/agents/*/flows/00000000-0000-0000-0000-000000000000/pages/af7f2b8e-4793-4d2c-aabf-8b095d36c6e7",
        "formInfo": {
            "parameterInfo": [
                {
                    "displayName": "fromCity",
                    "required": true,
                    "state": "FILLED",
                    "value": "Seattle",
                    "justCollected": true
                },
                {
                    "displayName": "toCity",
                    "required": true,
                    "state": "EMPTY"
                },
                {
                    "displayName": "departureDate",
                    "required": true,
                    "state": "EMPTY"
                },
                {
                    "displayName": "returnDate",
                    "required": true,
                    "state": "EMPTY"
                },
                {
                    "displayName": "numPassengers",
                    "required": true,
                    "state": "EMPTY"
                },
                {
                    "displayName": "flightclass",
                    "required": true,
                    "state": "EMPTY"
                }
            ]
        },
        "displayName": "collectParams"
    },
    "sessionInfo": {
        "session": "projects/*/locations/global/agents/*/sessions/3fc1e0-ef4-752-cc0-cbd2f991a",
        "parameters": {
            "fromcity": "Seattle"
        }
    },
    "fulfillmentInfo": {
        "tag": "from_city"
    },
    "text": "from Seattle",
    "languageCode": "en"
}

And this is the JSON object sent to the webhook after all the slots are filled (i.e. the condition route for $page.params.status=FINAL

{
    "detectIntentResponseId": "650b55af-3249-4a54-b866-e8fbbbd410b9",
    "pageInfo": {
        "currentPage": "projects/*/locations/global/agents/*/flows/00000000-0000-0000-0000-000000000000/pages/af7f2b8e-4793-4d2c-aabf-8b095d36c6e7",
        "formInfo": {
            "parameterInfo": [
                {
                    "displayName": "fromCity",
                    "required": true,
                    "state": "FILLED",
                    "value": "Seattle"
                },
                {
                    "displayName": "toCity",
                    "required": true,
                    "state": "FILLED",
                    "value": "Las Vegas"
                },
                {
                    "displayName": "departureDate",
                    "required": true,
                    "state": "FILLED",
                    "value": {
                        "year": 2022.0,
                        "month": 6.0,
                        "day": 20.0
                    }
                },
                {
                    "displayName": "returnDate",
                    "required": true,
                    "state": "FILLED",
                    "value": {
                        "year": 2022.0,
                        "month": 6.0,
                        "day": 25.0
                    }
                },
                {
                    "displayName": "numPassengers",
                    "required": true,
                    "state": "FILLED",
                    "value": 2.0
                },
                {
                    "displayName": "flightclass",
                    "required": true,
                    "state": "FILLED",
                    "value": "economy",
                    "justCollected": true
                }
            ]
        },
        "displayName": "collectParams"
    },
    "sessionInfo": {
        "session": "projects/*/locations/global/agents/*/sessions/3fc1e0-ef4-752-cc0-cbd2f991a",
        "parameters": {
            "departuredate": {
                "year": 2022.0,
                "month": 6.0,
                "day": 20.0
            },
            "flightclass": "economy",
            "fromcity": "Seattle",
            "numpassengers": 2.0,
            "returndate": {
                "year": 2022.0,
                "month": 6.0,
                "day": 25.0
            },
            "tocity": "Las Vegas"
        }
    },
    "fulfillmentInfo": {
        "tag": "all_params"
    },
    "messages": [
        {
            "text": {
                "text": [
                    "Your flight details:nFrom: SeattlenTo: Las VegasnLeaving on: 2022-06-20nReturning on: 2022-06-25nNumber of passengers: 2nFlight class: economy"
                ],
                "redactedText": [
                    "Your flight details:nFrom: SeattlenTo: Las VegasnLeaving on: 2022-06-20nReturning on: 2022-06-25nNumber of passengers: 2nFlight class: economy"
                ]
            },
            "responseType": "HANDLER_PROMPT",
            "source": "VIRTUAL_AGENT"
        },
        {
            "text": {
                "text": [
                    "Confirm (Yes/No)?"
                ],
                "redactedText": [
                    "Confirm (Yes/No)?"
                ]
            },
            "responseType": "HANDLER_PROMPT",
            "source": "VIRTUAL_AGENT"
        }
    ],
    "text": "economy",
    "languageCode": "en"
}


About this website

I created this website to provide training and tools for non-programmers who are building Dialogflow chatbots.

I have now changed my focus to Vertex AI Search, which I think is a natural evolution from chatbots.

Note

BotFlo was previously called MiningBusinessData. That is why you see that watermark in many of my previous videos.

Leave a Reply