DEV Community

SavagePixie
SavagePixie

Posted on

Asteroid App: Phase One

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.

Top comments (4)

Collapse
 
michaeltharrington profile image
Michael Tharrington

When you write:

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 ?"

I'm assuming there's meant to be a cat fact after "but did you know that ___" ? You telling me that you deprived us of a valuable cat fact in the middle of this post?! πŸ™€

Collapse
 
savagepixie profile image
SavagePixie

I beg the community's pardon for that! I actually typed <random cat fact> between "that" and "?", but the html sanitiser must have deleted it, thinking it was a malicious tag. But you're absolutely right. It is a wrong that must be righted.

Collapse
 
lizziepika profile image
Lizzie Siegle

Love the Cat Facts API!

Collapse
 
savagepixie profile image
SavagePixie

Thanks! I thought it might be a fun whimsical addition.