HangBot: a GroupMe bot that plays hangman

I made a bot that plays hangman through GroupMe messages. Check it out on Github.

screenshot of a game of hangman in chat with the bot
Screenshot of an actual game

After a friend of mine created a simple bot that replied to keywords with images, I made a more complex bot that played hangman. I chose hangman because it was relatively simple to code and fit the text-based nature of GroupMe bots well.

Development

Both this tutorial and this tutorial were invaluable in creating this bot. The latter is a fully functioning bot that reacts to comments so adding functionality on top of that was not difficult.

I sketched out the control logic for the hangman game before implementing it, and it was simple enough to not require much debugging. This was fortunate because due to the particulars of the workflow setup it is very easy to catch compile-time errors but runtime errors can only be detected by the script failing silently in a real-world test. I know there are ways to test it locally with simulated input but I didn’t bother for this project.

Sloppy code, future improvements

Because I treated this as a mini-hackathon there are many things I could take an active effort to improve later.

  • The array defining a list of 4000+ words for the random word picker is hardcoded into the main .js file and is also a one-liner spanning over 49k characters! Clearly this would be better off in a separate file, but it was most convenient this way.
  • Another potential improvement would be the reduction of this.res.writeHead(200) and this.res.end() lines everywhere. I found that I couldn’t put these into another function for simplicity but that is likely due to my limited understanding of how these functions operate.
  • For some reason after (usually) the 5th consecutive command the bot doesn’t respond for a while. This caused some difficulty in debugging as I didn’t know whether a lack of response was caused by the aforementioned lag or by a runtime error failing silently. This appears to be an issue with Heroku.