Build a Lord of the Rings Lockdown Scavenger Hunt

February 08, 2021
Written by
Stuart Logan
Contributor
Opinions expressed by Twilio contributors are their own

Studio Scavenger Hunt SMS WhatsApp

I thought I'd missed the boat to get this post put together. My wife had her birthday last June, and (even then) we weren't expecting not being allowed to leave the house!

Now that many people are facing another lockdown, I thought it was a good time to build a birthday scavenger hunt powered by Twilio Studio and WhatsApp. So come along, we're going on an adventure!

Prerequisites

Before we can build our scavenger hunt, you'll need to sign up and register for a few things (if you haven't yet).

Build a Studio and WhatsApp Scavenger Hunt

The first thing you need to do is pick a theme. Earlier in the year, we'd had our favourite annual Lord of the Rings trilogy viewing – naturally this would set a great platform for bad jokes (and terrible puns).

Next, you need to buy presents. I can't really help you there, but in the spirit of a scavenger hunt I used a range of silly and small gifts to some "proper" presents culminating in a boxed set of the books.

Now you need to come up with the clues to find the hidden treasures. I wanted quotes from the stories to make up the bulk of my clues, but I didn't want to have to trawl the books to find them.

As Gandalf said, "All we have to decide is what to do with the time that is given us," – long story short, I didn't have time to find them myself. So thanks to my "Mellon" at The One API for supplying the quotes I needed to get this done.

I used some simple Python scripts to fetch quotes, and then filtered on the characters that I knew delivered some of the best. I haven't included these here, but please get in touch with me if you need a hand (my contact info is at the bottom).

Matching clues/quotes to hidden locations and presents was the tricky bit (but also the most fun). For example, "What about elevenses? Luncheon? Afternoon tea? Dinner? Supper? He knows about them, doesn't he?" - Pippin here led our intrepid Hobbit to the pantry to find coffee.

And with that human-powered work, you're now ready to add your Twilio integration.

Overview of a scavenger hunt built with Twilio

Finally, it's time to put everything into a Twilio powered solution!

The flow I wanted was to present a 'clue,' then have my Hobbit reply to the clue with the present she found at that location before moving on to the next one. While none of the clues were overly difficult, I felt it would be a good idea to offer a second hint.

To add some more fun, it would be great to get a random quote at any time. I also wanted to add a failure message to get our Hobbit back on track if they didn't find the right thing, and a success message to inspire our Hobbit to continue their journey.

<To load my flow, download my JSON file here. You can use this tutorial which shows how to import it to your account.>

Here is a snapshot of the first couple of clues (I ended up with 12 in total) to help you get going.

Scavenger hunt flow with Twilio Studio
Scavenger hunt flow with Twilio Studio

Walkthrough a scavenger hunt in Twilio Studio

It’s a bit tricky to see, so I’ll walk through what’s happening.

First, the Hobbit was a left a good old-fashioned paper clue to "speak friend" to the Whatsapp number. When the correct password of "mellon" is received, the scavenger hunt unlocks and the Hobbit is sent a message with an intro and the rules of play. That leads to Clue 1, which uses the “Send and Wait for Reply” widget.

Clue1

When the Hobbit replies, we need to determine what they’ve said and what to do next. I’ve given four possibilities using the “Split Based On…” widget.

Split Based On...

Next I have a "Send Message" widget. You can guess the clue, get it wrong, and be scolded by Gandalf. This loops back to Clue 1 and waits for the Hobbit to try again.

Clue 1 Wrong

After that I have another "Send Message" widget. If the Hobbit replies with “hint”, they get another clue.

Hint 1

In our Clue1Right "Send Message Widget", the clues led the Hobbit to the front door where a boxed set of helium balloons were waiting. When the Hobbit replies with “Balloons” they get a success message before moving on to the next clue.

Clue 1 Right

Now there’s one final option I haven’t covered yet – what if the Hobbit replies “random”?

In that case, I want to give them a random quote. Remember the text files I mentioned earlier that contained quotes from different characters? Well I took my hundred favourite quotes from them and created an array within a Twilio Function. Then I return one randomly chosen quote:

exports.handler = function (context, event, callback) {
const quotes = [
'Put it out you fools! Put it out! - Frodo',
'Stay this madness! - Gandalf',
'Send them to me! Come on! - Gimli',
…
'How long do you need? - Aragorn',
'Until at last I threw down my enemy......and smote his ruin upon the mountainside. - Gandalf',
'You said this fortress would never fall while your men defend it. They still defend it. They have died defending it. - Aragorn',
'Natha daged dhaer - Legolas',
];
const randomQuote = quotes[Math.floor(Math.random() * quotes.length)];
callback(null, { quote: randomQuote });
};

To access the Function from the Studio flow I use a "Run Function" Widget and select the Function above.

Random Quote Function

Then I use a “Send Message” widget to deliver the parsed quote returned from the function

Send Random Quote

All that’s left to do now is to use your Whatsapp Sandbox to connect to this Studio Flow. You can find instructions for setting up your sandbox here.

Once you have your sandbox running you'll need to set the "When a Message Comes in" configuration to be the webhook URL for your flow.

When a message comes in

You can get this by clicking on the Trigger widget in your flow and copying the Webhook URL.

Trigger Widget Configuration

This flow works equally well if you want to use SMS as well. You'll need to purchase a Twilio number and set the same configuration as above for "When a Message Comes in"

Building a scavenger hunt with Twilio Studio and Functions

Even though the world is in the midst of a pandemic, I don’t believe that means there isn’t any fun anymore. In the words of Aragorn, “A day may come when the courage of men fails… but it is not THIS day.”

I hope this brings some fun to you over the coming weeks, and I’d love to hear what themes you come up with – and the adventures you go on.

Stuart Logan is part of the Twilio Solutions Engineering team based in the UK. He comes from a traditional communications background and is amazed every day by what developers can do with Twilio. If you have any questions, please feel free to contact him on Twitter, LinkedIn, or Github.