Razgriz
Razgriz

Reputation: 7343

DialogFlow Python3 Webhook - Increase Timeout?

I have a DialogFlow Intent that manages to parse the user's query about an item price. For example, the user asks "How much for a can of sardines?", my DialogFlow is able to get "can of sardines" as the user input.

Once it get's that, it would proceed to fulfilment where it would send a POST request to a WebHook I have. I linked the Fulfilment to my local Python3 Flask App through ngrok.com.

Right now, what my Python App does is it takes in the user input (can of sardines), and uses PDFGrep to look for the user input through the PDF of the pricelist that's in the server. The pricelist has 3 columns: product code, product name, product price. For each instance that the user input appears, the entire line is sent out as an output. This means that if "can of sardines" appears 3 separate times, the row lines would be shown.

An output to the console would be something like this:

10000   Can of Sardines - 6 Cans    $5.00
10001   Can of Sardines - 12 Cans   $9.00
10002   Can of Sardines - 18 Cans   $13.00

This works in the console just fine.

However, the file is rather large with about 348 pages worth of items. So what happens is that my pdfgrep command takes some time to come up with the output, but DialogFlow, from what I understand, seems to expect a server response from it's POST request within a given short amount of time.

Is there a way to adjust the timeout of the Webook for the DialogFlow API?

Upvotes: 2

Views: 363

Answers (2)

Vaisakh Gopinath
Vaisakh Gopinath

Reputation: 123

Dialogflow webhooks have a timeout of 5 seconds.You can increase timeout by chaining intents,that is you can use an intent as a trigger to another intent(which can give you 5+5 seconds to send a response) Here in this code, when actual_intent is hit it will redirect it to demo_intent which have an event called demo_event May be you can use multiprocessing with threading module for the time taking task, adjust the sleep times accordingly

    if 'action' in request_['queryResult']:
        if request_['queryResult']['action']=='actual_intent':
            time.sleep(3)
            reply={
            "followupEventInput": {
                "name": "demo_event",
                
             }
            }

            return jsonify(reply)

        if request_['queryResult']['action']=='demo_intent':
            time.sleep(3)
            reply = {
                 "fulfillmentMessages": [
                     {
                         "text": {
                             "text": [
                                 "Some message you want to show"
                             ]
                         }
                     },
                       ]
                 }

Upvotes: 0

sid8491
sid8491

Reputation: 6800

There is no way of increasing this timeout because it would spoil the conversation experience of the user i.e user would get frustrated if he has to wait for a long time for a response.
What you can do is, send a response to the user that you are checking for the prices, then once you get the data from the database you send another reply using a POST request to the client.

Upvotes: 1

Related Questions