|
đ
Get Your First AI Automation FREE
Limited-time offer for qualified businesses.
|
In Dialogflow you can create agent responses in two ways first âstaticâ response by adding details in the console itself for the basic functionality and second is a dynamic response by managing Fulfillment through the web service called webhook service. You can create a more complex and flexible conversation flow by webhook service.
For Dialogflow, webhook service needs to accept JSON requests and return JSON response as per specified guidelines by Dialogflow.
In the Dialogflow documentation, there are some limitations given to send your webhook response.
If the above limitations are not fulfilled then the webhook request will time out and give the error: âWebhook call failed. Error: DEADLINE_EXCEEDEDâ, which you can see in Fulfillment status.
As per Dialogflow guidelines given for the âcustom eventâ which can be invoked for time alert during in conversation. This event could help to trigger an intent which alerts the end-user. We are using the concept of the âcustom eventâ for time alert to extend the webhook deadline.
By creating âcustom eventâ we are managing time such that it cannot increase the given guideline âtime limitationâ for the webhook response (Technically we have 5 seconds time limits per intent to manage the timing). For that, we need to set up the webhook response for âfollowupEventInputâ(Click here to check the âfollowupEventInputâ JSON response). When âfollowupEventInputâ is set for the webhook response, Dialogflow ignores all other fields of response as given in Dialogflow documentation.
Here we extend time up to 10 seconds by creating a chain of two âfollowupEventInputâ for the welcome intent. Follow the below instruction to implement it.
sudo apt install virtualenv
virtualenv followup_env --python=python3
source followup_env/bin/activate
pip install Flask
pip install DateTime
You can find the code snippet for extending the webhook deadline in this GitHub repository:Â extend-dialogflow-webhook-deadline-time
Basically, in the code, we are creating a chain of two âfollowupEventInputâ for âwelcome intentâ means total three intents are created one âwelcome intentâ and two intents for the âfollowupEventinputâ. From the last intent, we have got the webhook response if it accurately works.
We are making one condition by comparing the current time with the extended time of 3 seconds for generating a normal webhook response and managing per intent calling time. And then we break this condition by adding a time delay of 3.5 seconds per intents so that âfollowupâ event occurs for a particular intent. You can also play with the command âtime.sleep()â to increase delay, but for us, it accurately works for the value of 3.5 seconds.
Sign-in into Dialogflow console and create a new agent. Give the Agent name as you like. You will find the below screen for the new agent:
Now click on âDefault Welcome Intentâ enable webhook response as shown in the below screenshot:
Create a first intent followup_event by filling below details. In that details the event name set inside the code and Action and parameters value we are using in code for making the condition.
Create other intent for followup event number 2 by giving below details as shown in the screenshots.
./ngrok http 5000
Now run the code snippet for extending the webhook deadline in the command terminal.
By testing in Simulator with âhiâ you will find the below screen for Dialogflow.
By clicking on âDIAGNOSTIC INFOâ and in that âRAW API responseâ you will find accumulated webhook latency time near 13 seconds as shown in the below screen. Sometimes if latency time for webhook per intent is larger than 5 seconds then output may not come from webhook for the followup event.
By using followup events we can extend the webhook deadline limit.