As we came to the last week of Eliot's MongoDB World Weekly Challenge, we wanted to challenge your creativity by asking you to create a digital Rube Goldberg machine that used Stitch and as many APIs and services as possible. We had some great entries and the one that tickled us the most also had some of the most intricate code we saw in the entries, it stood out as a winner.
The creator of the winning entry, Jonathan Dharmaraj, told us how the idea behind the challenge was new to him. "I had never heard of the term “Rube Goldberg Machine” before the challenge. It was a lot of fun watching different videos on different machines and how extravagant they can get!!".
From the outside, Jonathan's creation seems simple. Select your astrological sign in Facebook and after a pause the ideal, universe selected GIF is returned to you. As the diagram shows, it's far from simple inside.
The process starts with Facebook Messenger and the user selecting an astronomical sign. When that's done, a Stitch webhook is called and the incoming message is processed. If it's an astrological sign, then the message is inserted into a MongoDB Atlas collection and typing dots are displayed to the user.
Now here's the part we like. When that message is written into the database, it's accompanied by a field called nextTrigger which names the next trigger to fire. For the first step, that's astroFn. And there's an astroFn trigger looking out for that nextTrigger setting. When it sees a document being inserted or updated it runs the astroFn function.
It's this simple mechanism what sees actions ripple through multiple triggers and functions. Each step sees information added to the message document in the database and then passed onto the next step.
astroFn function calls the astrological API, gets a lucky number and adds that to the document sending it on to the
offsetFn trigger and function. There, two API's are used, one to see if Mercury is in retrograde and select a dice, another to throw the selected dice. The offset and the next function (
limitFn) are written to the document and it moves on through the triggers.
limitFN, the lucky number and values from two APIs - the water temperature in Woods Hall via NOAA and the air temperature from the Insight Lander on Mars - and does a little calculation. That result becomes a limit value and we're nearly there. The offset, limit, lucky number and sign are now passed on to a GiphyAPI function. Here all the assembled data is put into a call to the Giphy API to select a GIF, the URL of which is added to the document, written and all pushed on to the
sendToFB trigger and function.
sendToFB, the message with the GIF and lucky number are returned to the user. And so the circle is complete and in a delightfully contrived way, just as we had hoped to see. You can find the code at https://github.com/jjdharmaraj/gif-text-buddy learn from it or you want to create your own version.
We're pleased to see Jonathan take the ultimate prize of Eliot's MongoDB World Weekly Challenge. As Jonathan told us, "It was fun!".