如何使用agent.add()?

时间:2019-04-27 14:22:40

标签: dialogflow dialogflow-fulfillment

显示所有通过console.log显示的日志。但是代理不会显示响应。

我尝试使用promise,但不知道如何在此代码中使用它。

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);

1 个答案:

答案 0 :(得分:0)

在invoice()函数中,未定义代理或未将其作为参数。因此,它无法识别agent.add()函数并且无法响应。将代理作为参数添加到函数中,然后重试。

还要检查这些内容以进行异步调用:

for Dialogflow

for Actions on Google