How to Create an Internal Bot With Node.JS and Hubot?
In our everyday work we use many tools that help us create many things better and faster - Confluence, Github, Jira, Google Calendar etc. We are growing fast and the number of tools we use can be a little overwhelming for newcomers and even for veterans.
It's sometimes difficult to find all the needed pieces of information without getting disturbed. Some of the tools we use don’t provide the kinds of summaries or insights that could help us to better monitor our work progress.
As an IT company, we always try to use our skills to automate internal processes that are indispensable parts of our job to allow us to focus on the most important things. Internal projects also serve as idea validators and experimental laboratories.
Because Slack is the de facto means of communication in our company, we decided to use it as the interface for our solution. We wanted to create a chatbot that would help us reduce work on repeatable and tedious tasks that could be easily integrated with our favorite tools and automate some internal processes.
Most important requirements
Ability to communicate with the bot through Slack
Providing an architecture that allows us to enhance the bot through new plugins easily
Ability to create periodic notifications
Make the bot a member of our team!
We went with Node.js for our chat-bot. It’s well known for being performant under heavy loads and one of the go-to solutions for messaging applications.
This choice allows us to use many well-developed libraries. Many of them are created to make the integration process with 3rd party platforms easier. For example, we have integrated our bot with services like GitHub, Slack, and CircleCI using vendor-provided packages, most of which were built by the companies whose services we integrated with. Communication with data providers is asynchronous, thanks to async/await & promises - Node.js makes that process much easier and faster to implement. As mentioned before, we had to communicate with multiple services, therefore, considering all the advantages that this solution provided us with, we started developing our own bot. We knew that by using this technology the development process would be much faster. We wanted for our bot to be easy to extend so that new features could be added by anyone knowing Node.js. This technology allowed us to build the perfect environment for our bot to run and to grow.
The challenges we had to face up were:
Creating a flexible architecture for the project
Lowering the entry threshold for new developers
Preparing a testing environment
The biggest challenge was to prepare the bot’s architecture in a way that would allow feature developers to add new plugins with minimal effort. We have done our best to make the entry threshold low.
Because of our decision to use self-contained plugins, some parts of the code were repeated in multiple places. It is not a good practice to repeat the same lines of a code, as it makes refactoring take much longer and makes the software harder to maintain. Knowing that, we decided that creating our own library called `bob-utils` would be the best option here. Thanks to that solution the plugins stayed self-contained and the redundancy problem was resolved.
The unified plugin architecture made it possible to build a generator that creates the structure and the schema of the new plugin as well as configuration files and a test suite. The plop library has helped us with that process.
The biggest problem during development was writing tests. Thankfully, a couple of open source libraries came in handy. After a few modifications to adjust them to our needs, they became a fundamental ecosystem for writing sufficient, web-like, tests.
As a result of our work, we created Bob, our Netguru bot. Thanks to Node.js, we built an extendable tool in a small amount of time. As time goes by, we are able to add new features that solve problems and automate our workflow.We have done our best to make the process of adding new features to the bot as easy as it could be. Now we have the possibility to add new features when needed, with minimal time required to do so. This means that the bot will be extended with new features and integrated with different services as time goes by. We have many passionate people with many extraordinary ideas for new features! The bot keeps the track of the most frequently used commands. That data can be used to improve this tool or even implement a machine learning process to make Bob even more flexible.