dialogflow / fulfillment-firestore-nodejs Goto Github PK
View Code? Open in Web Editor NEWIntegrating Firebase's Firestore database with Dialogflow
License: Apache License 2.0
Integrating Firebase's Firestore database with Dialogflow
License: Apache License 2.0
I want to know code for searching and retrieving data from firebase to dialogflow?
I tried out the following fulfilment example pattern but adapted to my dataset. However, I get a webhook timeout error. The agent.add('..message..) is not executed when called within the .then (...) after the firestore read and write.
The issue comes only in Firestore and not in Firebase for an equivalent datamodel. The Firebase cloud function execution time in console log shows as about 4.5 sec in Firestore and 2.5 sec in Firebase (on a separate note, it is surprising why the execution time not in milli-sec for both Firestore and Firebase).
Example function here:
https://github.com/dialogflow/fulfillment-firestore-nodejs/blob/master/functions/index.js
Error details - pasted part of it from the 'Diagnostic Info' in dialogflow simulator:
......
"intentDetectionConfidence": 1,
"diagnosticInfo": {
"webhook_latency_ms": 5001
},
"languageCode": "en"
},
"webhookStatus": {
"code": 4,
"message": "Webhook call failed. Error: Request timeout."
}
}
Missing the setup steps below the Dialogflow portion
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) |
---|
Is there currently or will there be support for querying collections with DialogFlow?
I'm running into an issue where the query snapshot doesn't.
I'm returning
.get().then(querySnapshot => {})
with Promise.resolve/reject
.
From what I've seen (and these docs) only .collection.doc is working.
I know this is probably an issue with me not understanding the project. I am newer to this type of programming (coming from PLC programming). I have an implementation where I have an intent on Dialogflow called Start Command which has a list of commands tied to a number. The name of the action is startCommand and the parameter name is number. I have seen the attached code but am not sure what needs to be changed to allow this code to work for my implementation. I have tried switching out some of the commands and get webhook errors (no surprise). Can someone clarify what needs to be changed and what all it affects? Thanks
I am trying to implement a chatbot using dialogflow and flutter. I need to save some data from the user at different points and also return this data to the user. In this process, user's uid will play an important role as I am trying to save data from user using doc id as user's uid. So my problem is how to get user uid in dialogflow fulfillment
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.