xjm
xjm

Reputation: 184

DialogFlow app does not get deployed in Heroku

I have no experience whatsoever with using dialog flow so I'm trying to follow this youtube tutorial to make a bot. Now, the bot works well when I tested it on the DialogFlow console, but it doesn't get deployed on Heroku. Whenever I try to open the url where the app's supposed to be deployed in, I keep on getting "Internal server error" (this used to be {"speech":"","displayText":"","source":"webhook"} before I applied this). It says "Failed to load resource: the server responded with a status of 500 (Internal Server Error)" in the console.

I tried following the docs here but I used Heroku instead of Google Platform and I'm not sure if I'm doing things right.

This is the current build log I got from the latest build:

-----> Node.js app detected
-----> Creating runtime environment

   NPM_CONFIG_LOGLEVEL=error
   NPM_CONFIG_PRODUCTION=true
   NODE_VERBOSE=false
   NODE_ENV=production
   NODE_MODULES_CACHE=true
-----> Installing binaries
   engines.node (package.json):  4.1.1
   engines.npm (package.json):   unspecified (use default)

   Resolving node version 4.1.1...
   Downloading and installing node 4.1.1...
   Using default npm version: 2.14.4
-----> Restoring cache
   Skipping cache restore (not-found)
-----> Building dependencies
   Prebuild detected (node_modules already exists)
   Rebuilding any native modules
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/ejs
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/express
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/accepts
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/mime-types
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/mime-db
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/negotiator
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/array-flatten
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/body-parser
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/bytes
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/content-type
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/debug
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/ms
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/depd
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/http-errors
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/inherits
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/http-errors/node_modules/setprototypeof
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/statuses
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/iconv-lite
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/on-finished
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/ee-first
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/qs
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/raw-body
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/unpipe
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/type-is
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/media-typer
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/content-disposition
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/cookie
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/cookie-signature
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/encodeurl
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/escape-html
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/etag
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/finalhandler
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/parseurl
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/fresh
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/merge-descriptors
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/methods
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/path-to-regexp
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/proxy-addr
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/forwarded
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/ipaddr.js
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/range-parser
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/safe-buffer
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/send
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/destroy
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/mime
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/serve-static
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/setprototypeof
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/utils-merge
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/vary
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/node-env-file
   [email protected] /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/js
   Installing any new modules (package.json)
-----> Caching build
   Clearing previous node cache
   Saving 2 cacheDirectories (default):
   - node_modules
   - bower_components (nothing to cache)
-----> Build succeeded!
-----> Discovering process types
   Procfile declares types -> web
-----> Compressing...
   Done: 11.5M
-----> Launching...
   Released v3
   https://make-sandwich.herokuapp.com/ deployed to Heroku

Please help me fix this error. I've posted the code here.


additionally, i've tried deploying the app on localhost and i keep getting this error:

Error: Cannot find module 'js'
    at Function.Module._resolveFilename (module.js:536:15)
    at Function.Module._load (module.js:466:25)
    at Module.require (module.js:579:17)
    at require (internal/module.js:11:18)
    at new View (C:\Users\EtoNalangGamitinMo\Downloads\make-sandwich-master\make-sandwich-master\node_modules\express\lib\view.js:81:14)
    at Function.render (C:\Users\EtoNalangGamitinMo\Downloads\make-sandwich-master\make-sandwich-master\node_modules\express\lib\application.js:570:12)
    at ServerResponse.render (C:\Users\EtoNalangGamitinMo\Downloads\make-sandwich-master\make-sandwich-master\node_modules\express\lib\response.js:1008:7)
    at C:\Users\EtoNalangGamitinMo\Downloads\make-sandwich-master\make-sandwich-master\index.js:22:11
    at Layer.handle [as handle_request] (C:\Users\EtoNalangGamitinMo\Downloads\make-sandwich-master\make-sandwich-master\node_modules\express\lib\router\layer.js:95:5)
    at next (C:\Users\EtoNalangGamitinMo\Downloads\make-sandwich-master\make-sandwich-master\node_modules\express\lib\router\route.js:137:13)

Upvotes: 0

Views: 552

Answers (1)

Prisoner
Prisoner

Reputation: 50711

The problem is that the directions at https://dialogflow.com/docs/getting-started/basic-fulfillment-conversation assume you're using Google's Cloud Functions (GCF). GCF makes it simple to deploy node.js functions without some boilerplate code required to attach those functions to an HTTP endpoint.

Heroku, however, needs to have those endpoints explicitly setup. GCF expects an express-like environment, which is one that Heroku also supports. Based on the barebones Heroku example at https://github.com/heroku/node-js-getting-started/blob/master/index.js, you might need to add lines such as this (which I haven't tested) to invoke your makeSandwich function:

const express = require('express')
const PORT = process.env.PORT || 5000

express()
  .use(express.static(path.join(__dirname, 'public')))
  .get('/', (req, res) => exports.makeSandwich( req, res ))
  .listen(PORT, () => console.log(`Listening on ${ PORT }`));

You'll also need to adjust your package.json to make sure it includes the express package.

Upvotes: 1

Related Questions