【问题标题】:Retrieve data from Firestore to display in DialogFlow从 Firestore 检索数据以显示在 DialogFlow 中
【发布时间】:2018-11-21 16:43:38
【问题描述】:

我正在尝试从 firestore 获取数据并将其显示在 DialogFlow 响应中。当我在 DialogFlow 中触发“buyerBusiness”意图时,功能 Web 实现成功,但检索到的数据不显示为响应。当我安慰他们时,它会出现在日志中。下面是为此编写的处理函数。

function buyerBusiness(agent) {
        console.log("buyer name is " + params.BuyerEntity);
        var abc = new Set();
        var results = [];
        admin.firestore().collection('SuppBuyAssoc').where('Advertiser', '==', params.BuyerEntity).limit(5).get().then(snapshot => {
            snapshot.forEach(doc => {
                abc.add(doc.data().Agency);
            });
            var x = Array.from(abc);
            var y;
            for (var j = 0; j < x.length; j++) {
                y = results.push(x[j]);
            }

            blueBird.all(results).then(function () {
                console.log('results are: ' + results);
                agent.add(results);
            }).catch(eror => {
                console.log("Errrrr");
                console.log(eror);
            })
            console.log("results are:"+ results);

        }).catch(reason => {
            // res.send(reason)
            console.log(reason);
        })

        // agent.add(`Testing this stuff`);
    }

这里是云功能的日志 -

3:32:33.069 PM info dialogflowFirebaseFulfillment results are: Publicis,Ogilvy,GroupM,WPP
3:32:32.668 PM info dialogflowFirebaseFulfillment results are:Publicis,Ogilvy,GroupM,WPP
3:31:55.910 PM
outlined_flag   
dialogflowFirebaseFulfillment
Function execution took 2930 ms, finished with status code: 200
3:31:54.253 PM
info    
dialogflowFirebaseFulfillment
buyer name is IBM
3:31:54.253 PM
info    
dialogflowFirebaseFulfillment
Dialogflow Request body: ----------
3:31:54.247 PM
info    
dialogflowFirebaseFulfillment
Dialogflow Request headers: ---------
3:31:52.981 PM
outlined_flag   
dialogflowFirebaseFulfillment
-------
3:31:52.981 PM
outlined_flag   
dialogflowFirebaseFulfillment
Function execution started

【问题讨论】:

    标签: node.js firebase-realtime-database google-cloud-firestore bluebird dialogflow-es


    【解决方案1】:

    要让 Dialogflow 实现库跟踪您的异步请求,您需要返回从调用 firestore 获得的承诺。

    尝试在 admin.firestore().collection 调用之前添加 return:

    function buyerBusiness(agent) {
      console.log("buyer name is " + params.BuyerEntity);
      var abc = new Set();
      var results = [];
      return admin.firestore().collection(/* rest of code */
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-11-28
      • 1970-01-01
      • 2020-04-08
      • 2020-04-26
      • 1970-01-01
      • 2020-03-13
      • 2018-08-19
      相关资源
      最近更新 更多