A Slackbot that streamlines the whole process
In order to fulfill the initially requested solution, we decided to include two applications created with Node.js. One - for the Slack bot and the other - for gathering information and analytics (let's call it the analysis app). For the Slack bot, we used Bolt Slack SDK because it's built on node-slack-sdk and has good support of both Node.js and Typescript. As the client's request was to put all collected information into a spreadsheet, we used Node.js in association with Google Spreadsheets API for the analysis app. Of course, both applications - the bot and the analysis app were created using Typescript to provide scalability and code clearness. To make the final solution easy to setup-and-deploy we decided to implement a serverless architecture. Suchwise, we used Firebase Functions for deployment and hosting. When everything was almost finished up and ready to use, 2 problems revealed:
- Google Spreadsheets API only allows 100 requests per 100 seconds on a free basis. Our application was to track reactions so it might overwhelm this limitation at times a new question was posted.
- Firebase Function warmup time might be up to 3-5 seconds. This means that if the application was not used for a couple of minutes, Function would shut down and have a 3-5 seconds delay each time it is called again. We could set the shutdown time to be long, but there was no way to setup Function so it never stops.
To resolve the first problem, we created a helper Function and made it scheduled. Now, we were putting all reactions information to Firestore which has no request per time limitation. It helped to keep data persistence. And our scheduled helper Function was syncing Firestore with Spreadsheet with only a single request per 2 minutes. The first issue was resolved. To deal with the second one, we used the same helper scheduled Function - it was sending an empty request to the main Function every two minutes. And set the main Function to postpone shutdown for 2 minutes 30 seconds. This way the main Function never shuts down.