Integrating Dialogflow with a Heroku JavaScript application

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.

Answer №1

Let's clean up your code by focusing on braces and parentheses:

server.post('/get-movie-details', (req, res) => {  // <-- Open brace...
    return res.json({
    });
    (error) => {  // <-- Should this error function be placed?
                  //     It's currently inside the success function
        return res.json({
        });
    });  // <-- ...mismatched closing brace
};

You may want to close your (req, res) function after returning res.json(), then open the error function as another argument to server.post(), like this:

server.post('/get-movie-details', (req, res) => {
    return res.json({
    });
},
(error) => {
    return res.json({
    });
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Contrasting {} and {} as any in TypeScript

Seeking clarity on TypeScript, what sets apart (foo and foo2) from (foo3 and foo4)? (foo and foo2) as well as (foo3 and foo4) produce identical results, yet during compilation, a red underline appears under foo2 and foo3. https://i.stack.imgur.com/lWaHc. ...

disallow rowOnClick function in the datatable

I am facing an issue with a t:datatable where the rowOnClick event is being triggered. The problem arises when there is an icon in a column that, when clicked, opens a popup. This action also triggers the rowOnClick event, which I don't want. For this ...

Switching from using a computed property in Vue 2 to implementing the Vue 3 Composition API

I am currently in the process of updating my Vue 2 application to Vue 3 and I have been exploring how to work with computed properties using the Composition API in Vue 3. One particular challenge I am facing is migrating a Vue 2 computed property that pro ...

Scrolling is endless with jCarousel - just press a button to keep moving even when you reach the first or

I seem to be experiencing a problem with jCarousel where, upon starting at the beginning, pressing the left button fails to scroll the carousel. The expected behavior is for the carousel to cycle to the end item when the left button is pressed while the f ...

Looking for a custom textured circle in three.js?

Is there a way to create a circle with a texture on one side in three.js without using sprites? I was considering using THREE.CylinderGeometry, but I'm unsure of where to add the "materials" in the new THREE.CylinderGeometry(...) section. Any suggest ...

blurring out of an input field and a division element

I am currently working on creating a dropdown suggestion box that hides when the input field and dropdown box are no longer in focus. My HTML code: <input type="text" id="user_address"> <div id="user_address_sg">SUGGESTION</div> <di ...

What is the reason for being unable to remove the event listener from a sibling element?

function show1() { console.log("ok1"); document.getElementById("a2").removeEventListener("click", delegate); } function show2() { console.log("ok2"); } function show3() { console.log("ok3"); } function delegate(event) { var flag = event.target ...

Having trouble getting Vue.js hello world to display on the page

I am attempting to create a Hello World app following the Vue.js site's get started documentation. Everything seems to be in order, but only the HTML code is being displayed on the page. Vue version: 1.0.26 Below is the HTML code: <!DOCTYPE ht ...

What is the best way to retrieve the initial cell from a row that the user is currently hovering over?

Is there a way to extract the first cell from a row when a user hovers over it and then clicks a specific key combination? (considering using jQuery) I have a table set up similarly where placing the mouse over a tr and pressing ctrl+c will copy the ID t ...

A Vue computed property is returning the entire function instead of the expected value

One of my computed properties is set up like this: methods: { url_refresh: function (id) { return `${this.url_base}?start=${Date.now()}` } } However, when I attempt to print the value on mount: mounted() { console.log(this.url_refresh) ...

Obtain the parameter fetching identical identifier

When I click on a search result on the left, I want it to load in the right div without refreshing the page or opening a new one. The search generates three results with pagination. However, no matter which result I click, the same ID loads. Can anyone spo ...

What is the best way to incorporate a gratitude note into a Modal Form while ensuring it is responsive?

Currently, I have successfully created a pop-up form, but there are two issues that need fixing. The form is not responsive. After filling/submission, the form redirects to a separate landing page for another fill out. Expected Outcome: Ideally, I would ...

Does an invisible property value exist?

Instead of: if ( ! $('#XX').is(':visible) ) Is there a property named invisible? I tested that one out, but it seems to not work. Appreciate the help! ...

AutoComplete feature activates when I choose a suggestion from the dropdown menu

<Autocomplete disablePortal id="geo-select-country" options={all_country} defaultValue={nation} onChange={(event, selected_nation) => { set_nation(selected_nation); }} ...

Objects may unexpectedly be sorted when using JavaScript or Node.js

When I execute the following code using node app.js 'use strict'; var data = {"456":"First","789":"Second","123":"Third"}; console.log(data); I am receiving the following output: { '123': 'Third', '456': 'F ...

When a project sets useBuiltIns to 'usage', there is an issue with importing the library generated by Webpack

I am eager to create a versatile UI component library and bundle it with Webpack. However, I encountered an issue when trying to import it into another project that has useBuiltIns: 'usage' specified in the babelrc file. The import fails with the ...

Creating a password with two distinct numbers using regular expressions

In javascript I am struggling to create a password that meets the criteria of having at least eight characters, including two SEPARATE digits, one uppercase and one lowercase letter, as well as one special character (-, @, #, $, &, *, +) but not /, !, ? ...

Error: Type Error - 'style' is not defined in the Progress Bar Project

Having recently started learning Javascript, I have been engaging with various tutorials and projects in order to gain familiarity with the language. One particular tutorial that caught my attention is a Progress-Bar tutorial by "dcode" available at this l ...

Oops! There seems to be a problem with your AngularJS/JavaScript code. The error message is "Uncaught ReferenceError:

As I venture into the world of AngularJS and JavaScript, I am working on creating a 'blog' using these technologies. Here is my HTML view code- <div ng-controller="Controller1"> <form ng-submit="sub()" role="form"> Title: <textar ...

Calculating the number of rows using JQuery

After browsing similar questions on Stack Overflow, I have not found a solution that fits my specific case. I have multiple tables on a page that share the same template without unique IDs. I am trying to determine if the rows are empty when certain data i ...