I'm getting an error regarding timeout. The log says a correct listening port should be set. Should I set up a web server instead of just using controller.spawn() and startRTM() function?
Error restarting application: Start app timeout
TIP: Application must be listening on the right port. Instead of hard coding the port, use the $PORT environment variable.
Code: same as Basic Usage code
var Botkit = require('botkit');
var controller = Botkit.slackbot({});
// connect the bot to a stream of messages
controller.spawn({
token: <my_slack_bot_token>,
}).startRTM()
// give the bot something to listen for.
controller.hears('hello',['direct_message','direct_mention','mention'],function(bot,message) {
bot.reply(message,'Hello yourself.');
});
% cat Procfile
web: node app.js
% cat manifest.yml
applications:
- path: .
memory: 128M
instances: 1
domain: mybluemix.net
name: xxx-bot
host: xxx-bot
disk_quota: 1024M
buildpack: https://github.com/cloudfoundry/nodejs-buildpack.git
Even I change the Procfile to run as worker, it sitll causes the error.
% cat Procfile
worker: node app.js
A log says... It looks down after 1 min. Probably setting timeout as 1 min.
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 down
0 of 1 instances running, 1 down
0 of 1 instances running, 1 down
I'm also developing a bot with Bluemix, you need to have a server running (Express, or make one with Botkit) and set it up with the process.env.VCAP_APP_PORT port.
Hi @SHBelsky ,
Thanks for the info. It runs with Blumix after adding the code below which sets express web server. It's a bit bothersome to need a extra job, since other public cloud like heroku and azure web app don't need it. It might be a cloud foundry policy, though...
const port = process.env.VCAP_APP_PORT || 3000;
controller.setupWebserver(port, function(err,webserver) {
controller.createWebhookEndpoints(controller.webserver);
});
@mttrs is it required to set up this webserver even when just communicating with RTM via websockets? running into something similar using a container service with docker
@aeweidne you don't need to create a webserver if you're using Slack. Just doing slackbot.startRTM(); should be sufficient.
edited this because I confused this GitHub topic with a different one :p
@aeweidne ,
You need to do it only when the app runs on any cloud foundry base PaaSs such as Bluemix. I'm not sure a container version works well, though.
@mttrs Is there a specific port that I need to expose on my container in order to take advantage of websockets? It's working fine locally and on a virtual machine but inside my container it is hanging without connecting.
@aeweidne ,
You mean that your container app runs on the bluemix? I've not tried the container app on bluemix, so I have no idea about it. But what if setting a web server with your app? The port should be VCAP_APP_PORT as above my comment.
@mttrs I am using a regular Docker container now, after moving on from Bluemix, and the websocket connection appears to close randomly after responding in chat. The node process on the container is still running, so it's not crashing. Going to try to use debug mode to get to the bottom of it. Thanks for the help
after turning on debug mode: this is the error I'm getting intermittently:
Mdebug: Got response { [Error: getaddrinfo ENOTFOUND slack.com slack.com:443]
code: 'ENOTFOUND',
errno: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'slack.com',
host: 'slack.com',
port: 443 } undefined
@aeweidne did you open the port 443 for SSL connection to slack.com?
I tried the same and seems like cloudfoundry/bluemix tries to ping the app after deploying and doesn't start the app if it is unable to find a port to connect with. @mttrs solution worked.
OUT Starting app instance (index 0) with guid xxxxxxxxxx
OUT
OUT > [email protected] start /home/vcap/app
OUT > node server/index.js
OUT info: ** No persistent storage method specified! Data may be lost when process shuts down.
OUT info: ** Setting up custom handlers for processing Slack messages
OUT info: ** API CALL: https://slack.com/api/rtm.start
OUT notice: ** BOT ID: yogibot_1 ...attempting to connect to RTM!
OUT notice: RTM websocket opened
ERR Instance (index 0) failed to start accepting connections
@aeweidne ,
My problem is solved and to separate from the other issue like docker, I'd like to close the issue. Please issue a new ticket if you wanna discuss the docker with bluemix.
Most helpful comment
Hi @SHBelsky ,
Thanks for the info. It runs with Blumix after adding the code below which sets express web server. It's a bit bothersome to need a extra job, since other public cloud like heroku and azure web app don't need it. It might be a cloud foundry policy, though...