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.

3 Answers 3

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 );
});
Sign up to request clarification or add additional context in comments.

4 Comments

thanks for kind reply. but am deployed my service in heroku am not using firebase. please help me.
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 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?
@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)
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
})

Comments

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.

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.