0

I want to connect Realtime database firebase with Dialogflow chatbot and how to get some data from Realtime database firebase using Dialogflow. I want when the user ask my chatbot to show the machine water quantity then chatbot will ask for the machine id of which you want to know water quantity, then chatbot access the realtime database firebase to check if the machine is present in database then it will show the water quantity of that machine.

I have tried to connect realtime database firebase this way-

'use strict';
 
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');

const firebaseAdmin=require("firebase-admin");

process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements

 firebaseAdmin.initializeapp({
 credential:firebaseAdmin.credential.applicationDefault(),
 databaseURL:"ws://rtdb.asia-southeast1.firebasedatabase.app/",
 });


exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
  const agent = new WebhookClient({ request, response });
  console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
  console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
 
  function welcome(agent) {
    agent.add(`Welcome to Akvo chat!`);
  }
 
  function fallback(agent) {
    agent.add(`I didn't understand`);
    agent.add(`I'm sorry, can you try again?`);
  }
  
//function getFromFirebase(agent){
//return firebaseAdmin.database().ref("board_id").once("value", snapshot=>{
//var boardid=snapshot.val();
  //agent.add(boardid);
//});
//}
 
 
  // Run the proper function handler based on the matched Dialogflow intent name
  let intentMap = new Map();
  intentMap.set('Default Welcome Intent', welcome);
  intentMap.set('Default Fallback Intent', fallback);
 //intentMap.set('board id', getFromFirebase);
  agent.handleRequest(intentMap);
});

But it shows an error.

Error: " Error happened during Cloud Functions Deployment "

can you please tell me how to do this.

Akvo
  • 3
  • 2

0 Answers0