Ever since starting work at Mercedes-Benz R&D NA, my Python proficiency has skyrocketed. I hope to someday make this bot again in Python using Google Cloud Functions and Terraform or cloud-managed Kubernetes (since I know that now). It will be so much cleaner! I'll be especially motivated if I get a job in SF. ;)
Oh shoot.
You, yelling into your phone as you sprint from your Prius:
Do I need to run to catch the Bayfair train to Powell?
Bartbot:
4 min until the next train from Bayfair to Powell. Smell the roses - but not for too long. ๐น
You, taking a moment to catch your breath:
๐
"Should I run to catch the train?" This was the main question that I wanted to answer with Bartbot.
I have always wanted to make some sort of quick access to the BART API but didn't know where to start developing. Then one day, as I looked for open-source projects to contribute to, I found some examples of Facebook Messenger chatbots! It was then that I became super inspired to create my own chatbot. Thus, Bartbot was born.
Being able to message (or even speak) to BART about the next trains seemed like such a convenient idea. So far, I've learned an incredible amount, since this project covers so much!
Things Bartbot taught me:
- Writing libraries
- Semantic Versioning
- Readme-Driven Development
- Logging & debugging
- Package logistics
- RESTful APIs
- All the protocols
- How to design them and how to call them
- Key/secret management
- Object Oriented Programming
- Not the theoretical stuff they teach you in school
- Inheritance is amazing
- Functional Programming
- Concurrency comes by design
- It isn't always useful to run concurrently
- Serverless programming
- Natural language processing
- NoSQL databases
I went through plenty of design iterations for how to structure the code, but I have settled with the stack below:
- Facebook Messenger
- Periodic GET requests for challenge (verify my webhook is online)
- POST requests for messages and postback events
- Amazon Web Services
- botocore
- Lambda
- Hosts my Serverless Flask application
- API Gateway
- Exposes a RESTful API endpoint for my Lambda function
- S3
- Hosts user data, sessions, and caches
- Systems Manager/Parameter Store
- Houses my secrets like API keys and the lot
- Wit.ai
- Natural language processing for requests
- Python 3.6
- Serverless Framework
- Handles AWS configurations to set up Lambda and API Gateway
- Originally, I went with Zappa. It seemed pretty well done but ultimately didn't work for Bartbot.
- Flask
- Requests
- Makes HTTP requests easy-peasy
- unittest
- Testing testing testing! Helps with unit testing and some integration testing
- virtualenv
- Configures development environment
- I customized some of the BASH scripts to include adding environment variables
- Have a look at the Python requirements
- Serverless Framework
- BART API
- API endpoint for BART information
- Future Features
- Pybart (In Development)
- A Python library for accessing the BART API with caching
- Dark Sky (Future Support)
- API endpoint for weather information at specific stations
- Transfer and arrival notifications
- I've thought hard about how to implement these with AWS Lambda constraings (and even AWS Step Functions), but haven't come to any solid ideas yet, since neither can take the ~2hr longest trip (Antioch to Dublin Pleasanton). Please shoot me a message if you happen to have a work-around!
- Increased use of concurrency (even though I'm working in Python)
- I can easily see implementing futures
- Pybart (In Development)
I will detail this section more at v1.0 release.
Ayy check it.
I'm not sure if I'll be supporting contributors before v1.0, but watch the repo and see the contributing guideline if you're interested! It'll be soon.
Also, check out the functions-to-implement checklist.
This is an awesome get-started article!
This Serverless tutorial got my app up and running.
GNU GLPv3 Copyright 2018, Anthony Ho.
Doot doot, my dudes.