首页 > 解决方案 > DialogFlow 参数值

问题描述

在 Dialogflow 中,我有一个名为 GetLocation 的 Intent。用户可以输入一个短语,例如:我想看看印度,参数“位置”存储该位置。对于我的参数,它的名称是“位置”,它的实体是sys.location. Dialog Flow 能够识别我的位置。

接下来,Dialog Flow写入我的Firebase数据库并写入数据库的位置参数(位置:(来自DialogFlow的位置)。问题是,它不是正常写入数据库的位置参数,而是更改了“位置”到管理区域:(来自 DialogFlow 的位置)。如何阻止它重命名 firebase 数据库中的位置参数?

这是我的履行代码:

function yourFunctionHandler(agent) {

       const location = agent.parameters.Location; 

    

    return admin.database().ref('locations').transaction((locations) => {
    if(locations !== null) {

      locations.place = location;
      
      
      agent.add(`Our recorded locations ` + location);

    }

    return location;
  }, function(error, isSuccess) {
    
  });
    
  //  return admin.database().ref('/locations/place').set(location);
  }

标签: firebasedialogflow-es

解决方案


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 handleAge(agent) {
    const age = agent.parameters.age;

    agent.add(`Thank you...`);

    return admin.database().ref('ageInfo').transaction((ageInfo) => {
      if(ageInfo !== null) {
        let oldAverage = ageInfo.runningAverage;
        let oldTotalCount = ageInfo.totalCount;
        let newAverage = (oldAverage * oldTotalCount + age) / (oldTotalCount + 1);
        ageInfo.runningAverage = newAverge;
        ageInfo.totalCount+=1;
        agent.add(`Average age stored` + newAverage);
      }
      return ageInfo;
    }, function(error, isSuccess) {
      console.log('error: ' + isSuccess);
    });

  }


  // Run the proper function handler based on the matched Dialogflow intent name
  let intentMap = new Map();
  intentMap.set('AskAge', handleAge);
  agent.handleRequest(intentMap);
});

URL= http://www.peterfessel.com/2018/07/google-dialogflow-chatbot-realtime-database-tutorial-read-write/


推荐阅读