John Smith
John Smith

Reputation: 67

DialogFlow Parameter value

In Dialogflow I have a Intent called GetLocation. The user can input a phrase like: I want to look at India, and the Parameter "Location", stores that location. For my Paramater, its name is "Location" and its entity is sys.location. Dialog Flow is able to recognize my location.

Next, Dialog Flow writes to my Firebase database and writes to the location parameter of the database (location: (location from DialogFlow). The problem is, instead of normally writing to the location parameter of the database, it also changes the "location" to admin-area: (location from DialogFlow). How do I stop it from renaming the location parameter in the firebase database?

Here is my Fulfillment code:

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

Upvotes: 0

Views: 3399

Answers (1)

서희상
서희상

Reputation: 11

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/

Upvotes: 1

Related Questions