0

我越来越:

意外标记 - 第 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);
});
4

1 回答 1

1

删除此符号:*>、* 并删除 export 关键字附近的大括号

你应该得到这个:

requestNode(options, function(error, requestInternal, body){
    console.log(body);
});

exports.dialogflowFirebaseFulfillment

我建议你安装包ESLint。它将帮助您发现并修复代码中的问题。

于 2020-02-05T09:02:59.183 回答