Closed janjay2018 closed 5 years ago
In the error stacktrace, you should see a line number for the error. That may help in identifying exactly where the problem is originating.
Thank you Fleker!, I've updated the issue with the full error, but I still can't figure out what's causing the error
Oh I see. Your database call was successful. However, you cannot directly add the document results. The agent.add
call expects one of several types of responses, such as a string or a button. Your database response has unexpected fields, like user_activity
.
You need to convert your database results into a valid format. There are many ways to do it.
agent.add(JSON.stringify(doc.data()))
const data = doc.data()
agent.add(`User ${data.user_activity} and felt ${data.user_feeling}`)
The second is more ideal, but the first will at least give you a valid response for quick iterating.
That's great! it works now š Thank you!!
Wait, it seems there's another problem with the code, I would be so grateful if you could perhaps point me in the direction to correct it?
Sure, I could assist if you have something else.
I updated the code so it looks like so, I want to use the code to iterate through each document in the collection positiveLogs and return the date the log was made as a new suggestion. The error I am getting says there are no defined responses, I have looked over the internet for solutions but I cannot find what I am doing wrong, as I have defined the platform responses for the agent? Any help would be much appreciated!
const dialogflowdoc = db.collection('users').doc('user3').
collection('positiveLogs').where("date","==",true).limit(2);
return dialogflowdoc.get().
then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
if(!doc.exists){
agent.add('Sorry there do not seem to be any logs to see');
}else{
const data= doc.data();
//agent.add(new Suggestion(`-${data.date}.`));
agent.add(`-${data.date}.`);
}
console.log(doc.id, " => ", doc.data());
});
})
.catch(function(error) {
agent.add("error retrieving documents");
console.log("Error getting documents: ", error);
});
}
The error I got is shown below,
Error: No responses defined for platform: null at V2Agent.sendResponses_
(/user_code/node_modules/dialogflow-fulfillment/src/v2-agent.js:243:13) at WebhookClient.send_
(/user_code/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:505:17) at promise.then
(/user_code/node_modules/dialogflow-fulfillment/src/dialogflow-fulfillment.js:316:38) at
process._tickDomainCallback (internal/process/next_tick.js:135:7)
The error seems to be originating from this file.
How are you wrapping this code in a function? The same as before? Are you sure that the Suggestion
code is no longer being run?
The code is wrapped exactly the same as before, like so,
function getPositiveLogs(agent){
const dialogflowdoc = db.collection('users').doc('user3').
collection('positiveLogs').where("date","==",true);
return dialogflowdoc.get().
then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
if(!doc.exists){
agent.add('Sorry there do not seem to be any logs to see');
}else{
const data= doc.data();
agent.add(new Suggestion(`-${data.date}.`));
}
console.log(doc.id, " => ", doc.data());
});
})
.catch(function(error) {
agent.add("error retrieving documents");
console.log("Error getting documents: ", error);
});
}
i am not sure because especially with this function, when i changed it before to include the two lines
const data = doc.data();
agent.add(`${data.user_activity}`);
the first time I deployed it, the response was, 'not available' it was only the second time i deployed fulfilment, that the function worked and I got the correct response. So I'm not sure if there's a delay in the processing or something? and it very well could be the Suggestion code is still being run, because it seems just for this function dialogflow seems super confused?
Is it possible that I am doing something wrong with the Promise?
There is a brief period where the previous function is still active, so you may have been running a cached version.
With regards to the use of Suggestions, you may want to check if you're importing everything, such as shown here: https://github.com/dialogflow/fulfillment-webhook-nodejs/blob/master/functions/index.js#L21
I'm sorry for the late reply, I was trying to do everything I could think of to check the Suggestions was working. It is definitely working for other functions, it seems there is just no response being shown for this function only. With the following function, there is no error shown in logs and the console is being updated with the information from the document, i.e.
qpZUzhuRMejIuqPT05Ui => { user_reward: 'no', date: Timestamp { _seconds: 1547247817, _nanoseconds: 469000000 }, user_feeling: 'happy', user_activity: 'met up with friend' }
but nothing shown in the simulator
this is everything I am importing, I am sure I am importing everything required
//these are functionalities that need to be used
const {dialogflow} = require('actions-on-google');
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
//initialise DB connection
const admin = require("firebase-admin");
process.env.DEBUG = 'dialogflow:debug*'; // enables lib debugging statements
//configure sdk
admin.initializeApp(functions.config().firebase);
admin.firestore().settings({timestampsInSnapshots: true});
const db = admin.firestore();
const timestamp = admin.firestore.Timestamp;
and this is the function now
function readPositiveLogs(agent){
const documentRef = db.collection('users').doc('user3').
collection('positiveLogs');
return documentRef.get().then(function(querySnapshot) {
querySnapshot.forEach(function(doc) {
if(querySnapshot.empty){
console.log('no documents found');
}else{
const data= doc.data();
const timestamp_date = data.date;
const string_date = timestamp_date.toDate();
agent.add(new Suggestion(`${string_date}`));
console.log(doc.id, " => ", doc.data());
}
});
})
.catch(function(error) {
agent.add("error retrieving documents");
console.log("Error getting documents: ", error);
});
}
I was wondering if this problem was due to the format of the date being a timestamp? because when I write another value from the log, i.e. the user_activity as a suggestion it comes up fine. I've tried JSON.Stringify however, and it does not seem to fix the problem. Is there anything you could suggest?
Thank you!
A Firestore data object is not a string nor JSON, and you may want to check those docs to see how to modify it into a string.
ahh yes, I see where I'm going wrong. Thank you Nick!
Hi,
I'm trying to read documents in the firestore database from dialogflow, but i keep getting this error Error getting documents: Error: Unknown response type: "{document data}"
I want the document to be a response to the users request, so it would be like user: i want to see this document agent: here is the document agent: Document Information below are the imports
and the function to retrieve the data
I would be grateful to anyone who can tell me where I am going wrong! Thank you