fulfillment-firestore-nodejs icon indicating copy to clipboard operation
fulfillment-firestore-nodejs copied to clipboard

Unable to receive date an spreadsheet API from Firebase that is connected with Dilaogflow

Open sanchit892 opened this issue 4 years ago • 0 comments

Unable to receive date an spreadsheet API from Firebase that is connected with Dilaogflow.

Here is my Index.js """ 'use strict';

const functions = require('firebase-functions'); const {WebhookClient} = require('dialogflow-fulfillment'); const {Card, Suggestion} = require('dialogflow-fulfillment'); const axios = require('axios'); const Twilio = require('twilio'); const nodemailer = require("nodemailer"); const mysql = require('mysql');

//const transporter = nodemailer.createTransport({ // service: 'gmail', //auth: { // user: 'EMAIL', //pass: 'PASSWORD' //} //});

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

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 getSpreadsheetData(){ return axios.get('https://sheetdb.io/api/v1/bzg9fw0dmp8ck'); }

function welcome(agent) { const name = agent.parameters.name; return getSpreadsheetData().then(res => { res.data.map(person => { if(person.Name === name) agent.add(Here are the details for ${name}. Gender: ${person.Gender}, Home: ${person.Home}, Subject: ${person.Subject}, Activity: ${person.Activity}); }); }); }

function fallback(agent) { agent.add(I didn't understand); agent.add(I'm sorry, can you try again?); }

function feedbackHandler(agent){ /const { name, email, phone, age } = agent.parameters;/ const { name, email, phone, text } = agent.parameters;

const data = [{
  Name: name,
  Email: email,
  Phone: phone,
  Feedback: text
}];
console.log(name);
console.log(email);
console.log(phone);
console.log(text);
return axios.post('https://sheet.best/api/sheets/76c728d6-ec36-466d-868a-504793f23dca', data)
.then(res=>{
  console.log("save success");
}).catch(err=>{
  console.log("error",err);
});

}

//function sendEmailHandler(agent){ //const { email, name } = agent.parameters;

//const mailOptions = {
  //  from: "Axlewebtech", // sender address
   // to: email, // list of receivers
   // subject: "Email from chatbot", // Subject line
   // html: `<p> Hello ${name} </p>`

// };

// transporter.sendMail(mailOptions, function (err, info) { // if(err) // { // console.log(err); // } //});

// }

// 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('feedback', feedbackHandler); //intentMap.set('sendEmail', sendEmailHandler); // intentMap.set('your intent name here', yourFunctionHandler); // intentMap.set('your intent name here', googleAssistantHandler); agent.handleRequest(intentMap); }); """

Here is package.js """ { "name": "dialogflowFirebaseFulfillment", "description": "This is the default fulfillment for a Dialogflow agents using Cloud Functions for Firebase", "version": "1.1.1", "private": true, "license": "Apache Version 2.0", "author": "Google Inc.", "engines": { "node": "8" }, "scripts": { "start": "firebase serve --only functions:dialogflowFirebaseFulfillment", "deploy": "firebase deploy --only functions:dialogflowFirebaseFulfillment" }, "dependencies": { "actions-on-google": "^2.2.0", "firebase-admin": "^5.13.1", "firebase-functions": "^2.0.2", "dialogflow": "^0.6.0", "dialogflow-fulfillment": "^0.6.1", "twilio": "3.39.3", "axios": "0.19.0", "nodemailer": "6.3.1", "mysql": "2.17.1" } } """

In firebase It's Showing this error

dialogflowFirebaseFulfillment | Function execution took 1522 ms, finished with status: 'crash'

dialogflowFirebaseFulfillment Error: No responses defined for platform: null at V2Agent.sendResponses_ (/srv/node_modules/dialogflow-fulfillment/src/v2-agent.js:243:13) at WebhookClient.send_ (/srv/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:505:17) at promise.then (/srv/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:316:38) at at process._tickDomainCallback (internal/process/next_tick.js:229:7)

sanchit892 avatar Feb 15 '20 10:02 sanchit892