Несколько записей даты - PullRequest
1 голос
/ 20 июня 2019

Вот некоторые изображения для намерений и увлечений

enter image description here

enter image description here

* +1012 *enter image description here

enter image description here

enter image description here

Я собираю даты от пользователей для создания событий календаря Google, но как только я добавляю код для второй даты, даже если он не используется, он не работает ни для одной из обеих дат выдает эту ошибку в базе данных:

TypeError: Невозможно прочитать свойство split из undefined at exports.dialogflowFirebaseFulfillment.functions.https.onRequest (/srv/index.js:38:68) в cloudFunction (/srv/node_modules/firebase-functions/lib/providers/https.js:37:41) на /worker/worker.js:783:7 в /worker/worker.js:766:11 в _combinedTickCallback (внутренняя / process / next_tick.js: 132: 7) at process._tickDomainCallback (internal / process / next_tick.js: 219: 9)

Это мой код

   function makeAppointment2 (agent) {
   const dateTimeStart = new Date(Date.parse(agent.parameters.date.split('T')[0] + 'T' + agent.parameters.time.split('T')[1].split('+')[0] + timeZoneOffset));
   const dateTimeEnd = new Date(new Date(dateTimeStart).setHours(dateTimeStart.getHours() + 1));
   const dateTimeStart2 = new Date(Date.parse(agent.parameters.date2.split('T')[0] + 'T' + agent.parameters.time2.split('T')[1].split('+')[0] + timeZoneOffset));
   const dateTimeEnd2 = new Date(new Date(dateTimeStart2).setHours(dateTimeStart2.getHours() + 1));
   const appointmentTimeString = dateTimeStart.toLocaleString(
     'en-US',
     { month: 'long', day: 'numeric', hour: 'numeric', timeZone: timeZone }
   );
   const appointmentTimeString2 = dateTimeStart2.toLocaleString(
     'en-US',
     { month: 'long', day: 'numeric', hour: 'numeric', timeZone: timeZone }
   );
   return createCalendarEvent2(dateTimeStart, dateTimeEnd, name, location, dateTimeStart2, dateTimeEnd2).then(() => {
     agent.add(`Great Mr/Mrs ${name}, your appointment has been scheduled on ${appointmentTimeString} & ${appointmentTimeString2}!.`);
     agent.add(`${response2}`);
   }).catch(() => {
     agent.add(`I'm sorry Mr/Mrs ${name}, there are no slots available for ${appointmentTimeString} Please choose another date.`);
   });
 function createCalendarEvent2 (dateTimeStart, dateTimeEnd, appointment_name, location, dateTimeStart2, dateTimeEnd2) {
  return new Promise((resolve, reject) => {
    calendar.events.list({
      auth: serviceAccountAuth,
      calendarId: calendarId,
      timeMin: dateTimeStart.toISOString(),
      timeMax: dateTimeEnd.toISOString()
    }, (err, calendarResponse) => {

      if (err || calendarResponse.data.items.length > 0) {
        reject(err || new Error('Requested time conflicts with another appointment'));
      } else {

        calendar.events.insert({ auth: serviceAccountAuth,
          calendarId: calendarId,
          resource: {
   'summary': appointment_name + "1st" ,
   'description': location,
   'start': {
     'dateTime': dateTimeStart,
   },
   'end': {
     'dateTime': dateTimeEnd,
   },
 } ,
        }, (err, event) => {
          err ? reject(err) : resolve(event);
        }
        );
      }
    });
    calendar.events.list({
      auth: serviceAccountAuth,
      calendarId: calendarId,
      timeMin: dateTimeStart2.toISOString(),
      timeMax: dateTimeEnd2.toISOString()
    }, (err, calendarResponse) => {

      if (err || calendarResponse.data.items.length > 0) {
        reject(err || new Error('Requested time conflicts with another appointment'));
      } else {

        calendar.events.insert({ auth: serviceAccountAuth,
          calendarId: calendarId,
          resource: {
   'summary': appointment_name + "2nd" ,
   'description': location,
   'start': {
     'dateTime': dateTimeStart2,
   },
   'end': {
     'dateTime': dateTimeEnd2,
   },
  } ,
        }, (err, event) => {
          err ? reject(err) : resolve(event);
        }
        );
      }
    });

  });

1 Ответ

0 голосов
/ 20 июня 2019

Я бы предложил извлечь такие параметры в вашем исполнении:

 function botHandler(agent) {
        let state = agent.parameters["stateName"];
        let uState = state.toUpperCase();
        let answer = "So you live in " + uState + "?";

        agent.add(answer);
    }

И вы можете проверить, присутствует ли параметр следующим образом:

if (agent.parameters["stateName"]) {
    //do stuff here
}

Я думаю, что он разбился, потому что не было никаких намерений.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...