首页 > 解决方案 > 如何在 Dialogflow 实现中获取当前意图的名称?

问题描述

我想在实现中获取当前意图的名称,以便我可以根据我所处的不同意图处理不同的响应。但我找不到它的功能。

function getDateAndTime(agent) {    
    date = agent.parameters.date; 
    time = agent.parameters.time;

    // Is there any function like this to help me get current intent's name?
    const intent = agent.getIntent();
}

// I have two intents are calling the same function getDateAndTime()
intentMap.set('Start Booking - get date and time', getDateAndTime);
intentMap.set('Start Cancelling - get date and time', getDateAndTime);

标签: dialogflow-esdialogflow-es-fulfillment

解决方案


request.body.queryResult.intent.displayName将给出意图名称。

'use strict';

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

exports.dialogflowFirebaseFulfillment = functions.https.onRequest((request, response) => {
  const agent = new WebhookClient({ request, response });

  function getDateAndTime(agent) {
      // here you will get intent name
      const intent = request.body.queryResult.intent.displayName;
      if (intent == 'Start Booking - get date and time') {
        agent.add('booking intent');
      } else if (intent == 'Start Cancelling - get date and time'){
          agent.add('cancelling intent');
      }
  }

  let intentMap = new Map();
  intentMap.set('Start Booking - get date and time', getDateAndTime);
  intentMap.set('Start Cancelling - get date and time', getDateAndTime);
  agent.handleRequest(intentMap);
});

但是如果你使用两个不同的函数会更有意义intentMap.set


推荐阅读