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 webhookYou can use webhooks to add custom business logic in both Di... More 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 parameterBoth ES and CX support the concept of parameters. If entitie... More 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"
}
Note: This is my old website and is in maintenance mode. I am publishing new articles only on my new website.
If you are not sure where to start on my new website, I recommend the following article:
Is Dialogflow still relevant in the era of Large Language Models?