How to deploy your hubot to Heroku and why your bot is not working after deploying

After completing the development of my Hubot, I decided to deploy it to Heroku.

I followed the tutorial on Github’s Hubot guideline as here.

For, short:

$ cd [path-to-your-hubot-folder]
$ heroku login

# Setup git (if not yet).
$ git init
$ git add .
$ git commit -m "Initial commit"

# Create a new heroku application.
$ heroku create

# Push to heroku master.
$ git push heroku master

# Set Slack token for heroku (Can be found at
# https://[your-slack-channel].slack.com/home 
# and under your Hubot app config).
$ heroku config:set HUBOT_SLACK_TOKEN=[xoxb-YOUR-TOKEN]

# Set heroku keep alive url (To keep your bot active).
$ heroku config:set HUBOT_HEROKU_KEEPALIVE_URL=$(heroku apps:info -s  | grep web-url | cut -d= -f2)

But my bot is not working at all, it keeps sleeping on the new Heroku’s bed and not responded to any of my commands.

I checked the build log on Heroku dashboard, it shows a lot of node modules are lack.

I viewed the .git_ignore file and its content:

node_modules
.DS_Store*
.hubot_history

So entire node_modules is ignored during commit and pushing to Heroku. So I think that it’s the reason why my bot is not working after deploying.

I remove that line, add node_modules then commit and push again to Heroku.

And finally… the monster awakens.

How to debug Github’s Hubot script?

First of all, Hubot is a complete Node.js application itself. And for Node.js applications in general, node-inspector is a celebrity out there as a debugger based on Blink Developer Tools.

If you did not install node-inspector yet, install it as a global package and under root.

$sudo npm install -g node-inspector

Wait for a few seconds till the installation process is done.

Inside your hubot project folder, start the debugger:

$node-inspector --no-preload --web-port 8123

When the following message appears, it means that our debug session is ready.

Node Inspector v1.0.0
Visit http://127.0.0.1:8123/?port=5858 to start debugging.

Now we need to start our bot, in a different way than the old ‘bin/hubot’ command and remember to put your bot name corresponding to your application:

$coffee --nodejs --debug node_modules/.bin/hubot --name "[your_bot_name]"

And to set a breakpoint, put debugger to any line of your code, like:

2017-04-04_174110

In Chrome, visit http://127.0.0.1:8123/?port=5858 to start your debugging session, debug like any of your web applications.