简体   繁体   English

DialogFlow Python3 Webhook - 增加超时?

[英]DialogFlow Python3 Webhook - Increase Timeout?

I have a DialogFlow Intent that manages to parse the user's query about an item price.我有一个 DialogFlow Intent 可以解析用户对商品价格的查询。 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.例如,用户询问“一罐沙丁鱼多少钱?”,我的 DialogFlow 能够得到“一罐沙丁鱼”作为用户输入。

Once it get's that, it would proceed to fulfilment where it would send a POST request to a WebHook I have.一旦得到它,它将继续执行,它将向我拥有的 WebHook 发送 POST 请求。 I linked the Fulfilment to my local Python3 Flask App through ngrok.com .我通过ngrok.com将 Fulfillment 链接到我本地的 Python3 Flask 应用程序。

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.现在,我的 Python 应用程序所做的是接收用户输入(沙丁鱼罐头),并使用PDFGrep通过服务器中价目表的 PDF 查找用户输入。 The pricelist has 3 columns: product code, product name, product price.价格表有 3 列:产品代码、产品名称、产品价格。 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.这意味着如果“沙丁鱼罐头”出现 3 次,将显示行线。

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.但是,该文件相当大,大约有 348 页的项目。 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.所以发生的情况是我的pdfgrep命令需要一些时间来产生输出,但据我所知,DialogFlow 似乎期望服务器在给定的短时间内响应来自它的 POST 请求。

Is there a way to adjust the timeout of the Webook for the DialogFlow API?有没有办法为DialogFlow API调整Webook的超时时间?

There is no way of increasing this timeout because it would spoil the conversation experience of the user ie 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.您可以做的是,向您正在检查价格的用户发送响应,然后一旦您从数据库中获取数据,您就使用 POST 请求向客户端发送另一个回复。

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 Dialogflow webhooks 的超时时间为 5 秒。您可以通过链接 Intent 来增加超时时间,也就是说,您可以使用一个 Intent 作为另一个 Intent 的触发器(可以给您 5+5 秒的时间来发送响应)在此代码中,当actual_intent 被击中,它会将它重定向到 demo_intent,其中有一个名为 demo_event 的事件可能是您可以将多处理与线程模块一起用于时间任务,相应地调整睡眠时间

    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"
                             ]
                         }
                     },
                       ]
                 }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM