Dialogflow Webhook错误和日期解析错误

时间:2019-07-17 07:49:09

标签: json dialogflow-fulfillment

intent我收到了'Webhook呼叫失败。错误:“诊断信息”下“实现状态”中对话框流的消息“ 500 Internal Server Error”消息。 GCP堆栈驱动程序错误日志中的错误是:“错误:没有用于请求意图的处理程序”和“ TypeError:agent.parameters.date.split不是函数”。如果您可以在此处建议对我的代码进行更改以进行纠正,将不胜感激。谢谢

[Intent1 意图2 Intent3

'use strict';

const functions = require('firebase-functions');
const {google} = require('googleapis');
const {WebhookClient} = require('dialogflow-fulfillment');

// Enter your calendar ID and service account JSON below.
const calendarId = 
const serviceAccount = {

// Set up Google Calendar service account credentials
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:*'; // It enables lib debugging 
statements

const timeZone = 'Asia/Shanghai';  // Change it to your time zone
const timeZoneOffset = "+8:00";

exports.dialogflowFirebaseFulfillment = 
functions.https.onRequest((request, response) => {
const agent = new WebhookClient({request, response});
console.log("Parameters", agent.parameters);
function makeAppointment (agent) {

const dateTimeStart = new 
Date(Date.parse(agent.parameters.date.split('T')[0] + 'T' + 
agent.parameters.time + timeZoneOffset));
const dateTimeEnd = new Date(new 
Date(dateTimeStart).setHours(dateTimeStart.getHours() + 1));
const appointmentTimeString = dateTimeStart.toLocalString(
'en-US',
{ month: 'long', day: 'numeric', hour: 'numeric', timeZone: timeZone }
);
return createCalendarEvent(dateTimeStart, dateTimeEnd).then(() => {
  agent.add(`Got it. I have your appointment scheduled on ${appointmentTimeString}. See you soon. Good-bye.`);
}).catch(() => {
  agent.add(`Sorry, something went wrong. I couldn't book the ${appointmentTimeString}. Is there anything else I can help you with?`);
});
}
let intentMap = new Map();
intentMap.set('makeAppointment', makeAppointment);
agent.handleRequest(intentMap);
});

function createCalendarEvent (dateTimeStart, dateTimeEnd) {
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) => {
  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: 'Meet & Greet Appointment - Sales Team',
        start: {dateTime: dateTimeStart},
        end: {dateTime: dateTimeEnd}}
    }, (err, event) => {
      err ? reject(err) : resolve(event);
    }
    );
  }
});
});
}

**// Error from GCP Stack log**
Error: No handler for requested intent
at WebhookClient.handleRequest (/srv/node_modules/dialogflow- 
fulfillment/src/dialogflow-fulfillment.js:327)
at exports.dialogflowFirebaseFulfillment.functions.https.onRequest 
(index.js:70)
at cloudFunction (/srv/node_modules/firebase- 
functions/lib/providers/https.js:57)
at (/worker/worker.js:783)
at (/worker/worker.js:766)
at _combinedTickCallback (internal/process/next_tick.js:132)
at process._tickDomainCallback (next_tick.js:219)


TypeError: agent.parameters.date.split is not a function
at makeAppointment (/srv/index.js:54)
at WebhookClient.handleRequest (/srv/node_modules/dialogflow- 
fulfillment/src/dialogflow-fulfillment.js:313)
at exports.dialogflowFirebaseFulfillment.functions.https.onRequest 
(index.js:70)
at cloudFunction (/srv/node_modules/firebase- 
functions/lib/providers/https.js:57)
at (/worker/worker.js:783)
at (/worker/worker.js:766)
at _combinedTickCallback (internal/process/next_tick.js:132)
at process._tickDomainCallback (next_tick.js:219)

0 个答案:

没有答案
相关问题