Poker Facilitator Messenger Bot

03 May 2020

Check out the GitHub repo here
Technologies Used: Node.js, Express, MongoDB, Mongoose, and Facebook Developer Tools

One Saturday evening in January I was hanging out with some friends and we wanted to play poker, however, my friend didn’t have a poker set handy at his house. We go around his house looking for anything we could use as chips, such as marbles or a ton of pennies and ended up using our phone calculators. During the game, we were spending far too much time trying to keep track of everything and making sure everyone’s scores were correct. When I went home that night I thought to myself what if there was a website you could use to replace the need for chips in Poker.

Fast forward two months later, I took a couple of courses on Python and Flask and created a simple web application with the vision of eventually creating a web application that could facilitate poker games. I thought to myself that a website may not be ideal for the game and thought of creating some sort of texting based bot. After seeing what would be the most feasible option for me I decided on creating a messenger bot and found a tutorial on how to do so. Creating the bot would require some Node.js knowledge and due to Coronavirus Pluralsight was offering free April, so I took a course on the basics on Node.js before getting started with the tutorial.

In less than a day I had a bot that was up and running that I could send and receive messages from and now I just had to create the logic behind the game. I decided on creating two main classes, a player class to control the player objects and a game class for the game objects. I thought of the basic features to have at first, such as generating a game pin, letting other people join the game with a game pin, initializing user’s wallets, and having an option to call, check, or raise for each player.

As I was trying to think of scenarios that occur in Poker or how the flow works I resulted in playing a few online games of poker to monitor how calling and raising works in a real game. I ended up deciding to get rid of the check button and simply allow users to call with 0 to check. In order to add some features, I had to read more of the Facebook Developer API docs to get the user’s name from their messenger ID for implementing features that require the admin to select the user who wins.

While testing some of these basic features of having all the users use the buttons to call, check, and raise a friend of mine pitched in some suggestions that greatly help improve the overall game, as he suggested telling everyone what the last move was and making sure the game can recognize the fact that someone is going “all-in”. I went through multiple iterations of adding smaller features and testing with other people to aim to get as much feedback as possible to make the bot as easy and intuitive to use as possible.

There would be times where I would be totally zoned in just working on making sure certain features were working the way I’d want them to and the next thing I knew was it was 5 am in the morning. Anyways, eventually, I got a fully working version without the use of a database as I just had a class to act as the database at this point and now wanted to learn how I could use Mongo.DB to store the objects.

Sample screenshots of the bot

Honestly, I didn’t expect connecting the bot to the database to be as hard as it was, as I had previously used a database for another project. However, I had to spend a substantial amount of time refactoring and changing up some of the methods I had to avoid circular imports because of the schemas needed to use Mongoose and Mongo.db. Eventually, I did even more testing and finally, all of the features of the bot were working and I added a few more features to improve the overall experience and know that I can easily message this bot through my computer or phone.

Now I know if I ever want to play poker and don’t have any chips around my friends and I can message the Poker Facilitator bot and be ready to play. It wouldn’t be possible for me to build this bot without the input of a few friends and the online tutorials I used.