我正在尝试为我的dialogflow代理创建一个后备计数器,以便它可以使用户知道该代理仍无法帮助他们。但是,我似乎无法反其道而行之。每当我运行测试时,它总是会重置为0。所以我陷在fallbackCount = 1
'use strict';
const {dialogflow} = require('actions-on-google');
const functions = require('firebase-functions');
const app = dialogflow({debug: true});
// Map the intent 'Default Fallback Intent' from the Dialogflow agent to this function.
app.intent('Default Fallback Intent', (conv) => {
// If 'fallbackCount' doesn't exist, create it and set the value to 0.
if (!conv.data.fallbackCount) {
conv.data.fallbackCount = 0;
}
// Increment the value of 'fallbackCount'.
conv.data.fallbackCount++;
// Adjust the fallback response according to the error count.
if (conv.data.fallbackCount === 1) {
conv.ask(`Sorry, I\'m still learning, could you rephrase that?`);
} else if (conv.data.fallbackCount === 2) {
conv.ask(`Sorry, I\'m still learning, could you say that in a different way?`);
} else {
// If 'fallbackCount' is greater than 2, send out the final message and terminate the conversation.
conv.data.fallbackCount = 0;
return conv.close(`This seems like it\'s beyond my expertise and I can\'t help. Would you like me to make a note of this question for my next update?`);
}
});
exports.dialogflowFirebaseFulfillment = functions.https.onRequest(app);