According to the documentation,
"When an intent in which a webhook was enabled is triggered, Dialogflow sends data to the service in the form of POST request with a POST body in the format of response to a query."
So I assume that a GET request is not possible...isn´t it?
In Postman I am able to make a GET request using my code but after deploying to Heroku and setting the URL in the fulfillment section, I am not able to get any proper response beyond a "Webhook call failed. Error: 404 Not Found".
Thanks a lot.
Here´s the code. This was my first attempt using Node :-)
const express = require('express');
const bodyParser = require('body-parser');
const http = require('https');
var port = process.env.PORT || 8080;
const server = express();
server.use(bodyParser.json());
server.post('/get-movie-details', function (req, res) {
//This line is crashing the app in Heroku from Dialogflow. Paramaters are not correctly passed
let movieToSearch = req.body.result.parameters.query;
let finalurl = encodeURI('https://api.themoviedb.org/3/search/movie?api_key=c21ed50674dabf90143d1136bf9279ae&language=en-US&query=' + req.body.result.parameters.query + '&page=1&include_adult=false');
console.log('This is the finalUrl: ' + finalurl);
http.get(finalurl, (responseFromAPI) => {
responseFromAPI.on('data', function (chunk) {
let movie = JSON.parse(chunk)['results'][0];
let dataToSend = movie.original_title + ' is a ' + movie.vote_average + ' vote average released in ' + movie.release_date + '. Maybe you want some more information?';
return res.json({
speech: dataToSend,
displayText: dataToSend,
source: 'The movieDataBase'
});
});
}, (error) => {
return res.json({
speech: 'Something went wrong!',
displayText: 'Something went wrong!',
source: 'get-movie-details'
});
});
});
server.listen(port);
console.log('Server started! At https://localhost:' + port);