Accessing previous follow up intent parameters within dialogflow-fulfillment

对着背影说爱祢 提交于 2021-02-07 08:09:22

问题


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.

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

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

回答1:


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']

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

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.

There are two things you should do:

  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.

  2. 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.



来源:https://stackoverflow.com/questions/53156526/accessing-previous-follow-up-intent-parameters-within-dialogflow-fulfillment

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!