0

我正在通过 dialogflow、google 日历和 voximplant 开发语音助手。我在履行代码中遇到问题,因为我不知道为什么,但我在诊断信息中不断收到此错误,以及控制台日志中的一系列错误。有人知道如何帮我一把吗?

我将在下面发布代码:

// See https://github.com/dialogflow/dialogflow-fulfillment-nodejs
// for Dialogflow fulfillment library docs, samples, and to report issues
'use strict';

 const functions = require('firebase-functions');
 const {google} = require('googleapis');
 const {WebhookClient} = require('dialogflow-fulfillment');
 
 // Enter your calendar ID below and service account JSON below
const calendarId = 'c_d86ppgn4qqpmfpq1cjd2higja8@group.calendar.google.com'; 
const serviceAccount = {
  "type": "service_account",
  "project_id": "italians-do-it-better",
  "private_key_id": "xxxxxxxxxxxx",
  "private_key": "-----BEGIN PRIVATE KEY-----\nxxxxxxxxxx\n-----END PRIVATE KEY-----\n",
  "client_email": "xxxxxxxxxx@italians-do-it-better.iam.gserviceaccount.com",
  "client_id": "xxxxxxxxxxx",
  "auth_uri": "https://accounts.google.com/o/oauth2/auth",
  "token_uri": "https://oauth2.googleapis.com/token",
  "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
  "client_x509_cert_url": "https://www.googleapis.com/robot/v1/metadata/x509/appointmentscheduler%40italians-do-it-better.iam.gserviceaccount.com"
};

 const serviceAccountAuth = new google.auth.JWT({
   email: serviceAccount.client_email,
   key: serviceAccount.private_key,
   scopes: 'https://www.googleapis.com/auth/calendar'
 });
 
 const calendar = google.calendar('v3');
 process.env.DEBUG = 'dialogflow:*'; // enables lib debugging statements
 
 const timeZone = 'Europe/Kaliningrad';
 const timeZoneOffset = '+02:00';
 
 exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
   const agent = new WebhookClient({request, response});
   console.log("Parameters", agent.parameters);
   const appointment_type = "Default";
         //agent.parameters.AppointmentType;
   
   function makeAppointment (agent) {
     // Calculate appointment start and end datetimes (end = +1hr from start)
     console.log("Parameters", agent.parameters.date);
     
     //Variabili più calcolo orario
     const guests = agent.parameters.guests;
     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));
     console.log("date start ", dateTimeStart, " date end ", dateTimeEnd);
     
     const date = new Date(agent.parameters.date);
     const bookingDate = new Date(date);
     
     const phonenumber = agent.parameters.phonenumber;
     let name = agent.parameters.name;
     const email = agent.parameters.email;
     var phone = phonenumber.toString().length;
     const now = new Date();
     
     const appointmentTimeString = dateTimeStart.toLocaleString( 'en-US', {timeZone:'Europe/Kaliningrad'});
     
     if (guests < 1){
       agent.add(`You need to reserve a table for at least one person. Please try remaking the reservation!`);
     } 
     else if (guests > 100){
       agent.add(`You can't make a reservation for more than 100 guests. Please try remaking the reservation!`);
     }else if (dateTimeStart < now){
       agent.add(`You can't make a reservation in the past. Please try remaking the reservation.`);
      } 
     else if (bookingDate.getFullYear() > now.getFullYear()) {
       agent.add(`You can't make a reservation for ${bookingDate.getFullYear()} yet. Please choose a date in ${now.getFullYear()}.`);
     }
     else if (phone != 10) {
       agent.add(`Your phone number has to be atleast 10 digits. Please try remaking the reservation!`);
     } else {     
     console.log("appointmentTimeString: ", appointmentTimeString);
     
     // Check the availibility of the time, and make an appointment if there is time on the calendar
     return createCalendarEvent(dateTimeStart, dateTimeEnd, guests, name, phonenumber, email, appointment_type).then(() => {
       agent.add(`Ok, let me see if we can fit you in. ${appointmentTimeString} is fine!.`);
     }).catch(() => {
       agent.add(`I'm sorry, there are no slots available for ${appointmentTimeString}.`);
     });
   }  
   let intentMap = new Map();
   intentMap.set('collectIncorrectValues', makeAppointment);
   intentMap.set('ScheduleAppointment.yes', makeAppointment);
   agent.handleRequest(intentMap);
   }});
 
 function createCalendarEvent (dateTimeStart, dateTimeEnd, guests, name, phonenumber, email, appointment_type) {
   const appointmentTimeString = dateTimeStart.toLocaleString( 'en-US', {timeZone:'Europe/Kaliningrad'});
   return new Promise((resolve, reject) => {
     calendar.events.list({
       auth: serviceAccountAuth, // List events for time period
       calendarId: calendarId,
       timeMin: dateTimeStart.toISOString(),
       timeMax: dateTimeEnd.toISOString()
     }, (err, calendarResponse) => {
       // Check if there is a event already on the Calendar
       if (err || calendarResponse.data.items.length > 0) {
         reject(err || new Error('Requested time conflicts with another appointment'));
       } else {
         // Create event for the requested time period
         calendar.events.insert({ auth: serviceAccountAuth,
           calendarId: calendarId,
           resource: {summary: 'Appointment: '+ appointment_type +' Appointment ', description: appointmentTimeString +',\n Name: ' + name + ',\n Guests: '+ guests + ',\n Phonenumber: ' + phonenumber + ',\n Email: ' +email,
             start: {dateTime: dateTimeStart},
             end: {dateTime: dateTimeEnd}}
         }, (err, event) => {
           err ? reject(err) : resolve(event);
                 }
         );
       }
     });
   });
 }

