Asteroid App: Project Submission
SavagePixie
Posted on April 17, 2020
What I built
For the Twilio Hackathon, I have built an automated WhatsApp account to which you can ask information about the closest asteroid to Earth at a particular date.
When a user sends a WhatsApp message, the API endpoint will try and parse it. If it is asking about asteroid information, it'll check for dates. If there are no dates present, it'll assume today. Otherwise, it'll parse the dates and use them as start and end of the period for which to issue the request to NASA's NeoWs API.
If the API is unable to parse the message, it will issue a request to Cat Facts API and respond with an apology and a cat fact.
If the parsing process is successful, it'll issue a request to NeoWs, glean the data returned and send it in a human-readable form.
Category Submission: Interesting Integrations
Demo
Here are some images of responses to different messages:
A simple request asking about the closest asteroid to Earth. Since there is no date, today is assumed:
Link to Code
Asteroid App's code, together with its README and set up instructions is available under a MIT license in this git repository.
How I built it (what's the stack? did I run into issues or discover something new along the way?)
I originally intended to build this project with Elixir. But it proved to be more than I could chew. So I decided to go with JavaScript and build it on Node.
You can read about some of the issues and notes of the process in previous posts in this series. There I documented part of the journey and most of the issues I ran into.
Something new that I discovered along the way was the beauty of Either
. Creating the request parser proved to be a bit of a challenge. Especially when I wanted to allow for custom date requests. In the beginning, I had simply coded it with a bunch of if
s. But it was a mess.
So I remembered Professor Frisby Introduces Composable Functional JavaScript, which I had been watching last week (if you don't know what an either
is, by the way, I strongly recommend watching the first five videos. The explanation is simply brilliant). So I decided to try a different approach using either
s.
The result was simply beautiful. Now, instead of a bunch of nested if
s, the parser is this simple pipeline of transformations:
checkKeyWords(str.toLowerCase())
.map(matchDate)
.chain(parseDate)
.map(buildObject)
.fold(
() => ({ result: 'notOk' }),
x => ({
result: 'ok',
payload: x,
})
)
Additional Resources/Info
I guess I'll use this section to say that building this project was a lot of fun. I got to learn how to integrate a Twilio service in my API and I experimented with functional libraries and types. The result is a pretty simple app, but I'm quite happy with the result. It does what I set out to accomplish.
Posted on April 17, 2020
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
April 16, 2020