1
votes
const DialogflowApp = require('actions-on-google').DialogflowApp;

const app = new DialogflowApp({request: request, response: response});

const WELCOME_INTENT = 'input.welcome';  // the action name from the Dialogflow intent
const NUMBER_INTENT = 'input.number';  // the action name from the Dialogflow intent
const NUMBER_ARGUMENT = 'input.mynum'; // the action name from the Dialogflow intent

I got Reference Error: request is not defined.

3

3 Answers

2
votes

It looks like, from just what you've provided, that you're not defining app inside an HTTPS handler. The DialogflowApp constructor expects to be passed a request and response object that are sent by an Express-like node.js handler. If you are using Google Cloud Functions or Firebase Cloud Functions, these will be what are available in your function handler.

So if you're using Firebase Cloud Functions, it might look something like this:

const DialogflowApp = require('actions-on-google').DialogflowApp;

const WELCOME_INTENT = 'input.welcome';  // the action name from the Dialogflow intent
const NUMBER_INTENT = 'input.number';  // the action name from the Dialogflow intent
const NUMBER_ARGUMENT = 'input.mynum'; // the action name from the Dialogflow intent

// You will use the action name constants above as keys for an "actionMap"
// with the value being a function that implements each action.
let actionMap = new Map();
// TODO - you need to do this part.

const functions = require('firebase-functions');
exports.webhook = functions.https.onRequest( (request,response) => {
  const app = new DialogflowApp({request: request, response: response});
  app.handleRequest( actionMap );
});
0
votes

if you are using a Node.js app with express ou need to create the instance (assistant in this case) of the Dialogflow class inside the method that handles the route used.

let express = require('express');
let app = express();
const DialogflowApp = require('actions-on-google').DialogflowApp;

app.post('/', function (request, response) {
  const  assistant = new DialogflowApp({request: request, response: response});
  //... code
})
0
votes

Adding these statements in your command may solve the issue

const DialogflowApp = require('actions-on-google').DialogflowApp;
const app = new DialogflowApp({request: request, response: response});

I hope this may solve your issue.