DialogFlow app does not get deployed in Heroku

痴心易碎 提交于 2019-12-13 20:19:09

问题


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
   ejs@2.5.7 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/ejs
   express@4.16.2 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/express
   accepts@1.3.4 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/accepts
   mime-types@2.1.17 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/mime-types
   mime-db@1.30.0 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/mime-db
   negotiator@0.6.1 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/negotiator
   array-flatten@1.1.1 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/array-flatten
   body-parser@1.18.2 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/body-parser
   bytes@3.0.0 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/bytes
   content-type@1.0.4 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/content-type
   debug@2.6.9 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/debug
   ms@2.0.0 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/ms
   depd@1.1.1 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/depd
   http-errors@1.6.2 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/http-errors
   inherits@2.0.3 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/inherits
   setprototypeof@1.0.3 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/http-errors/node_modules/setprototypeof
   statuses@1.3.1 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/statuses
   iconv-lite@0.4.19 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/iconv-lite
   on-finished@2.3.0 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/on-finished
   ee-first@1.1.1 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/ee-first
   qs@6.5.1 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/qs
   raw-body@2.3.2 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/raw-body
   unpipe@1.0.0 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/unpipe
   type-is@1.6.15 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/type-is
   media-typer@0.3.0 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/media-typer
   content-disposition@0.5.2 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/content-disposition
   cookie@0.3.1 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/cookie
   cookie-signature@1.0.6 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/cookie-signature
   encodeurl@1.0.1 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/encodeurl
   escape-html@1.0.3 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/escape-html
   etag@1.8.1 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/etag
   finalhandler@1.1.0 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/finalhandler
   parseurl@1.3.2 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/parseurl
   fresh@0.5.2 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/fresh
   merge-descriptors@1.0.1 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/merge-descriptors
   methods@1.1.2 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/methods
   path-to-regexp@0.1.7 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/path-to-regexp
   proxy-addr@2.0.2 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/proxy-addr
   forwarded@0.1.2 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/forwarded
   ipaddr.js@1.5.2 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/ipaddr.js
   range-parser@1.2.0 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/range-parser
   safe-buffer@5.1.1 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/safe-buffer
   send@0.16.1 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/send
   destroy@1.0.4 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/destroy
   mime@1.4.1 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/mime
   serve-static@1.13.1 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/serve-static
   setprototypeof@1.1.0 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/setprototypeof
   utils-merge@1.0.1 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/utils-merge
   vary@1.1.2 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/vary
   node-env-file@0.1.8 /tmp/build_07222934258aa157e39d784f7e60dd1c/digracesion-make-sandwich-9119d54/node_modules/node-env-file
   js@0.1.0 /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)

回答1:


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.



来源:https://stackoverflow.com/questions/48161060/dialogflow-app-does-not-get-deployed-in-heroku

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!