srikanth
srikanth

Reputation: 308

TypeError: agent.intent is not a function at exports.dialogflowFirebaseFulfillment.functions.https.onRequest

I am trying to display the few items using actions-on-google Carousel, to handle the click action I need to use intent('actions.intent.OPTION', (?,?,?)) function, but doing it results in below error,

ERROR:

TypeError: agent.intent is not a function at exports.dialogflowFirebaseFulfillment.functions.https.onRequest

The code is

const functions = require('firebase-functions');
const {
    WebhookClient
} = require('dialogflow-fulfillment');
const {
    Image,
    Carousel,
    BrowseCarousel,
    BrowseCarouselItem,
} = require('actions-on-google');
exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {

  const agent = new WebhookClient({
    request,
    response
  });
  agent.requestSource = agent.ACTIONS_ON_GOOGLE;
  console.log('Dialogflow Request headers: ' + JSON.stringify(request.headers));
  console.log('Dialogflow Request body: ' + JSON.stringify(request.body));
  // Run the proper function handler based on the matched Dialogflow intent name
  let intentMap = new Map();
  intentMap.set('Welcome Intent', welcome);
  intentMap.set('Default Fallback Intent', fallback);
  intentMap.set('video.search', searchQuery);
  // intentMap.set('your intent name here', googleAssistantHandler);
  agent.handleRequest(intentMap);

  agent.action('actions.intent.OPTION', (conv, params, option) => {
    let response = 'You did not select any item';
    if (option) {
        response = 'You have chosen: ' + option;
    }
    conv.ask(response);
  });
}

Kindly help If I'm missing anything in here ?

Also, I need to trigger the deep link, from the intent handled method is there any way to trigger explicit deep link intent URI from here?

Upvotes: 1

Views: 640

Answers (1)

Prisoner
Prisoner

Reputation: 50701

The error message seems odd, but it looks like you copied the code from Google's documentation without reading the rest of the info, and have tried changing it to agent.action.

The problem is that you are treating agent.action as a function - and it is not. This is a property that contains the name of the "action" that was set in the Parameters section for the Intent.

Handling actions.intent.OPTION through Dialogflow is by creating an Intent that has the event actions_intent_OPTION with no training phrases. Something like this:

enter image description here

You would then have a handler that handles the "input.option" intent (to use the name I did in the example), just as you would for other intent handlers.

Upvotes: 1

Related Questions