Неожиданный токен — синтаксическая ошибка в моем коде node.js

Я собираюсь:

Неожиданный токен — синтаксическая ошибка в 19-й строке (в * *) коде.

Пожалуйста помоги. Я новичок в node.js.

Вот ошибка полностью:

Не удалось развернуть вашу облачную функцию: функция не удалась при загрузке пользовательского кода. Сообщение об ошибке: Невозможно загрузить код в файле index.js. В вашем коде есть синтаксическая ошибка? Подробная трассировка стека: /srv/index.js:20 }exports.dialogflowFirebaseFulfillment = functions.https.onRequest((запрос, ответ) => { ^^^^^^^

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);
});

person nihal konan    schedule 05.02.2020    source источник


Ответы (1)


Удалите эти символы: *>, * и снимите фигурную скобку возле ключевого слова exports.

Вы должны получить это:

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

а также

exports.dialogflowFirebaseFulfillment

Советую установить пакет ESLint. Это поможет вам найти и исправить проблемы в вашем коде.

person EduardS    schedule 05.02.2020