I've got the following intent handler:
async function expenseLogHandler(agent) {
const value = agent.parameters["value"];
const currency = agent.parameters["currency"] || "SGD";
const timestamp = Number(new Date());
const payload = {};
payload.quick_replies = [{
content_type: 'text',
payload: 'log more',
title: 'log more'
}]
try {
const expense = await db.collection("expenses").add({
value, currency, timestamp
});
console.log('Logged expense: ', expense);
payload.text = `ok done: ${currency} ${value} added`;
// Remove and move this outside of try/catch sometime
agent.add(new Payload(agent.FACEBOOK, payload))
} catch(err) {
console.error('Error logging expense: ', err);
payload.text = `Something went wrong: ${err.toString()}`;
// Remove and move this outside of try/catch sometime
agent.add(new Payload(agent.FACEBOOK, payload))
}
}
Every single time it's invoked, an expense is instantly being created in Cloud Firestore - it reflects within Firebase and also on the Cloud Function's logs.
However the Facebook message payload erratically doesn't show 30% of the time (there is no error, and the expense is _always_ created), just the error doesn't show.
What could I be doing wrong?
It seems like you're hitting the 5 second limit Dialogflow has for a response to be returned. If nothing is returned in 5 seconds, the default response will be sent but the function will finish running in the background.
@nathanjliu's assessment seems reasonable @sarupbanskota can you confirm this is causing your issue?
That's right @nathanjliu and @matthewayne, appears to be the 5s limit.
I was aware of the DF limit itself, but didn't realise how/when the cold boot problem would affect a cloud function. So while my original question is answered, I'm curious if there's an easy way to check what node dependency versions might be cached within cloud functions infra?
For future reference for anyone else who runs into a similar issue, I found the following helpful: