Asteroid App: Phase One
SavagePixie
Posted on April 9, 2020
For the Twilio Hackathon, I'm doing an automated WhatsApp account to which you can ask information about the closest asteroid to Earth at a particular date.
What I have done so far
I have decided to use Sanctuary, because some functional types (particularly Maybe) are going to be useful. It also provides a layer to declare types using Haskell notation, which is really cool. I'm not sure I'll use that part, though, as I'm not used to it. If I've got enough time, it might be cool to dive into it.
I have finished the functionality that fetches data from NeoWs. The most challenging part was delving through the vast amount of data that the API provides to take only what I'm interested on. I also had to create my own version of take
, because, for some reason, Sanctuary has decided to make it return a Maybe with Nothing if you ask for more items that the list's length. So, following the way Elixir does it, I created one that returns the whole list if you ask for more elements than it has.
I have also created a module that calls Cat Facts API. If the program can't parse a user's request, instead of simply failing, it'll respond with "Sorry, I didn't understand your request, but did you know that cats' eyes shine in the dark because of the tapetum, a reflective layer in the eye, which acts like a mirror?" (or some other random cat fact).
Lastly, I have created a Twilio account and got WhatsApp running. I'm going to leave actually connecting it to my Node's endpoint until that's finished, but I can now send and receive WhatsApp messages.
Next Steps
For the next phase, I plan on doing the following:
- Making a module to parse the user's request, i.e., reading the message that the user sends and extracting the data to make a request to NeoWs.
- Writing a function that returns a Maybe. If the parsing is successful, it'll return the data for the request to NeoWs and the next function will do the request. If it isn't, it'll return Nothing and the next function will do a request to Cat Facts.
- Put together a first draught of a readme.
It's not a whole lot, but the project is starting to take shape. Plus, investigating this Sanctuary library is proving to be quite fun.
Posted on April 9, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
April 16, 2020