Chatbot cloud functions not connecting to Firebase/Dialogflow

39 Views Asked by At

So as a disclaimer, I'm extremely new to AI (on my first week of learning), and I've been suggested the following video to get the gist of the creation of a basic chatbot : https://www.youtube.com/watch?v=0NXqwT3Y09E. The point of this video is to create a chatbot based on Dialogflow & Firebase, using javascript Cloud Functions. I apologize for adding an external reference, but being a total beginner, I felt like I had to add it as a contingency in case I misrepresented something in the video, but I'll point later the video time where there's the most relevant informations to my problem.

Following the video roughly and guessing how some things that weren't presented explicitly in the video were done, I've encoutered some issue starting from 10:34 where the video enters "jeffd23: /dialogflow$ firebase deploy --only functions"in the Terminal.

I've tried my best to mimic the Explorer view in the video (starting from 5:47) with Visusal Studio Code : I've added a json package, the node modules and created a service acount for both Firebase and Dialogflow with the associated project.

Explorer View

The code is as following :

const functions = require('firebase-functions');
const cors = require('cors')({ origin: true});
const admin = require('firebase-admin');
const serviceAccount = require('./service-account.json');

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: "https://splendid-howl-409721-default-rtdb.firebaseio.com/"
});

const { SessionsClient } = require('dialogflow');


exports.dialogflowGateway = functions.https.onRequest((request, response) => {
  cors(request, response, async () => {
    const { queryInput, sessionId } = request.body;


    const sessionClient = new SessionsClient({ credentials: serviceAccount  });
    const session = sessionClient.sessionPath('splendid-howl-409721', sessionId);


    const responses = await sessionClient.detectIntent({ session, queryInput});

    const result = responses[0].queryResult;

    response.send(result);
  });

  const { WebhookClient } = require('dialogflow-fulfillment');

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

    const result = request.body.queryResult;


    async function userOnboardingHandler(agent) {

     // Do backend stuff here
     const db = admin.firestore();
      const newLocal = 'users';
     const profile = db.collection('users').doc('jeffd23');

     const { name, color } = result.parameters;

      await profile.set({ name, color })
      agent.add(`Welcome aboard my friend!`);
    }


    let intentMap = new Map();
    intentMap.set('UserOnboarding', userOnboardingHandler);
    agent.handleRequest(intentMap);
});
});

When I try to enter the command "jeffd23: /dialogflow$ firebase deploy --only functions" in a bash Terminal (although I'm not sure if it's the same Terminal as the video) , I get the following messasge :

Terminal Issue

I've already added the Firebase collection and document with the same name as the video, so I'm not sure what's the issue here. My first thought is that the code is somehow not connecting to Firebase.

Firestore Database

I'm aware that the question lacks precision and there might be some crucial information that I didn't mention, so please do not hesitate to indicate if it's the case.

Thanks so much in advance.

0

There are 0 best solutions below