Dialogflow Firestore Integration.

1 view
Skip to first unread message

salem abid

Sep 13, 2021, 11:48:40 AMSep 13
to gce-discussion
I need some help.
I am developing a chatbot using Dialogflow. I want to retrieve my data from Firestore using fulfillment.
A candidate should provide his full name, his email and his phone number then should be stored in the database with a default candidature status (in progress) and an auto-generated id,
admin can modify that status and candidate can check updates using his id.
So the first part worked, i added data with auto-generated id, here's the code :

function saveToDBHandler (agent) {
     let full_name = agent.parameters.full_name;
     let phone_number = agent.parameters.phone_number;
     let  email_address = agent.parameters.email_address;
     var newCandidateRef = db.collection('candidates').doc();
   full_name : full_name,
   phone_number : phone_number,
   email_address : email_address,
   candidature_status : 'In progress', 
   agent.add(`data stored with ID : ${newCandidateRef.id}`));
Now when I want to read the candidature_status value using get() as shown is Firebase documentation it doesn't work.
here's my code :

function getStatusHandler(agent) {
  let candidateID = agent.parameters.id;
  const docRef = db.collection('candidates').doc(candidateID);
  const doc = docRef.get();
if (doc.exists) {
  console.log('Document data:', doc.data().candidature_status);
  agent.add(`Candidature status: ${doc.data().candidature_status}`);
} else {
  console.log('No such document!');
  agent.add(`No such ID found!`);  


I enter the provided id then I always get the response "No such ID found!".
What am I missing here?
Reply all
Reply to author
0 new messages