Sunday, April 30, 2023

Using async in inline Editor of GCP Dialogflow. But, timeout too short.

 


Using async in inline Editor of GCP Dialogflow 

/* experimental: [asyncawait] */

https://stackoverflow.com/questions/42637630/does-jshint-support-async-await/48772304#48772304


to know queryText from the user

https://stackoverflow.com/questions/60408929/how-do-you-read-query-the-response-body-in-api-v2-of-dialogflow-fulfillment


function handleRequest(request, response) { const queryText = request.body.queryResult.queryText; // use the queryText variable to process the user's input }


sample code (without async)

https://github.com/priyankavergadia/AppointmentScheduler-GoogleCalendar/blob/master/index.js


Dialogflow CX timeout only 30 sec

Dialogflow ES timeout only 15 sec

https://groups.google.com/g/dialogflow-cx-edition-users/c/jajSEPqhYZE


Following code didn't work.

  async function answerQuestion(agent) {

    const response = await axios.post(

...    {

      message: JSON.stringify(request.body.queryResult.queryText)

    },

    {

      headers: { 'Content-Type': 'application/json' },

      timeout: 2 * 60 * 1000

    }

    );

    agent.setContext({ name: "Question", result: response });

    agent.add(`${response.data.data.answer} \n\n ${response.data.data.sources}`);

  }