Thursday, 14 November 2019

Creating my first Nodejs app in Heroku for a Slackbot but I can't seem to get it to build correctly

So I have a slackbot that was working if someone talked to it, but I wanted to build out a few apis so I could do a little more with it and keep it in heroku.Here is my code:slackRoutes.js (made it small just to test) 'use strict'; module.exports = function(app) { var slackController = require('../controllers/slackController'); app.route('/message') .get(slackController.message_received) slackController:'use strict'; var mongoose = require('mongoose'), // Task = mongoose.model('Tasks'); exports.message_received = function(req, res) { if (err) res.send(err); res("Successful") } index.js:/** * A Bot for Slack! */ /** * Define a function for initiating a conversation on installation * With custom integrations, we don't have a way to find out who installed us, so we can't message them :( */ function onInstallation(bot, installer) { if (installer) { bot.startPrivateConversation({user: installer}, function (err, convo) { if (err) { console.log(err); } else { convo.say('I am a bot that has just joined your team'); convo.say('You must now /invite me to a channel so that I can be of use!'); } }); } } /** * Configure the persistence options */ var config = {}; if (process.env.MONGOLAB_URI) { var BotkitStorage = require('botkit-storage-mongo'); config = { storage: BotkitStorage({mongoUri: process.env.MONGOLAB_URI}), }; } else { config = { json_file_store: ((process.env.TOKEN)?'./db_slack_bot_ci/':'./db_slack_bot_a/'), //use a different name if an app or CI }; } /** * Are being run as an app or a custom integration? The initialization will differ, depending */ if (process.env.TOKEN || process.env.SLACK_TOKEN) { //Treat this as a custom integration var customIntegration = require('./lib/custom_integrations'); var token = (process.env.TOKEN) ? process.env.TOKEN : process.env.SLACK_TOKEN; var controller = customIntegration.configure(token, config, onInstallation); } else if (process.env.CLIENT_ID && process.env.CLIENT_SECRET && process.env.PORT) { //Treat this as an app var app = require('./lib/apps'); var controller = app.configure(process.env.PORT, process.env.CLIENT_ID, process.env.CLIENT_SECRET, config, onInstallation); } else { console.log('Error: If this is a custom integration, please specify TOKEN in the environment. If this is an app, please specify CLIENTID, CLIENTSECRET, and PORT in the environment'); process.exit(1); } /** * A demonstration for how to handle websocket events. In this case, just log when we have and have not * been disconnected from the websocket. In the future, it would be super awesome to be able to specify * a reconnect policy, and do reconnections automatically. In the meantime, we aren't going to attempt reconnects, * WHICH IS A B0RKED WAY TO HANDLE BEING DISCONNECTED. So we need to fix this. * * TODO: fixed b0rked reconnect behavior */ // Handle events related to the websocket connection to Slack controller.on('rtm_open', function (bot) { console.log('** The RTM api just connected!'); }); controller.on('rtm_close', function (bot) { console.log('** The RTM api just closed'); // you may want to attempt to re-open }); /** * API logic goes here! */ // Begining API var express = require('express'), app = express(), port = process.env.PORT, // mongoose = require('mongoose'), // Task = require('./api/models/todoListModel'), //created model loading here bodyParser = require('body-parser'); // mongoose instance connection url connection // mongoose.Promise = global.Promise; // mongoose.connect('mongodb://localhost/Tododb'); app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.json()); var routes = require('./api/routes/slackRoutes'); //importing route routes(app); //register the route app.listen(port); console.log('todo list RESTful API server started on: ' + port); // Ending API /** * Core bot logic goes here! */ // BEGIN EDITING HERE! controller.hears('wifi', 'direct_message', function (bot, message) { bot.reply(message, 'wifi login: \nwifi password: '); }); controller.hears(['hello', 'hi', 'greetings'], ['direct_mention', 'mention', 'direct_message'], function(bot,message) { bot.reply(message, 'Hello!'); }); /** * AN example of what could be: * Any un-handled direct mention gets a reaction and a pat response! */ //controller.on('direct_message,mention,direct_mention', function (bot, message) { // bot.api.reactions.add({ // timestamp: message.ts, // channel: message.channel, // name: 'robot_face', // }, function (err) { // if (err) { // console.log(err) // } // bot.reply(message, 'I heard you loud and clear boss.'); // }); //}); and package.json:{ "name": "itbot", "version": "1.0.0", "description": "The awesomest bot evar.", "main": "index.js", "scripts": { "start": "node index.js", "test": "echo \"Error: no test specified\" && exit 1", "postinstall": "bower cache clean && bower install && npm run build" }, "repository": { "type": "git", "url": "git+https://github.com/pri8771/easy-peasy-bot" }, "keywords": [ "slack", "bot" ], "author": "D.E. Goodman-Wilson", "license": "MIT", "bugs": { "url": "https://github.com/DEGoodmanWilson/easy-peasy-bot-app/issues" }, "homepage": "https://github.com/DEGoodmanWilson/easy-peasy-bot-app#readme", "engines": { "node": "12.13.0" }, "dependencies": { "botkit": "^0.6.21", "botkit-storage-mongo": "^1.0.2", "bower": "^1.5.2", "bower-json": "^0.8.1", "express": "^4.17.1", "mongodb": "^3.3.4", "mongoose": "^5.7.11" }, "devDependencies": { "nodemon": "^1.19.4" } } The error I keep getting is:-----> Node.js app detected -----> Creating runtime environment NPM_CONFIG_LOGLEVEL=error NODE_ENV=production NODE_MODULES_CACHE=true NODE_VERBOSE=false -----> Installing binaries engines.node (package.json): 12.13.0 engines.npm (package.json): unspecified (use default) Resolving node version 12.13.0... Downloading and installing node 12.13.0... Using default npm version: 6.12.0 -----> Restoring cache - node_modules -----> Installing dependencies Installing node modules (package.json + package-lock) > nodemon@1.19.4 postinstall /tmp/build_dbd4297e62fad3a9f96b6e58f3535fa5/node_modules/nodemon > node bin/postinstall || exit 0 Love nodemon? You can now support the project via the open collective: > https://opencollective.com/nodemon/donate > itbot@1.0.0 postinstall /tmp/build_dbd4297e62fad3a9f96b6e58f3535fa5 > bower cache clean && bower install && npm run build bower ENOENT No bower.json present npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! itbot@1.0.0 postinstall: `bower cache clean && bower install && npm run build` npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the itbot@1.0.0 postinstall script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR! /tmp/npmcache.Kl0L9/_logs/2019-11-14T18_53_01_536Z-debug.log -----> Build failed We're sorry this build is failing! You can troubleshoot common issues here: https://devcenter.heroku.com/articles/troubleshooting-node-deploys If you're stuck, please submit a ticket so we can help: https://help.heroku.com/ Love, Heroku ! Push rejected, failed to compile Node.js app. ! Push failed

Submitted November 14, 2019 at 07:01PM by number001

No comments:

Post a Comment