title: Return Promise Output in Dialoflow
body: <p>My problem is that in Dialogflow, My intent calls on a webhook THAT calls on a method.
  The method "CheckCosts" is running as all the console.logs work. 
  BUT the webhook is not retrieving anything from the output of the "CheckCosts" method.</p>
  
  <p>Below is the webhook. This is the webhook thats called upon when the intent is submitted.</p>
  
  <pre><code>function checkCostsIntent(app) {
      let origin = parameter.originAddress;
      let destination = parameter.destinationAddress;
      let costString = '';
  
      /*let testing = CheckCosts(origin, destination);
      app.add(testing);*/
  
      CheckCosts(origin, destination).then((cost)=&gt;{
          console.log(cost);
          costString = cost;
      });
  
      app.add(costString);
  }
  </code></pre>
  
  <p>Below is the method that the webhook will call upon.</p>
  
  <pre><code>function CheckCosts(originAddress, destinationAddress) {
      return new Promise((resolve, reject) =&gt; {
  
          let defaultPath = 'maps.googleapis.com/maps/api/distancematrix/json?units=metric';
          let APIKey = '&amp;key=&lt;API KEY&gt;';
          let origin = originAddress;
          let destination = destinationAddress;
          let newPath = defaultPath + '&amp;origins=' + origin + '&amp;destinations=' + destination + APIKey;
          let url = 'https://' + newPath;
          console.log(url);
  
          https.get(url, (res) =&gt; {
              let body = '';
              res.on('data', (d) =&gt; { body += d; }); // store each response chunk
              res.on('end', () =&gt; {
                  let response = JSON.parse(body);
                  console.log(response);
  
                  let distance = response.rows[0].elements[0].distance.text;
                  let travelTime = response.rows[0].elements[0].duration.text;
                  let distanceValue = response.rows[0].elements[0].distance.value;
                  let travelTimeValue = response.rows[0].elements[0].duration.value;
  
                  var ref = database.ref().child('price');
                  return ref.once('value').then(function (snapshot) {
                      let baseFair = snapshot.child('base').val();
                      let perKm = snapshot.child('perKm').val();
                      let perMin = snapshot.child('perMin').val();
  
                      let distanceCost = distanceValue / 1000 * perKm;
                      let timeCosts = travelTimeValue / 60 * perMin;
  
                      let cost = baseFair + distanceCost + timeCosts;
                      cost = cost.toFixed(2);
  
                      console.log('Total costs of distance is $' + distanceCost);
                      console.log('Total costs of time is $' + timeCosts);
                      console.log('The total cost of the ride is $' + cost);
                      let output = 'Distance between ' + origin + ' and ' + destination + ' is ' + distance + '. Time taken is ' + travelTime + '. And the total cost of the ride is $' + cost;
  
                      console.log(output);
                      resolve(output);
                  },
                  function (error) {
                      console.log('error' + error.code);
                  });
  
              });
              response.on('error', (error) =&gt; {
                  console.log(`error calling the Distance Matrix API:' ${error}`);
                  reject('fail');
              });
          });
      });
  }
  </code></pre>
  
  <p>Basically the main problem is that im not getting the <code>resolve(output)</code> in my webhook as i get nothing from the <code>console.log()</code> in my <code>checkCostsIntent()</code> webhook.</p>
  
  <p>Is there a problem with my Return promise?
  or my resolve?</p>