2
'use strict';
var http = require('http');
var request = require('request');
exports.weatherWebhook = (req, res) => {
    const host = 'http://api.openweathermap.org/';
    const wwoApiKey = '7ffbb59524a81a6ac42ac3e942f68c5d';
    var city = req.body.queryResult.parameters['geo-city'];
    var path = 'data/2.5/weather?' +'APPID=' + wwoApiKey +'&q=' +city+'&units=imperial';
    request(host+path,function(error,response,body)
    {   
        var a=JSON.parse(body);
        console.log(JSON.parse(body));
        var temp=a.main.temp;
        var location=a.name;
        console.log(location);
        res.json({ 'fulfillmentText': city }); 
    });


};

Why do I get internal server error and how can I pass values to fulfillment text via resolve function?

Sindhu Arju
  • 438
  • 1
  • 5
  • 15

1 Answers1

2

You have a number of problems here, so it is difficult to know where to start.

You say you want to use dialogflow's parameters, but you haven't included the dialogflow fulfillment library at all, and you're not doing any intent handling, so it isn't clear what you're having trouble with there.

When you do, you will probably want to use Promises instead of callbacks.

Finally, if you're getting errors, then posting the error log along with your code will help us point you in the right direction without having to run the code ourselves.

Prisoner
  • 49,922
  • 7
  • 53
  • 105