gpt4 book ai didi

google-cloud-firestore - agent.add 不工作但 console.log 工作

转载 作者:行者123 更新时间:2023-12-05 07:18:13 24 4
gpt4 key购买 nike

在下面的代码中,“agent.add”不起作用,但“console.log”起作用了。我已经添加了决心和拒绝的 promise ,但仍然没有用。我尝试了不同的方式,但来自 firestore 的多次响应,无法将其发送给用户。能够在 firebase 中看到日志,但在 dialogflow 中看不到。

    const {Firestore} = require('@google-cloud/firestore');
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
const admin = require('firebase-admin');

admin.initializeApp();

process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging
statements
const firestore = new Firestore();
const settings = {/* your settings... */
timestampsInSnapshots: true};
firestore.settings(settings);

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));
const db = admin.firestore();

```
function welcome(agent) {
agent.add(`Welcome to my agent!`); // not working
console.log("Welcome Agent");
const num = agent.parameters.number;

let usersRef = db.collection('add');
let query = usersRef.where('Number', '==', num);
return new Promise((resolve,reject)=>{ // not working
return query.get()
.then(querySnapshot => {
if (querySnapshot.empty) {/*
const timestamp = querySnapshot.get('created_at');
const date = timestamp.toDate();*/
console.log('No matching documents.');
agent.add(`No Matching Documents`);
return;
}
querySnapshot.forEach(doc => {
const line1 = doc.get('Line1');
const line2 = doc.get('Line2');
const explain = doc.get('explanation');
console.log('Line1: ', line1); //this works
console.log('Line2: ', line2); //this works
console.log('explain: ', explain); //this works
agent.add(`your response is ` +doc.get('Line1')); //not working
agent.add(`Final Response - ${line2}`); //not working
agent.add(doc.get('explanation')); //not working
});
resolve('resolved');
})
.catch(err => {
console.log('Error getting documents', err);
reject(err);
});
});
}

最佳答案

问题现已解决。在最后一个 agent.add 中添加了 return 语句,它正在工作。谢谢。

agent.add(your response is +doc.get('Line1')); 
agent.add(Final Response - ${line2});
return agent.add(doc.get('explanation'));

关于google-cloud-firestore - agent.add 不工作但 console.log 工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58449742/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com