Dialogflow BikeShop部署不起作用的那些

问题描述 投票:0回答:1

我查看了针对此错误找到的每个答案,并尝试了解决方案,但是很遗憾,我没有找到任何东西。因此,无论发生此错误的原因为何,我都会很高兴给出答案。

我已完全从完成的BikeShop中取得的所有东西都放在https://github.com/dialogflow/fulfillment-bike-shop-nodejs下:我唯一更改的是将API从v2更改为v1。

我已经创建了日历,但是如果现在部署了实现,则只能在Firebase上获得答案:警告,根据GCLOUD_PROJECT估算Firebase的配置。初始化firebase-admin可能会失败

我对一个有用的答案非常满意:)

我的代码:

index.js:

 **
 * Copyright 2017 Google Inc. All Rights Reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

'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, see https://github.com/dialogflow/bike-shop/blob/master/README.md#calendar-setup
const calendarId = '[email protected]'; // looks like "[email protected]"
const serviceAccount = {
  "type": "service_account",
  "project_id": "bikeshopsample-60b67",
  "private_key_id": "eece28a19c41a3ec9c53773873d37e51485c6956",
  "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQC1K7cPHY7t2zOJ\nYCSjE41+imEoInIbJJCF57/W4624wmhoucJpPagCq38RcREoup6oODrdfDai3/zR\n7bym4EetlfSmcmLIiSbctVCVlbNtL0YZevZKvTQVId6HQoVPEgEE76y3/Hkbe/lH\n3/QWNNiCwK7tWiAo2mQE1+AQiIpl9E7y8zViQ5QN9A8BW3YJDr4ZoxTlI3tY1x4P\nmsD9bladpGyPS3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iPVaXCcN8bGU0Ah8jx2v3CWSAyZ//9jhND8\n5cagA+VG3wu3xNeGijv4xOOPWgWX5IncPTqUVi+K0QLvR1OirT8thuEvVfXnfSd0\nVgclIEJm8Dt1U+4428ABxDa37pjeK243sOgTvq+stQKBgQDhgrHZDhaLt2VTg1T9\norwRvovUaTthievRLnBjvHYJbeph1VsUh9XX6m9jrDB4cFYNriY4l92cU5oC6c+T\nvZ0ZiYqs+E3AoBvpR8iQEZPR2bL++O//8zp7Zm7mCD0csIHGq6bjzV7R8cEY5ZwZ\nFM+r0SjiHxl1CeQ+yfMNsm3gcQ==\n-----END PRIVATE KEY-----\n",
  "client_email": "[email protected]",
  "client_id": "117495070361998279022",
  "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/bike-shop-calendar%40bikeshopsample-60b67.iam.gserviceaccount.com"
}; // Starts with {"type": "service_account",...

// 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:*'; // enables lib debugging statements

const timeZone = 'Germany/Berlin';
const timeZoneOffset = '+01:00';

exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
  const agent = new WebhookClient({ request, response });

  function hours (agent) {
    if (currentlyOpen()) {
      agent.add(`We're open now! We close at 5pm today.`);
    } else {
      agent.add(`We're currently closed, but we open every weekday at 9am!`);
    }
  }

  function makeAppointment (agent) {
    // Calculate appointment start and end datetimes (end = +1hr from start)
    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 appointmentTimeString = dateTimeStart.toLocaleString(
      'en-US',
      { month: 'long', day: 'numeric', hour: 'numeric', timeZone: timeZone }
    );

    // Check the availibility of the time, and make an appointment if there is time on the calendar
    return createCalendarEvent(dateTimeStart, dateTimeEnd).then(() => {
      agent.add(`Ok, let me see if we can fit you in. ${appointmentTimeString} is fine!. Do you need a repair or just a tune-up?`);
    }).catch(() => {
      agent.add(`I'm sorry, there are no slots available for ${appointmentTimeString}.`);
    });
  }

  let intentMap = new Map();
  intentMap.set('Hours', hours);
  intentMap.set('Make Appointment', makeAppointment);
  agent.handleRequest(intentMap);
});

function currentlyOpen () {
  // Get current datetime with proper timezone
  let date = new Date();
  date.setHours(date.getHours() + parseInt(timeZoneOffset.split(':')[0]));
  date.setMinutes(date.getMinutes() + parseInt(timeZoneOffset.split(':')[0][0] + timeZoneOffset.split(':')[1]));

  return date.getDay() >= 1 &&
        date.getDay() <= 5 &&
        date.getHours() >= 9 &&
        date.getHours() <= 17;
}

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) => {
      // Check if there is a event already on the Bike Shop 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: 'Bike Appointment',
            start: {dateTime: dateTimeStart},
            end: {dateTime: dateTimeEnd}}
        }, (err, event) => {
          err ? reject(err) : resolve(event);
        }
        );
      }
    });
  });
}

package.json:

{
  "name": "dialogflowFirebaseFulfillment",
  "description": "Dialogflow fulfillment for the bike shop sample",
  "version": "0.0.1",
  "private": true,
  "license": "Apache Version 2.0",
  "author": "Google Inc.",
  "engines": {
    "node": "6"
  },
  "scripts": {
    "lint": "semistandard --fix \"**/*.js\"",
    "start": "firebase deploy --only functions",
    "deploy": "firebase deploy --only functions"
  },
  "dependencies": {
    "firebase-functions": "2.0.2",
    "firebase-admin": "^5.13.1",
    "actions-on-google": "2.2.0", 
    "googleapis": "^27.0.0",
    "dialogflow-fulfillment": "0.5.0"
  }
}
firebase google-calendar-api dialogflow
1个回答
0
投票

劳斯莫夫。我从https://github.com/dialogflow/fulfillment-bike-shop-nodejs创建了一个自己的代理,并尝试了它,但对我来说不起作用。我无法启动代理并仅从默认后备意图获得答案。您如何激活它?

© www.soinside.com 2019 - 2024. All rights reserved.