DEV Community

SavagePixie
SavagePixie

Posted on

Asteroid App: Phase Two

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.

Done So Far

I came across some issues using Sanctuary. It doesn't really support promises well. Looking through the issues, somebody suggested using Fluture, which looks interesting, but I don't really have a lot of time to put in it now, so it'll have to wait until a fluture project. There was also some suggestions about defining a specific type for promises, but I couldn't seem to get it to work. In the end, I thought it was more trouble than it was worth and decided to switch to Ramda instead.

I have written a module that parses the user's request and returns and object with the result: 'ok' and the start and end dates of the request if successful and simply result: 'notOk' otherwise. For now, it will only return the current day as both start and end dates if the request includes the words "asteroid" and "close". It isn't very customisable, yet, but it returns something.

Because Sanctuary didn't work well with promises and its Maybes were a bit weird, I decided to change the approach and do something more Elixir-like. The parser function will return a result of ok or notOk. Based on that, the next function will either send a request to NeoWs or to Cat Fact API (did you know that a healthy cat's body temperature is between 38 and 39ºC?). Then I created an object with ok and notOk keys to simulate some sort of pattern matching.

Finally, I put together a README based on Twilio's example. I'm not sure if it follows the guideline of having clear setup instructions yet, but hey, it's a beginning.

The code is now public on my github repository.

Next Steps

The basic structure of the app is almost done. For the next phase, I plan on accomplishing the following:

  • Plug the node API to Twilio, so that when a user sends a message to the WhatsApp number it'll actually get processed by asteroid app.

  • Tidy up the code a bit. Right now it's quite messy.

After that is done, I'll want to look into making the requests for data more customisable. At the very least, I want to make it possible to ask for one specific date. But I would also like to allow a date range and expressions like "last week" or "in two weeks". We'll see how I manage.

Top comments (0)