包.json:

{
  "name": "dialogflowFirebaseFulfillment",
  "description": "This is the default fulfillment for a Dialogflow agents using Cloud Functions for Firebase",
  "version": "0.0.1",
  "private": true,
  "license": "Apache Version 2.0",
  "author": "Google Inc.",
  "engines": {
    "node": "10"
  },
  "scripts": {
    "start": "firebase serve --only functions:dialogflowFirebaseFulfillment",
    "deploy": "firebase deploy --only functions:dialogflowFirebaseFulfillment"
  },
  "dependencies": {
    "actions-on-google": "^2.2.0",
    "firebase-admin": "^5.13.1",
    "firebase-functions": "^2.0.2",
    "dialogflow": "^0.6.0",
    "dialogflow-fulfillment": "^0.5.0"
  }
}

控制台日志错误:

控制台日志 控制台日志 控制台日志 控制台日志

对话流错误: 对话流错误 对话流错误

控制台日志错误:

{
  "textPayload": "Error: No handler for requested intent\n    at WebhookClient.handleRequest (/workspace/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:317:29)\n    at exports.dialogflowFirebaseFulfillment.functions.https.onRequest (/workspace/index.js:89:10)\n    at cloudFunction (/workspace/node_modules/firebase-functions/lib/providers/https.js:57:9)\n    at process.nextTick (/layers/google.nodejs.functions-framework/functions-framework/node_modules/@google-cloud/functions-framework/build/src/invoker.js:100:17)\n    at process._tickCallback (internal/process/next_tick.js:61:11)",
  "insertId": "000000-9adc6f24-bfa5-469b-ae82-5f4124522534",
  "resource": {
    "type": "cloud_function",
    "labels": {
      "function_name": "dialogflowFirebaseFulfillment",
      "region": "us-central1",
      "project_id": "italians-do-it-better"
    }
  },
  "timestamp": "2021-07-13T08:31:30.209Z",
  "severity": "ERROR",
  "labels": {
    "execution_id": "v9ps952et2kk"
  },
  "logName": "projects/italians-do-it-better/logs/cloudfunctions.googleapis.com%2Fcloud-functions",
  "trace": "projects/italians-do-it-better/traces/f4d789b9c84aaf5bb311c9332f125ca8",
  "receiveTimestamp": "2021-07-13T08:31:30.716907289Z"
}
4

0 回答 0