The best place to start when explaining lunch-bot is to begin with Friday lunch at Sparkbox. Friday lunch is the one day a week we prepare and cook our own food as a team. Families are encouraged and welcome to come, and it’s a great time. As Sparkbox has grown in size (from six to twenty-six), we’ve realized we need a little more organization around Friday lunch.
To fully explain lunch-bot, I need to explain how we organize Friday lunch at Sparkbox. We have an extensive Google Sheet where each row contains the date, the main course, sides, lead cook, cooking assistants, lead cleaner, and cleaning assistants. Folks can sign up for the various roles, and because it’s a spreadsheet, everything is immediately up-to-date. lunch-bot is an attempt to provide meaningful reminders for the upcoming week.
lunch-bot is a Slack integration (excuse me, bot) that parses the Google Sheet and then posts to the Sparkbox Slack to remind those who are helping prepare and clean up the Friday lunch. It is currently configured to send out messages on Wednesdays and Thursdays. The Wednesday message is a private message to each person who’s signed up for the coming Friday. This serves as a nice reminder since people can sign up months in advance but may now have a schedule conflict. The message on Thursday is a public one in our #general channel, pinging the people who are helping with lunch the following day. This serves as a final point to make any changes before Friday prep has to begin.
I’ll walk through what makes Google Sheets and Slack (paired with Heroku) such powerful tools and perfect choices for creating lunch-bot—or a bot of any kind.
The Google Sheets API
Google Sheets is a pretty incredible spreadsheet application. One of the hidden gems of Google Sheets is that it has an API. We used the google-sheets-api npm package to fetch the lunch data in our sheet. Sadly, the Google Sheets API doesn’t offer a traditional API authentication flow (meaning it’s weird to set up), but we’ve documented the important bits in the lunch-bot README.
The Google Sheets API returns a pretty gnarly data object—expect to use a lot of the JS Array methods or lots of lodash, or both! Data manipulation aside, the beauty of using a Google Sheet as the “database” for lunch-bot is that anyone on the team can easily modify the data (e.g. swap weeks with another team member). A spreadsheet as a database is surprisingly user-friendly—who knew?
ES6 + Promises
lunch-bot is really a collection of API calls and data transformations to get all the information we need in a helpful format. ES6 arrow functions, ES6 string templates, and Promises help organize and clean the code. A nice example of these things in action is the generalAnnouncement file. We use Promise.all to wrap up the various API calls to the Google spreadsheet and string templates to build the actual message.
We also heavily use ES6 import statements (along with babel) to organize and compile our code. Using imports lets us organize our code and re-use common pieces.
Our bot needed a home and a way to get home—Heroku offered both. With Heroku, we get super simple deploys (just git push) and a convenient place for lunch-bot to run. Typically, something like lunch-bot would run via something like cron; however, Heroku isn’t a typical VPS situation. Heroku exposes cron-like functionality via the Heroku Scheduler addon. The Scheduler is very straightforward, and it’s free.
One of the perks of being on Heroku is we can structure our repo to take advantage of the Heroku Button. The Heroku Button makes it easy to create your own instance of an open-source app. We had to change a few things in our repo to make this seamless. One of those was how we handled API keys and various Sparkbox-specific bits. We ended up using environment variables to handle those situations. We can just prompt for those in the Heroku Button setup flow and store them as settings in the current Heroku instance. (Please triple check that you’re not publishing your Slack keys. If you have already committed them, clean your repo before making it public)!
lunch-bot isn’t a huge advancement in AI, but it is a very nice addition to the structure of the office. The potential applications of Google Sheets, Slack, and Heroku are huge. The fact that anyone can create a new bot for free is powerful. We hope this post whets your appetite for other Slackbot fun!