Accountability, Motivation and Slackbots
I've been playing with Slack applications and chatbots for a while now, I find Slack to be a very interesting frontend for content that can be interacted with through a group with shared interest, they can be useful to keep every one up to date on work matters or automate some process, as well as have fun in more casual Slack channels.
Earlier this year, before there were any restrictions many of us in a particular Slack group was taking up running as a way to get fit, we discovered Strava had a feature for groups where we could compete in a leaderboard as a way to motivate each other.
With a channel dedicated to discuss running and fitness I looked into integrating Strava and Slack so we could bring our club's result into the channel, turns out this was quite easy with Zapier, with a few clicks we quickly had a message on the channel whenever someone posted a new activity:
I also found Slava, an independent app which fullfills the same purpose with slightly better formatted messages:
It was a major hit, Slack messages kept our activities as continuous points and made us motivate each other, throughout the year the Strava club accrued more than 500 activities from 16 members totalling over 2000km and we continue to post new runs multiple times a day.
#Advent of Code
Later on the year, as one of my favorite holiday season traditions start, Advent of Code, I thought if maybe the same formula would work, so I decided to create a Slack app to notify our channel whenever someone completed one of the puzzles
While there were no ready-made integrations or Zapier apps for this, it shouldn't be so hard to create one, I decided to try it myself since the whole activity is about coding anyway, so to speed things up I thought about giving serverless functions with Amazon Lambda a go.
Since Advent of Code has a pretty simple API for private leaderboards, it was easy enough to just query the API and filter all the completions with a timestamp larger than the previous time checked, then format the message and post to a Slack webhook, so I wrote a simple Python function.
To get it working all that is necessary is exporting a YEAR variable(for the year to checked), a LEADERBOARD_ID variable, which can be found in the leaderboard's page, the COOKIE from advent of code which can be obtained from the browser, and a SLACK_WEBHOOK_URL which is generated by creating an app for your Slack group.
After copy-pasting the code into AWS Lambda, I needed a way to trigger the function to run, this can be done with a rule in AWS Event Bridge that runs the following cron expression:
0/15 * ? DEC * *
This expression simply means to run the function every 15 minutes(starting from minute zero)every hour of every day during December, it's recommended by Advent of Code creator to not poll excessively so 15 minutes should be more than enough to get up to date data.
And sure enough, it works:
We didn't have as many people doing Advent of code as running, so this didn't exactly get as many people motivated, but it worked for me, I managed to get further into this years puzzles than ever before. You can check my Advent of Code puzzle solutions here.