在对话流实现中访问先前的后续意图参数

时间:2018-11-05 14:38:32

标签: dialogflow

我正在使用内联编辑器中提供的默认dialogflow代码,该代码基于dialogflow-fulfillment ^ 0.5.0来整理多个后续意图中给出的所有参数。我有一个设置,其中跟进意图会提出问题,最终结果会问所有问题。

从dialogflow控制台内的先前意图中提取数据以包含在响应中,将仅使用#order-cream-followup.chocolate-type从先前意图中获取参数,或者使用$quantity从当前意图中获取参数。但是,尽管agent.parameters['quantity']的工作方式与$quantity相似,但我找不到在对等的对话流中完成与#order-cream-followup.chocolate-type等效的方法

很抱歉,如果这是一个明显的答案,那么我会迷失在关于Dialigflow和在google上执行操作的各种不同文档中。

我的代码:(当前只是登录到控制台,然后再添加代码以处理该数据)

// See https://github.com/dialogflow/dialogflow-fulfillment-nodejs
// for Dialogflow fulfillment library docs, samples, and to report issues
'use strict';

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

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 placeOrder(agent) {
    console.log('placing order:');
    console.log(agent.context.get('order-cream-followup').parameters['choctype']);
    agent.add('Thanks ' + agent.parameters['name'] + ', please collect your order from the window.');
  }

  // Run the proper function handler based on the matched Dialogflow intent name
  let intentMap = new Map();
  intentMap.set('order - cream - marshmallow - check - yes - name - submit', placeOrder);
  agent.handleRequest(intentMap);
});

1 个答案:

答案 0 :(得分:2)

要获取仍处于活动状态的上下文(即,其 Table 3 | ID | Name |Info1(Table2)|Info2(Table3)| |-------|-----------|-------------|-------------| | 1 | Name1 | text1 | text1 | | 1 | Name1 | text1 | text1 | | 1 | Name1 | null | text1 | | 2 | Name2 | text2 | text2 | | 2 | Name2 | text2 | null | | 3 | Name3 | null | text3 | 尚未达到0),可以使用lifespanCount。所以你的例子看起来像

agent.context.get()

(在库的0.6.0版中引入。)

但是...这要求上下文仍然有效。如果您使用的是“跟进意图”(可能会造成混乱),则寿命最初仅设置为2,因此它们可能已过期。

您应该做两件事:

  1. 不要使用跟进意图。尽管在某些情况下很有用,但它们可以缩小响应选项的范围,并且可以使对话变得非常紧张。

  2. 使用具有较长使用寿命的您控制的上下文将结果收集为Webhook的一部分。因此,在收集了新信息的每个Intent之后,将其存储在名为“ order”的Context中,例如,其寿命会在每次更新后重置为99。