I had been wanting to dip into the Twitter API for reasons that are definitely not related to building my own Twitter Bot Army and found myself inspired by a recent conversation about how adding in superfluous "world building" detail can sometimes have questionable results.
What did this add? Why was this ever allowed to be tweeted? Should this be the source of inspiration for my next personal project? I don't know the answer to the first two but the latter will received a resounding "sure, why not"!
I decided that this project would essentially aim to mimic the twitter of a creator that was constantly retconning or adding to their series' canon. For my Twitter project's source material I chose Avatar: The Last Airbender (ATLA) for two main reasons:
- ATLA is a perfect animated show (Editor's Note: Originally I had a whole passionate explanation here but really I think I can stop at those six words)
- There was a nice ATLA API - Thanks Paige Gorry!
Despite my red herring of an opening sentence to this blog - This personal project is not a twitter bot for my fictitious bot army but rather more akin to a random(ish) tweet generator. For the intention of this project (make wacky tweets that add/retcon plot points) I thought it would be fun to make a front end that the "audience" could interact with which is how I ended up with this.
The Tweet Generator front end is built with React and the Twitter handling back end is Ruby on Rails.
At a high level it works like this:
- Clicking the generate button will Math.rand(omly) call one of 19 possible tweet template functions
- Depending on which tweet template function is hit a fetch request will be made to the ATLA API for a random character name or two and/or state will be set with the corresponding template message
- A POST request with our state's message will be sent to our Ruby on Rails back end for handling
- Receiving the message on the back end will trigger a function that posts our message via the Twitter API
- The tweet is now live!
You can check out the code for both here: