1

I am having a problem when testing my Google Assistant app (made in DialogFlow). Every time I run the first intent and satisfy the criteria to run the corresponding action, the assistant ends and doesn't allow the user to input a value that may trigger the follow-up intent. The microphone is closed every time instead of continuing the conversation.

Is there a way to set up intents and corresponding webhook to ensure the app doesn't close itself every time a single action is completed?

'use strict';

process.env.DEBUG = 'actions-on-google:*';
const App = require('actions-on-google').DialogflowApp;
const functions = require('firebase-functions');

// x. start custom code
const orderLists = [
  {
    reference: '0',
    clothing: ['shirt', 'top', 'bra'],
    deliveryStatus: 'will be delivered before 1pm, make sure youre in!'
  },
  {
    reference: '1',
    clothing: ['shirt', 'top', 'bra'],
    deliveryStatus: 'is due for delivery on February 2nd.'
  },
  {
    reference: '2',
    clothing: ['shirt', 'top', 'bra'],
    deliveryStatus: 'is due for delivery on February 3rd.'
  },
  {
    reference: '3',
    clothing: ['shirt', 'top', 'bra'],
    deliveryStatus: 'was delivered today at 2pm to your default address.'
  },
  {
    reference: '4',
    clothing: ['shirt', 'top', 'bra'],
    deliveryStatus: 'was left with your neighbour at 22 Waltham Drive, today at 2pm.'
  }
]


// a. the action name from the make_name Dialogflow intent
// const NAME_ACTION = 'make_name';
const NAME_ACTION = 'query_order';
const NAME_ACTION2 = 'query_order.query_order-more';
// b. the parameters that are parsed from the make_name intent
// const COLOR_ARGUMENT = 'color';
// const NUMBER_ARGUMENT = 'number';
const ORDERNUMBER_ARGUMENT = 'number';

const min = 0;
const max = 10;

exports.sillyNameMaker = functions.https.onRequest((request, response) => {
  const app = new App({request, response});
  console.log('Request headers: ' + JSON.stringify(request.headers));
  console.log('Request body: ' + JSON.stringify(request.body));


// c. The function that generates the silly name
  function queryOrder (app) {
    let number = app.getArgument(ORDERNUMBER_ARGUMENT);
    app.tell('Order number '+ number + ', ' + orderLists[number].deliveryStatus) + 'Would you like to know more?';
  }
  function queryOrderItems (app) {
    let number = app.getArgument(ORDERNUMBER_ARGUMENT);
    app.tell('Order number '+ number + ', ' + orderLists[number].clothing);
  }
  // d. build an action map, which maps intent names to functions
  let actionMap = new Map();
  actionMap.set(NAME_ACTION, queryOrder);

  let actionMap2 = new Map();
  actionMap2.set(NAME_ACTION2, queryOrderItems);

app.handleRequest(actionMap);
app.handleRequest(actionMap2);
});
Prisoner
  • 49,922
  • 7
  • 53
  • 105
Jon Hick
  • 153
  • 1
  • 6

1 Answers1

3

The issue is that, in each case, you're using app.tell() to send the message back to the user. This not only sends the message, but tells the Assistant that the conversation is over and to close the microphone.

If you wish to continue the conversation (keep the microphone open and wait for a reply from the user), you should use app.ask() instead.

So your queryOrder() method might look something like this:

  function queryOrder (app) {
    let number = app.getArgument(ORDERNUMBER_ARGUMENT);
    app.ask('Order number '+ number + ', ' + orderLists[number].deliveryStatus) + 'Would you like to know more?';
  }

(As an aside - asking "Would you like more?" was very good practice in this case. Never leave the microphone open without prompting the user for what is expected.)

Prisoner
  • 49,922
  • 7
  • 53
  • 105
  • Thank you very much for your response, I had a feeling it would be something as simple as syntax. Is it ok to reference several functions in the same file? Or are they handled separately? Thanks +1 – Jon Hick Jan 29 '18 at 13:59
  • Dialogflow doesn't care how you organize your code - as long as you handle the request and send a response. (If you have further questions along this line - please ask them as another question.) – Prisoner Jan 29 '18 at 14:45