Suppose there are multiple child, in that case, the data structure will change slightly. It will be something like this: data |_ 1 |_ first_name: Rahul |_ last_name: Sharma |_2 |_first_name: XYZ |_last_name: ABC You need something unique like ID (Here I used 1, 2 etc but you can use username, email or anything which is unique) to uniquely identify a record. Then the code to write into the database should be something like: return admin.database().ref("data").child(ID).set({ first_name: res.data.first_name, last_name: res.data.last_name }); Where ID can be 1, 2, 3.. and so on.... And code to read from database should be something like: return admin.database().ref("data").once("value").then((snapshot) => { const value = snapshot.child(ID).val(); const first_name = value.first_name; }
@@AxleWebTechnologies Thanks man! I was stuck in this part for a while. Your video helped me a lot. Can you please post a video on how to access Firebase cloud functions using fulfilment. I have a JSON file in the Cloud function but I'm not able to access it in Dialogflow. Please help me with this.
@@sivakarthick2924 Glad you find it useful. Will create a video on accessing Firebase cloud functions soon. Please subscribe and press the bell icon to get the updates.
Probably something wrong with the format in which you are storing your data in firebase. Have a look here: stackoverflow.com/questions/43196547/firebase-unable-to-access-data-with-snapshot
Thank you very much Sir for posting this, but when I click on enable inline editor in fulfillments it asks to manage billing and a billing account. whereas in this video you weren't asked to enable billing? Have you already enabled billing and does it charge when we connect it to firebase?
hi, I have developed the chatbot in dialogflow (which is for diabetes patients), so now I need to save data. so for that should I need to write the same code as you wrote. plsss replyyyy
Hi Kamalpreet, you dont need to write the same code. The code you will write depends on what you want to achieve. If you need any help, please drop me an email at anshul.shrivastava@axlewebtech.com
function readdb(agent) { const mobileno=agent.parameters.text; return admin.database().ref('data').transaction((data) => { const mobileno=agent.parameters.text; let mob=data.mobile; let bal=data.balance; if(mobileno==mob) { agent.add(`Your account balance is`+bal); } else { agent.add(`not register`); } return data; } ); Firebase DB data is parent child is mobile no & balance now in that i have multiple mobile no and each no have different balance then how it work?
Buenos dias, disculpe la molestia tengo un error que dice: "Webhook call failed. Error: Request timeout" esto sucede cuando trato de leer los datos. Algguien seria tan amable de ayudarme y decirme que hago mal.
Hey I like your videos alot... Hello Sir I need your help regarding the chatbot project. Actually, in my project, I need different chatbot screens for the different users so that one user cannot see the other user messages and ita very difficult to me please help Please reply...! Thank you
Hi sir why am i getting a Webhook call failed. Error: DEADLINE_EXCEEDED. in reading the data from the firebase? i can already save the data but when i am trying to retrieve it there is that error. i followed you code and the error is still the same. can you help me sir function HandleReadFromDB(agent){ return admin.database().ref('data').once('value').then((snapshot)=>{ const value = snapshot.child('text').val(); if(value !== null){ agent.add(`The value from the database is ${value}`); } });
I follow all steps, but in the end it is not working. When i write something to save to DB, the text parametar is not chaning in the firebase DB. It stay "ABCD". Do you have any solutions?
Deployment isn't working at 19:16. It says Snapshot and Value aren't defined and that Snapshot is missing a ): The deployment of your Cloud Function failed: Function failed on loading user code. Error message: Code in file index.js can't be loaded. Is there a syntax error in your code? Detailed stack trace: /srv/index.js:41 return admin.database().ref('data').once('value').then((snapshot) ^ SyntaxError: missing ) after argument list function handleReadFromDB(agent){ return admin.database().ref('data').once('value').then((snapshot) const value = snapshot.child('text').val(); if(value !== null){ agent.add(`the value from database is ${value}`); } });
@@AxleWebTechnologies Oh my god I saw it it was there for only 2-3 seconds I must have blinked my eyes. Can't believe I spent a day trying to troubleshoot this. Thanks for taking the time to reply to the email I really appreciate this!
function handleReadFromDB(agent){ //return admin.database().ref('data').once('value').then((snapshot) return admin.database().ref('data').once('value').then( snapshot => { const value = snapshot.child('text').val(); if(value != null){ agent.add(`The value from database is ${value}`); } }); }
Could you please tell me whether I can store the conversation done from chatbot by every user in the database to have a track on what all queries is being asked from the users. Please let me know!
Hi Sir, When i push the data in firebase my data looks like this: Now i am trying to read the 'Price' data based on disease reference and Test name. From last 4-5 hrs , I am trying but its not happening. Could you please help us.It will be very grateful :) Data | |--Diabetes | |----UniqueIdGenerated when i push the data from dialoag flow | | |--Price:100 | | |--Test:'Diabetes Test' | | | |----UniqueIdGenerated when i push the data from dialoag flow | | |--Price:103 | | |--Test:'Sugar Level' | |--Heart Disorder | |----UniqueIdGenerated when i push the data from dialoag flow | |--Price:340 | |--Test:'VITAL CARE HEART' | | |----UniqueIdGenerated when i push the data from dialoag flow |--Price:402 |--Tets:'HEALTH HEART SCREEN' /*Read Function function handleReadFromDB(agent) { if(agent.prameter.Test==='VITAL CARE DIABETES'){ return admin.database().ref('Data/Diabetes').once('value').then((snapshot)=>{ const value = snapshot.child('Price').val(); if (value!==null) { agent.add(`The value is from database is ${value}`); } });}} let intentMap = new Map(); intentMap.set('Default Welcome Intent', welcome); intentMap.set('Default Fallback Intent', fallback); intentMap.set('savetodb', handleSaveToDB); intentMap.set('readfromdb', handleReadFromDB); agent.handleRequest(intentMap); }); */ /*Push function*/ function handleSaveToDB(agent){ //const TEXT = agent.parameters.TEXT; const Disorder = agent.parameters.Disorder; const Test = agent.parameters.Test; // const AGE = agent.parameters.AGE; const Price=agent.parameters.Price; // if(Disorder==='Diabetes'){ admin.database().ref('Data/'+Disorder).push({ //Disorder:Disorder, Test: Test, //AGE: '23', Price: Price });
Try removing if condition and see if it works ie. this line if(agent.prameter.Test==='VITAL CARE DIABETES') { } if it still doesn't work, please drop me an email at anshul.shrivastava@axlewebtech.com ~Anshul
I receive this warning which I suspect is why I cannot access the database:"Warning, FIREBASE_CONFIG environment variable is missing. Initializing firebase-admin will fail",
Yes, you can do that by using Custom Webhook option (Fulfillment > Webhook) However, you need to keep in mind that you have to setup your own web server which can accept POST requests in order to get this working.
I have been getting this error for the last 20 days and could not solve it.Please Please Please can u tell me how to deal with it.This is really important as my entire project is based on this. When I click on the deploy button it shows an error"Error happened during Cloud Functions Deployment"..Please let me know how to debug it.
It looks like you don't have permission for deployment. Please make sure you are the owner of the Google cloud project. If you are not, make sure you get owner permission from whoever is the owner of the project. Feel free to comment if you still see the issue.
Hello I hope you can help me ... I have the code as you wrote it and it worked very well but a few weeks ago I stopped writing my dialogflow in my firebasedb ... I did not change anything in the code or anything in the chatbot ... why will it be that no longer saves the data? first of all, Thanks
I need help to solve this error, whenever i try to deploy it gives me this error.. Error: The deployment of your Cloud Function failed: Function failed on loading user code. Error message: Code in file index.js can't be loaded. Is there a syntax error in your code? Detailed stack trace: TypeError: Cannot read property 'app' of undefined at Object. (/srv/index.js:8:18) at Module._compile (module.js:653:30) at Object.Module._extensions..js (module.js:664:10) at Module.load (module.js:566:32) at tryModuleLoad (module.js:506:12) at Function.Module._load (module.js:498:3) at Module.require (module.js:597:17) at require (internal/module.js:11:18) at getUserFunction (/worker/worker.js:439:24) at loadUserCode (/worker/worker.js:495:18)
I am retrieving json data according to my need from firebase. I am now facing problem on how to represent this array of data in the agent response. Can you suggest me any reading material or help with the code. Thanks in advance
yes definitely, sessionId depends on which platform you are using for e.g. facebook, slack etc. Check the response format for corresponding platform and then save it in firebase database.
Hi, Thank you for this video tutorial! I'm just wanting to connect my Dialogflow Bot to a database of information about films. I want the user to be able to ask. Is Ant-man covered by my film license? and for the bot to respond Yes or No. I have a csv file with the data. What do you think would be the best way to do this?
Hi bro, i did what you did before but the console log is Warning, estimating Firebase Config based on GCLOUD_PROJECT. Initializing firebase-admin may fail? How do i solve this bro?
Thank you for video, it works fine. I need to read from firebase not only text, but other fileds to display Rich Response such as Basic Cards, Suggestion chips and simple response (Google Assistant integration). Do you have some codes or suggestions? Thank you so much!
Hello Anshul sir thanks a lot for your response I tried deploying a cloud function through inline editor but getting this error: Permission 'cloudfunctions.functions.setIamPolicy' denied on resource 'my-cloud-function-path' (or resource may not exist). Can you please assist or let me know what level of permission did u have while deploying this
Someone please help. I Followed everything as it is. Data from some intents gets stored perfectly, but for some it does not get stored. Why? I have enable webhook call and the code is exactly same :(
@@AxleWebTechnologies can't paste all here. so here is a section. As you can see the function for name and age as exactly the same. but age is getting stored, but name isn't. 'x' is variable to store a unique ID so each users data will store under the separate parent node function namefn(agent) { const NameObj=agent.parameters.NameNew; admin.database().ref('USER'+x).update({ Name:NameObj }); } function age(agent) { const agee=agent.parameters.age; admin.database().ref('USER'+x).update({ age:agee }); } let intentMap = new Map(); intentMap.set('name',namefn); //not working intentMap.set('age',age); intentMap.set('email',email); intentMap.set('mobile number',mobile_number); intentMap.set('zip code',zip_code); intentMap.set('qualification',qualification); intentMap.set('languages',languages); intentMap.set('partTimeFullTime',partOrFull); //not working intentMap.set('job title',job_title); intentMap.set('experience',experience); intentMap.set('current salary',current_salary); intentMap.set('notice - period',noticeperiod); intentMap.set('Desiredsalary',Desired_salary); //not working intentMap.set('password',password); // I don't see a problem in console logs either :/ . As said earlier webhook is enabled for all intents and the parameter names also match. thanks
Hy there, i have seen your video. I have problem nowdays dialogflow use Api V 2.0, how i solve this problem, i check in raw api response this "message": "Webhook call failed. Error: DEADLINE_EXCEEDED."
This is due to webhook taking more than 5 seconds to respond. Please don't perform heavy operations on webhook which might take more than 5 seconds to respond.
Muchas gracias, estuve buscando esto por la red durante varios días y no entendía nada hasta que acabo de ver tu vídeo. Ya me suscribo a tu canal y de nuevo gracias!
I want to call external Rest Api(cloud application along with the Body ,Custom Header,Authentication) and want to get response in the chat from dialogflow ,any leads on it will be appreciated.
Yes, you can do that using axios library. Following link might help you: stackoverflow.com/questions/44617825/passing-headers-with-axios-post-request PS: Make sure to Enable billing account otherwise Dialogflow can't connect to external network.
Thanks for sharing the video. It is really useful .Although i followed the same steps , there are no errors but my values are NULL. I am not sure what is causing the problem.Please help me out .dialogflow.cloud.google.com/#/agent/avg-project-ombxgx/
It is difficult to tell the error without seeing the code. There are couple of things you can check 1. Make sure billing account is enabled 2. Make sure fulfillment is enabled in the intent 3. Make sure you can see some logs in the console.logs.
Hey Anshul, at 13:11 I accidentally pressed the "Add" button and my "data-first_name" disappeared. Did I save this in the database? Could that cause problem down the line?
Did you publish your code for the fulfillment somewhere? I can't get my code to work and I know that there is a simple syntax that I missed. I got the write to work fine, but I can't get reading to work properly.
Yes here it is: Connect Dialogflow with MySQL gist.github.com/Anshul0305/aace32e8eabcb2ef49835d0079091e00 Connect Dialogflow with Spreadsheets gist.github.com/Anshul0305/0af703a063f51ca00213add2634cd88b Connect Dialogflow with External APIs gist.github.com/Anshul0305/405e050cf438975baec8a746ffda9991
5:12 I'm a little confused. Are the training phases the same regardless of how the database is used? Asking because we have an project at our college about creating a voicebot for a restaurant. We want it to work so that people can order pizzas without calling real people.
I cant even enable the inline editor it shows this: Cloud Functions integration requires billing to be set up (more info on pricing and usage here: cloud.google.com/functions/pricing). Please go to Google Cloud Console to set up billing first.
Yes, you have to setup billing account for that. Please watch our video on how to connect Dialogflow with external APIs. In that we have explained how to enable billing account.
Hey! Will this work even if I have intents as a follow up? Because I tried this but it is not showing the changes though getting deployed without any error
Yes this should work. Make sure to enable fulfillment in your follow up intents, also in your code, make sure to write the correct code for the intent map.
How we can build a Chatbot like Google home for only one category and fetch Realtime data from database. Also please make video on how to deploy this Chatbot in android studio.
You can use Dialogflow for building Google home chatbot. They call it actions on Google. Visit developers.google.com/actions/ for more details. Android studio is for building apps for Android OS. I would recommend using Visual Studio Code for chatbot coding.
Thanks for a great tutorial, I want to build an bot which asks users their Id and some 10-20 questions and then it should be saved in fire base with their mail -ids and answers can you please help? @Axle Web Technologies
What if I have a second or 3rd degree nested data, are you able to assist on that? Example: data |_ 1 |_ name |_first_name: abc |_last_name: xyz How do I read and write these? Thanks.
please help me in this , i want make agent help user to create his CV so i want the agent ask the user some Questions and save his answers in data base , but there is a problem in this agent we want ask him about his skill for Example so as this "Do you have skills want to add it ?" and if the answer of the user is yes ask him "what is your skill name ?" and if his answer is no ask him about different section such as "Do you want to add any studies for you ?" and make the same operation but aslo if he enter the name of skill for example we must ask him if he want to add anther skill or no as this "do you have anther skill want to add ?" please help me this is sooo important for me sir
Why does the data get overwritten all the time. I need to use this approach but need to find a way to store data from multiple users without overwriting them. Please help
how we can store information of many number of people in firebase database? is there an option that, we can create automatically generating tree in firebase?
There is no specific reason. Both are great. In some projects we have used cloud firestore as well. The choice depends on your use case. Please refer to this link for more details: firebase.google.com/docs/database/rtdb-vs-firestore
Dear Axle, thanks a lot for your video. I followed step by step your video but I got the following error. I rechecked and everything is equal to your video...Could you please advise? The deployment of your Cloud Function failed: Function failed on loading user code. Error message: Code in file index.js can't be loaded. Is there a syntax error in your code? Detailed stack trace: TypeError: admin.initializeAPP is not a function at Object. (/user_code/index.js:8:7) at Module._compile (module.js:577:32) at Object.Module._extensions..js (module.js:586:10) at Module.load (module.js:494:32) at tryModuleLoad (module.js:453:12) at Function.Module._load (module.js:445:3) at Module.require (module.js:504:17) at require (internal/module.js:20:19) at getUserFunction (/var/tmp/worker/worker.js:435:24) at loadUserCode (/var/tmp/worker/worker.js:491:18)
Hi AxleWeb. Thank you very much for this excellent video. I followed your instructions. The SaveFromDB works very well, but the ReadFromDB gives the string The value from database is ${value} instead of converting text value in value. I have put them in backtick key. Also, I noticed that when my savetoDB command works, it stores information as "Hello World INSTEAD of "Hello World" in your example. Attached is my code. Can you help? 'use strict'; const functions = require('firebase-functions'); const admin = require('firebase-admin'); const {WebhookClient} = require('dialogflow-fulfillment'); const {Card, Suggestion} = require('dialogflow-fulfillment'); admin.initializeApp ({ credential: admin.credential.applicationDefault(), databaseURL: 'ws://dfdatabasedemo-xhpqqm.firebaseio.com/' }) ; 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 welcome(agent) { agent.add(`Welcome to my agent!`); } function fallback(agent) { agent.add(`I didn't understand`); agent.add(`I'm sorry, can you try again?`); } function handleSaveToDB (agent) { const text = agent.parameters.text; return admin.database().ref('data').set({ first_name: 'Rahul', last_name: 'Sharma', text: text }); } function handleReadFromDB (agent) { return admin.database().ref('data').once('value').then((snapshot) => { const value = snapshot.child ('text').val(); if (value !== null) { agent.add('The value from database is ${value}'); } }); } let intentMap = new Map(); intentMap.set('Default Welcome Intent', welcome); intentMap.set('Default Fallback Intent', fallback); intentMap.set('SaveToDB', handleSaveToDB); intentMap.set('ReadFromDB', handleReadFromDB); agent.handleRequest(intentMap); });
Hi Ashish, you need to use backtick in the below code agent.add('The value from database is ${value}'); so it should be something like this: agent.add(`The value from database is ${value}`);
hi, buddy, may I ask you a favor? I followed the vedio , Writing data feature is OK, but READ DATA feature has been wroten many time. hope you can introduce more knowledge about it.
Suppose there are multiple child, in that case, the data structure will change slightly. It will be something like this: data |_ 1 |_ first_name: Rahul |_ last_name: Sharma |_2 |_first_name: XYZ |_last_name: ABC You need something unique like ID (Here I used 1, 2 etc but you can use username, email or anything which is unique) to uniquely identify a record. Then the code to write into the database should be something like: return admin.database().ref("data").child(ID).set({ first_name: res.data.first_name, last_name: res.data.last_name }); Where ID can be 1, 2, 3.. and so on.... And code to read from database should be something like: return admin.database().ref("data").once("value").then((snapshot) => { const value = snapshot.child(ID).val(); const first_name = value.first_name; }
Hi,I am having difficulties in saving the input data into database. The diagnostic info showed me 'Webhook call failed. Error: Request timeout'. Is there any solution for this?
For that you need to use Dialogflow API. We will launch video tutorials on Dialogflow APIs soon. Please subscribe to our channel and press the bell icon to get the latest notifications.
Hello sir ,your tutorials are great. Thanks for uploading them I wanted to know how to make a Chatbot which can place order on your behalf. E.g. Amazon . The bot should be able to search products, set quantity and direct you to payment directly.
Thanks. great tutorial....I have written same code...but while ReadfromDB intent, it is not picking variable from db...instead is shows simple message -> The value from database is ${value} ......my code is as below: function handleReadfromDB(agent){ return admin.database().ref('data').once('value').then((snapshot) => { const value = snapshot.child('text').val(); if(value !== null) { agent.add('The value from database is ${value}') ; } }); } any guesses where I am doing wrong ?
Hi Ashish, you need to use backtick in the below code agent.add('The value from database is ${value}'); i.e. use ` instead of ' so it should be something like this: agent.add(`The value from database is ${value}`);
Hi Alex!! When I want to capture new data of a person without knowing the name or other data and write it in the database the new data, how can I do it?
Thank you so much for your help and guidance. Please help me with the below queries . Appreciate any pointers from you :) queries ====== 1. can we give reference (vegetables in this case ) as input which is taken from user? (or does it need to be hardcoded ?) 2. how do i get value of parameter which is child of a child [in this case : input is patato -- i want to get soil_ph_value of patato ] 3. can we store image as a parameter here (patato pic for e.g)? structure in database : ================== vegetables patato growing_time soil_ph_value tamato growing_time soil_ph_value ================ Pseudocode : (not working) =================== const veg_input = agent.parameters.veg_input; agent.add(` veg input is :${veg_input}`); return admin.database().ref('vegetables').once('value').then((snapshot) => { const time_to_grow = snapshot.child('veg_input').child('grow_time').val(); agent.add(`your growingtime is :${time_to_grow}`); ===================== Please guide .. thanks
Hello, again! Do you have something on Yes and No answers? I searched but I couldn't find it. The problem I'm facing is that a lot of interactions have Yes and No flows, but the bot is mixing them. Or if I have same single words (even if they are in different entities and diferent intents) i gets mixed. I'm not sure if it is something in the contexts, the lifespam, the followup intent or any other issue. If the user answers with a simple yes or no, it gets mixed. If they say "yes I use paypal" it gets right. But in real use case I cannot demand a complete answer. Any tips? Thank you so much!
Ok, here is what you can do. Let's say you have an intent "Use Paypal". When you ask a question, "Would you like to use Paypal", set an output context, "use-paypal" in that intent. Now create two more intents named "Use Paypal - Yes" and "Use Paypal - No" In "Use Paypal - Yes", input context should be "use-paypal" and training phrases should be "Yes, yeah" etc In "Use Paypal - No", input context should again be "use-paypal" but training phrases should be "No,nope" etc and then in both intents Use paypal - yes and no, you can write corresponding response in the response section. You can watch my video on contexts and follow up intents here: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-kIlZ8FgNVx0.html
Hi Axle, thanks for the tutorial, really helpful and educational. Is there a way to connect a Dialogflow Agent to an Oracle Database. If so may you please share how it can be done. Thanks
Hey!! Tks so much for this video! I managed to go to the point of writing the first parameter in the database. But when I set the second one, the first one is erased from the database. (the first parameter turns red in firebase and the last one turns green) This is the code: function handleCompanyName(agent){ const text = agent.parameters.companyname; return admin.database().ref('data').set({ companyname: text }); } function handleAccountingType(agent){ const text = agent.parameters.accountingtype; return admin.database().ref('data').set({ accountingtype: text }); } let intentMap = new Map(); intentMap.set('welcome', welcome); intentMap.set('Default Fallback Intent', fallback); intentMap.set('company.name', handleCompanyName); intentMap.set('accounting.type', handleAccountingType); agent.handleRequest(intentMap); }); I'll have to do this for around 30 parameters, so I'm kind of lost on how to follow as is not working from the second one. The second question is that for some other intents I have up to 5 different parameters. For example, I have an Onboarding preferences intent, and I ask for datastart (using @sys.date) and financialswhen (using one entity I created called @financials-when). As they are all under one Intent I couldn't understand how to write this code. Thanks in advance for your help!
Hello Rosana, Please see my pinned comment. You need to use ref("data").child(ID).set() Where ID is a unique ID of each entry in the database. Feel free to comment back if you still have any questions.
@@AxleWebTechnologies yes, is working. Now the code is like: function saveCompanyName(agent){ const companyname = agent.parameters.companyname; return admin.database().ref('data').child('company name').set({ companyname: companyname }); } And the database is like: data accounting type accountingtype: "Quarterly" company name companyname: "Apple" :) I'm not sure if for the ID is better to use a number or a name as I'm doing now. But I can change later on if necessary. Now I'll try the multiple entries from one intent and let you know if successful or if I have more questions. Thanks a lot!
@@AxleWebTechnologies Also done with more than one parameter from a unique Intent. Code that worked: function saveStartandOnboardingDate(agent){ const datastart = agent.parameters.datastart; const financialswhen = agent.parameters.financialswhen; return admin.database().ref('data').child('start and onboarding').set({ datastart: datastart, financialswhen: financialswhen }); } Thaaaanks!
Yes we can connect Dialogflow with PostgreSQL, MySQL, MariaDB etc. I will create a video on this topic soon. Please subscribe and press the bell icon to get the latest updates.
Sir thankyou so much... I learned a lot from you I wanted to build a chatbot which queries the database for that i need help from you can you provide your email for contact
You can create an API using express which is connected to MySQL or sql sever and then you can connect Dialogflow with your APIs. You can watch my other video on how to integrate Dialogflow with external APIs
hi @Axle Web Technologies! i already have integrated my dialog flow with firebase database but the problem is that the values in my child nodes updates itself automatically with the values that i had stored previously.
I believe you want to store multiple values, for that please see the Pinned comment above (or below), I have explained there, how to store multiple values in the database.
Very helpful video. Actually, I'm looking to create a database layer where I save all the keywords, conversation, etc that's happening in dialogflow in the database and use it further
hi , i ve watched all your videos ! you helped me a lot but one thing is missing and don't get it , i want my chatbot in arabic language and i couldn't add translation to dialogflow , please help me ! thank you so much