DialogFlow,完成操作后让助手保持打开状态

时间:2018-01-29 13:17:21

标签: javascript action actions-on-google dialogflow

我在测试Google智能助理应用程序(在DialogFlow中制作)时遇到问题。每次我运行第一个intent并满足运行相应操作的条件时,助手都会结束并且不允许用户输入可能触发后续意图的值。麦克风每次都关闭,而不是继续对话。

有没有办法设置意图和相应的webhook,以确保每次单个操作完成后应用程序都不会自动关闭?

'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);
});

1 个答案:

答案 0 :(得分:3)

问题在于,在每种情况下,您都使用app.tell()将消息发送回用户。这不仅会发送消息,还会告诉智能助理会话已结束并关闭麦克风。

如果您希望继续对话(保持麦克风打开并等待用户回复),则应使用app.ask()代替。

因此,您的queryOrder()方法可能如下所示:

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

(顺便一提 - 询问"你想要更多吗?"在这种情况下是非常好的做法。永远不要让麦克风打开而不提示用户预期的内容。)