我在dialogflow中构建了一个bot,它由一系列意图组成,我想在firestore下的用户响应中保存一个集合。我在node.js中编写了后端代码但遇到了一些问题。 我正面临一个名为“App不是构造函数”的问题 在exports.dialogflowFirebaseFulfillment.functions.https.onRequest“
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const Firestore = require('@google-cloud/firestore');
const firestore = new Firestore();
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');
process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements
const array = require('array');
admin.initializeApp();
var db = admin.firestore();
var users = array();
const App = require('actions-on-google').DialogflowApp;
const NAME_ACTION = 'Welcome';
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
const app = new App({request, response});
console.log('Request headers: ' + JSON.stringify(request.headers));
console.log('Request body: ' + JSON.stringify(request.body));
let action = request.body.result.action; // https://dialogflow.com/docs/actions-and-parameters
console.log('Actions = '+ JSON.stringify(action));
let query = request.body.result.resolvedQuery;
const parameters = request.body.result.parameters; // https://dialogflow.com/docs/actions-and-parameters
const inputContexts = request.body.result.contexts; // https://dialogflow.com/docs/contexts
function makeName (app) {
// early age
let Name = app.getArgument(Name_Argument);
if(action === 'Welcome'){
var data = {
0: Name,
};
var setDoc = db.collection('data').doc('one').set(data);
}
}
let actionMap = new Map();
actionMap.set(NAME_ACTION, makeName);
app.handleRequest(actionMap);
function sendResponse (responseToUser) {
if (typeof responseToUser === 'string') {
let responseJson = {};
responseJson.text = responseToUser; // spoken response
responseJson.displayText = responseToUser; // displayed response
response.json(responseJson); // Send response to Dialogflow
} else {
let responseJson = {};
responseJson.text = responseToUser.text || responseToUser.displayText;
responseJson.displayText = responseToUser.displayText || responseToUser.text;
responseJson.data = responseToUser.richResponses;
responseJson.contextOut = responseToUser.outputContexts;
response.json(responseJson); // Send response to Dialogflow
}
}
});
答案 0 :(得分:0)
在下面检查我的代码,
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
var name = 'test';
const app = new WebhookClient({ request, response });
console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
使用const app = new WebhookClient({ request, response });
代替const app = new App({request, response});