Giter VIP home page Giter VIP logo

fulfillment-firestore-nodejs's Introduction

Dialogflow Firestore Sample

  • This sample demonstrates how to connect Dialogflow to the Firestore database.
  • Dialogflow parses users' requests and sends requests to Firebase function indicating whether it should add or retrieve an entry from the Firestore database. The Firebase function queries the database to add or retrieve the entry and then compiles the proper response to the user. You can speak to your Dialogflow agent and tell it to write something to the database or retrieve it.
  • The sample will save what you tell it to save into the database as well as retrieve the value you store previously.
  • When you speak to your Dialogflow agent a webhook call is sent to Firebase functions which talks to the Firestore database to retrieve or add a entry as see below:

This sample is meant to be a starting point for anyone looking to connect a database to their Dialogflow agent and can be expanded to store users preferences, retrieve relevant data from your systems or enable your users to collaborate via chat/voice.

Dialogflow → Webhook Request → Firebase Function → Firestore Database

Setup

Dialogflow and Fulfillment Setup

To create this agent from our template:

Firestore Setup

  1. In Dialogflow's console, in the left menu > go to Fulfillment > Enable Inline Editor > Deploy.
  2. At the bottom, go to View execution logs in the Firebase console.
  3. In the Firebase console, go to Database > Create database.
  4. Select Start in locked mode > Enable.

Running the sample

  1. In Dialogflow's console, in the Dialogflow simulator on the right, query your Dialogflow agent with Write Buzz Aldrin to the database and then query What's in the database? to get the response "Buzz Aldrin".

Related Samples

Name Language
Fulfillment & Regex Validation Node.js
Weather: Fulfillment & WWO API Node.js
Bike Shop: Fulfillment & Google Calendar API Node.js
Temperature Trivia: Fulfillment & Actions on Google Node.js
Fulfillment & Actions on Google Node.js
Fulfillment & Firestore Database Node.js
Multi-language/locale Node.js
Basic Slot Filling Node.js

For Fulfillment Webhook JSON Requests & Responses.

References & Issues

How to make contributions?

Please read and follow the steps in the CONTRIBUTING.md.

License

See LICENSE.

Terms

Your use of this sample is subject to, and by using or downloading the sample files you agree to comply with, the Google APIs Terms of Service.

fulfillment-firestore-nodejs's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

fulfillment-firestore-nodejs's Issues

Unable to link

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

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

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)

Dialogflow fulfilment Webhook timeout on Firestore save and read

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."
}
}

Collection Querying with DialogFlow

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.

how to write in a certain uid of user

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.