Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

134
Vistas
Dialogflow Google Calendar integration crashing

I try to get events from a Google Calendar and pass them to my chatbot in DialogFlow.

'use strict';

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

const calendarId = "some_id";
const serviceAccount = {some_account};

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

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

    function checkAppointment (agent) {
      return check().then((value) => {
            agent.add(`yep ${value.data}`);
        }).catch(() => {
            agent.add(`I'm sorry.`);
        });
    }

    let intentMap = new Map();
    intentMap.set('CheckAppointment', checkAppointment);
    agent.handleRequest(intentMap);
});

function check(agent){
    var beginning = moment().format("YYYY-MM-DDT00:01:00Z");
    var end = moment().format("YYYY-MM-DDT23:59:00Z");
    return new Promise((resolve, reject) => { 
        calendar.events.list({
            auth: serviceAccountAuth, 
            calendarId: calendarId,
            timeMin: beginning,
            timeMax: end,
        }, (err, calendarResponse) => {
            console.log(calendarResponse.data);
            if (err || calendarResponse.data.items.length <= 0) {
                reject(err || new Error('theres nothing here'));
            } else {
                resolve(calendarResponse);
            }
        });
    });
}

Here's the log after trigerring the intent: enter image description here

It just says "crash" and therefore I have no idea what the bug could possibly be. Any ideas what to do to find out?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda