1
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.

Prisoner
  • 49,922
  • 7
  • 53
  • 105

3 Answers3

2

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 );
});
Prisoner
  • 49,922
  • 7
  • 53
  • 105
  • thanks for kind reply. but am deployed my service in heroku am not using firebase. please help me. – Niranjan Dharmarajan Feb 02 '18 at 14:36
  • Please edit your original question with more information then. What other code have you written for this project, or is that it? Have you written other node.js/express code on Heroku before, or what frameworks have you used? – Prisoner Feb 02 '18 at 15:11
  • @Prisoner I am not sure about OP, but I am trying to create a HTTPS handler that DOESN'T use Firebase. I have account linking set up through a custom OAuth URL and I just want to get the access token but I have zero interest in using firebase. Before I was able to use: exports.handler = function(event, context, callback) {} to export the handlers and get everything I needed, but how do I convert that to get it the access_token via DialogFlow? – Russell Ingram Feb 03 '18 at 01:01
  • 1
    @RussellIngram - that's really a different question. Go ahead and ask it as a new question, and provide as much detail as you can (including what environment you *are* using) – Prisoner Feb 03 '18 at 03:25
0

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
})
Nazeem
  • 468
  • 2
  • 9
0

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.