在对话流实现中访问先前的后续意图参数 [英] Accessing previous follow up intent parameters within dialogflow-fulfillment

查看:56
本文介绍了在对话流实现中访问先前的后续意图参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using the default dialogflow code provided in the inline editor, based on dialogflow-fulfillment ^0.5.0 to collate all the parameters given over several follow up intents. I have a setup where follow up intents ask questions, resulting in a final intent that has all questions asked.

从dialogflow控制台内的先前意图中提取数据以包含在响应中,将仅使用#order-cream-followup.chocolate-type 从先前意图或中获取参数> $ quantity 从当前意图中获取参数.但是,虽然 agent.parameters ['quantity'] $ quantity 一样工作,但我找不到与#order-cream-followup等效的方法在对话框流程实现中的.chocolate-type

Pulling data from previous intents inside the dialogflow console to include in a response would just be using i.e. #order-cream-followup.chocolate-type to get a parameter from a previous intent or $quantity to get a parameter from the current intent. But while agent.parameters['quantity'] works like $quantity, I can't find the way to do the equivalent of #order-cream-followup.chocolate-type within dialogflow-fulfillment

很抱歉,如果这是一个显而易见的答案,那么我会迷失在有关Google的Dialigflow和操作的各种不同文档中.

Apologies if this is an obvious answer, I'm getting lost in the various different documentation for dialigflow and action on google in general.

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

My code:(currently just logging to console before adding code to handle pushing out that data)

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

推荐答案

要获取仍处于活动状态的上下文(即,其 lifespanCount 尚未达到0),可以使用 agent.context.get().所以您的示例看起来像

To get a context that is still active (ie - its lifespanCount has not reached 0), you can use agent.context.get(). So your example would look something like

agent.context.get('order-cream-followup').params['chocolate-type']

(在库的0.6.0版中引入.)

(This was introduced in version 0.6.0 of the library.)

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

However... this requires that the context still be valid. If you are using Followup Intents (which can get messy), the lifespan is originally only set to 2, so they may have expired.

您应该做两件事:

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

  1. Don't use Followup Intents. While useful in some cases, they can narrow the response options too much and can make very stilted conversations.

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

Use a Context that you control, with a large lifespan, to collect the results as part of a webhook. So after each Intent where you have collected new information, you store this in a Context named, for example "order" that has a lifespan that you reset to 99 after each time you update it.

这篇关于在对话流实现中访问先前的后续意图参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