After extensive research, I delved into the realm of integrating DialogFlow requests with a webhook hosted on platforms like Heroku. With both Heroku and nodeJS impeccably installed on my system, I diligently followed the heroku tutorial to kickstart the process. All seemed well until an unexpected roadblock cropped up that's persistent despite having all required components in place.
To showcase my progress thus far, here is the link: https://github.com/joshua-yan/dialoguetest
The journey began with:
C:\Users\******>cd C:\Users\*****\guided
C:\Users\******\guided>npm init
C:\Users\******\guided>npm install express body-parser
Subsequently, I crafted the file index.js and tailored the example code (sourced from an online guide explaining imdb api integration). Despite putting my best foot forward with the provided script, executing node index.js in command prompt led me to believe there were phantom syntax errors lurking within my code.
This is what my index.js
looks like:
server.post('/get-movie-details', (req, res) => {
var p1x = req.body.queryResult.parameters['p1x'];
var p1y = req.body.queryResult.parameters['p1y'];
var p1z = req.body.queryResult.parameters['p1z'];
var p2x = req.body.queryResult.parameters['p2x'];
var p2y = req.body.queryResult.parameters['p2y'];
var p2z = req.body.queryResult.parameters['p2z'];
var p1 = [p1x, p1y, p1z];
var p2 = [p2x, p2y, p2z];
var answ = Math.sqrt(Math.pow(p2[0] - p1[0], 2) + Math.pow(p2[1] - p1[1], 2) + Math.pow(p2[2] - p1[2], 2));
return res.json({
speech: answ.toString(),
displayText: answ.toString()
});
(error) => {
return res.json({
speech: 'Something went wrong!',
displayText: 'Something went wrong!',
source: 'get-movie-details'
});
});
};
server.listen((process.env.PORT || 8000), () => {
console.log("Server is up and running...");
});
If you seek insights into the error message:
C:\Users\******\guided\index.js:23
});
^
SyntaxError: Unexpected token )
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:588:28)
at Object.Module._extensions..js (module.js:635:10)
at Module.load (module.js:545:32)
at tryModuleLoad (module.js:508:12)
at Function.Module._load (module.js:500:3)
at Function.Module.runMain (module.js:665:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:607:3
In summary: My endeavors with DialogFlow and Heroku have left me feeling lost and confused. While I've managed to set up DialogFlow without hiccups, grappling with the fulfillment aspect has proven to be quite challenging.
My objective is straightforward - take numerical inputs from DialogFlow, perform mathematical operations using javascript, and present the computed result. Seeking guidance on accomplishing this task sans the complexity of API integration, which most online guides tend to focus on.