How do I end my custom action on assistant?

Viewed 136

I have a very simple action that just gives me some status and then I want to end it, no conversation, nothing else, just get the status and end it. Right now I'm doing this:

agent.add(message1);
agent.add(message2);
agent.end('done');

I've also tried (as you'll see on the code below just doing agent.end(completeMessage); but assistant keeps waiting for me to do more, my action doesn't end.

I've made a totally simple sample to demostrate, test intent is the one that has the end() call:

enter image description here

Code:

'use strict';

const functions = require('firebase-functions');
const { WebhookClient } = require('dialogflow-fulfillment');
const { Card, Suggestion } = require('dialogflow-fulfillment');

const fetch = require("node-fetch");

process.env.DEBUG = 'dialogflow:debug'; // enables lib debugging statements

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 testIntent(agent) {
    agent.end('done');
  }

 intent name
  let intentMap = new Map();
  intentMap.set('Default Welcome Intent', welcome);
  intentMap.set('Default Fallback Intent', fallback);
  intentMap.set('test intent', testIntent);
  agent.handleRequest(intentMap);
});

Anyone have any ideas of how I can make my action just totally end when I called test intent?

1 Answers

If you are using the dialogflow-fulfillment library with Actions on Google, you can only have two simple responses (text or SSML strings). Since your code calls agent.end() after two messages have already been set, it may be ignored.

Instead you can call it as

agent.add(message1);
agent.end(message2);

The documentation for agent is for the WebhookClient object. If you want to skip the library, there is also the webhook response JSON documentation.

Related