Facebook Badminton Bot
2022-10-02For the last 3 years, I have been playing badminton on almost a weekly basis. It's been a great way to get some cardio in, and socialise with friends at the same time.
When it came to organising a court to play on, each member of the group will usually take turns to organise the booking, checking to see who can make it to the session, and getting in contact with the court owners.
When this responsbility was passed to me, like any good (lazy) developer, I had an idea to automate this job as much as possible. I shared this idea with a friend who was eager to contribute. Alas, the work had begun.
Part 1: Python
The initial attempt was met with disappointment. The python package fbchat, looked to be the most promising package that we could use to create our bot. Upon further testing, it appears that the Facebook have 'plugged the hole' for 3rd party automation on their platform, with almost all of the package functionality no longer working.
Furthermore, it appears that the original developer of the package, is no longer supporting the project. We had to settle on using Selenium.
Selenium was set up to open a browser, log into facebook.com using a 'service account' (we had created a facebook user which served as our service account), and create a poll in the Badminton group chat, asking who could make it to that weeks session.
Happy with the initial work, we now focused on having the bot run on AWS.
Part 2: AWS
AWS Network Diagram (Route tables not pictured)EDIT 2023/02/04: NAT Gateway was converted to a NAT Instance, GW is way too much $$$$
The flow starts with the scheduled EventBridge rule (set to once a week) triggering the lambda function. The lambda retrieves the service account credentials from SSM Parameter Store, and logs into facebook.com to create the poll, piggy-backing off the NAT Gateway and Internet Gateway.
A challenge faced was getting lambda to run Selenium, as the base lambda python container image has no idea what Selenium is. I stumbled upon this project by Diego Parrilla, which creates a Headless Chrome client which is used as an AWS Lambda Layer. Thanks to Diego, this problem was no more!
Conclusion
Overall, this project was quite fun to work on. While not completely automating the task of managing the badminton booking, it certainly does a portion of the heavy lifting.
In the future, we plan to integrate AWS Simple Notification Service to send SMS messages to the players, informing them about the status of that week's booking. We also want to create a data store (either DynamoDB or RDS) to allow more advanced functionality with the bot.
Check out the code here on GitHub.
Please feel free to get in touch via any of the contact methods above if you have any questions or suggestions regarding the bot.