我越来越:
意外标记 - 第 19 行(在 * * 中)代码中的语法错误。
请帮忙。我对 node.js 相当陌生。
这是完整的错误:
您的云函数部署失败:函数加载用户代码失败。错误消息:无法加载文件 index.js 中的代码。您的代码中是否存在语法错误?详细的堆栈跟踪:/srv/index.js:20 }exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => { ^^^^^^^
SyntaxError:意外的标识符
'use strict';
const functions = require('firebase-functions');
const {WebhookClient} = require('dialogflow-fulfillment');
const {Card, Suggestion} = require('dialogflow-fulfillment');const requestNode = require('request');
const NUMBER_ARGUMENT = 'number';process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statementsfunction saveToDb(numberToSave) {
const options = {
url: 'https://dog-pictures-2d717.firebaseio.com/picture.json',
method: 'PUT',
headers: {
'Content-Type': 'application/json'
},
body : JSON.stringify({
"number" : numberToSave
})
};
requestNode(options, function(error, requestInternal, body){
console.log(body);
*> });*
}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));
function welcome(agent) {
agent.add(`Welcome to my agent!`);
}
function fallback(agent) {
agent.add(`I didn't understand`);
agent.add(`I'm sorry, can you try again?`);
}
function showPicture() {
let number = request.body.queryResult.parameters[NUMBER_ARGUMENT];
saveToDb(number);
}// Run the proper function handler based on the matched Dialogflow intent name
let intentMap = new Map();
intentMap.set('Default Welcome Intent', welcome);
intentMap.set('Default Fallback Intent', fallback);
// Here you pass as first argument the name of the Intent
intentMap.set('Show picture', showPicture);
// intentMap.set('your intent name here', yourFunctionHandler);
// intentMap.set('your intent name here', googleAssistantHandler);
agent.handleRequest(intentMap);
});