0

I'm getting:

Unexpected token - Syntax error in the 19TH line (in * *) code.

Please help. I'm fairly new to node.js.

This is the error in full:

The deployment of your Cloud Function failed: Function failed on loading user code. Error message: Code in file index.js can't be loaded. Is there a syntax error in your code? Detailed stack trace: /srv/index.js:20 }exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => { ^^^^^^^

SyntaxError: Unexpected identifier

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

1 Answer 1

1

Remove this symbols: *>, * and remove brace near exports keyword.

You should get this:

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

and

exports.dialogflowFirebaseFulfillment

I advice you to install package ESLint. It will help you find and fix problems in your code.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.