1

Sometimes my webhook execution fails and other times not. When it fails, the request takes around 2500ms before it returns an empty response. The firebase logs show that intent is triggered and does all the calculations but fails to do agent.add() at the end. In case of successful completion of the same webhook intent, I get a response within 500 ms. I read that maybe the absence of promise could be an issue, but I have a promise too.

function findCalendarEvent(agent) {
    let x = new Promise((resolve, reject) => {
      calendar.events.list({
        auth: serviceAccountAuth, // List events for time period
        calendarId: calendarId,
        timeMin: (new Date(Date.parse(agent.parameters.date.split('T')[0] + 'T' + "00:00:00" + timeZoneOffset))).toISOString(),
        timeMax: (new Date(Date.parse(agent.parameters.date.split('T')[0].split("-")[0] + "-" + agent.parameters.date.split('T')[0].split("-")[1] + "-" + (parseInt(agent.parameters.date.split('T')[0].split("-")[2]) + 1).toString() + 'T' + "00:00:00" + timeZoneOffset))).toISOString(),
        singleEvents: true,
        orderBy: "startTime"
      }, (err, calendarResponse) => {
        console.log(calendarResponse);
        err ? reject(err) : resolve(calendarResponse);
      })
    });
    return x.then((calendarResponse) => {
      appointments = calendarResponse.data.items;
      return available_slots(appointments).then(slots => {
        console.log(slots);
        let ctx = {'name': 'appointment_time', 'lifespan': 5, 'parameters': {'date':agent.parameters.date}};
        agent.setContext(ctx);
        return agent.add(slots)
      }).catch(err => {
        return agent.add(err)
      });
    })
      .catch(err => {
        return agent.add(err)
      })
  }
Muhammad Naufil
  • 2,420
  • 2
  • 17
  • 48

0 Answers0