首页 > 解决方案 > 使用履行向后续意图添加回退的问题

问题描述

我们正在用 mysql 制作一个聊天机器人。我们想为每个意图做一个后备,但它不起作用。

在此处输入链接描述

我们看到了这个视频(youtube)并应用了它。但它在后续意图中不起作用。

代码

└>Code_Ship

这是我们的意图结构。

即使添加了否定答案而不是 Code_Ship 中的期望答案,也会重复来自 Code_Ship 的问题。

这种方法不起作用,所以我正在修改 index.js 文件以实现。

  'use strict';

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

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 welcome(agent) {
  agent.add(`Welcome to my agent!`);
}

function fallback(agent) {
  agent.add(`I didn't understand`);
  agent.add(`I'm sorry, can you try again?`);
}

  
  function queryShipCode(connection){
  return new Promise((resolve,reject)=>{
    connection.query('SELECT *FROM ShipCode',(error,results,fields)=>{
      resolve(results);
    });
  });
}

function handleCode(agent){
  agent.setContext({
    name: 'first-call',
    lifespan: 2,
  });
}

function handleCode_Ship(agent){
  agent.getContext('first-call');
   const ShipCode_shipname = agent.parameters.shipname;
  return connectToDatabase()
  .then(connection => {
    return queryShipCode(connection)
    .then(result => {
      console.log(result);
      result.map(ShipCode => {
          if(ShipCode_shipname === ShipCode.name){
          agent.add(`ShipCode : ${ShipCode.code} , ShipName : ${ShipCode.name}`);
        }else if(ShipCode_shipname !== ShipCode.name){
          agent.add(`Sorry. I didn't understand.`);          
        }

      });
      connection.end();
    });
  });
}

这些是我们代码的一部分。

我不能尝试使用agent.add( Sorry. I didn't understand.); 在 handleCode_Ship() 中。我不能使用这种方法(否则)?

我们不擅长对话流。请告诉我们。

标签: dialogflow-eschatbotdialogflow-es-fulfillmentfulfillment

解决方案


推荐阅读