0

All the logs which are displayed by using console.log are shown. But agent doesn't display the response.

I try to use promise but do not know how to use it with this code.

function combineCollection(agent) {

  console.log('At combineCollection');
    return admin.firestore().collection('House').where('userId','==',lineId).get().then(function(querySnapshot) {
      querySnapshot.forEach(function(doc) {
        console.log('find houseNo by userId');          
        houseNo = doc.id;
        console.log('houseNo in combinefunction: '+houseNo);
        console.log('before find invoice');
        invoice();
      });
    })
    .catch(function(error) {
        console.log('Error getting documents: ', error);
    });     
}


function invoice(){
    let price = 5;
  console.log('houseNo: '+houseNo);
 return admin.firestore().collection('Invoice').where('houseNo','==',houseNo).get().then(function(querySnapshot) {
      querySnapshot.forEach(function(doc) {
        console.log('find invoice by houseNo');
        console.log(doc.id, " => ", doc.data());
        price = doc.data().price;
        console.log(price);     // it's show
        agent.add(price);       // it's not show
      });
    })
    .catch(function(error) {
        console.log('Error getting documents: ', error);
    });    
}


 let intentMap = new Map();

 intentMap.set("aa",combineCollection);
hfurkanvural
  • 420
  • 2
  • 16

1 Answers1

0

In invoice() function, agent is not defined or got as parameter. So, it can not recognize the agent.add() function and can not respond. Add agent as parameter to your function and try again.

Also check these for async calls:

for Dialogflow

for Actions on Google

hfurkanvural
  • 420
  • 2
  • 16