Break Awkward Silences With Terrible Festive Jokes Via SMS

Break Awkward Silences with Terrible Festive Jokes via SMS

Published December 18, 2018 by Martyn Davies

In this tutorial I’ll show you how to build your own awkward silence breaker, in the form of an SMS app that will reply to you with terrible festive jokes and one-liners that you can throw out to the table, quickly breaking the tension.

Getting large groups of family members together at any time of year can sometimes get a little awkward. Like when Uncle Bill has been mixing his drinks, and he ultimately says something about cousin Roberta that leaves everyone uncomfortably munching on parsnips.

Awkward. Fire up your code editor and let’s get started.

Try Before You Build

My version of this app is live, so you can message it right now and see the results before we dig into the code.


Send an SMS containing the word ‘awkward’ to +44 7520619627 if you’re in the UK, or +1 201 844 9627 if you’re in the US and bust out laughing at the genius lines you’ll be sent in return… maybe.


(The keen of eye will have already spotted that the last 4 digits of each of those numbers spell out X-M-A-S on a telephone keypad.)

One line didn’t break the grim, grim silence? Okay, SMS the word ‘more’ in reply and get another line that might help.

Building The App

The app we’re going to build uses Node.js, the Koa framework (which is just a more modern implementation of Express), and the Nexmo Messages API.

The code is available in a repository on the Nexmo Community GitHub account, and also in remixable form on Glitch.

Prerequisites

  • The Nexmo Command Line Interface
  • A Nexmo account
  • A fresh SMS capable number
  • Node.js version 8 or above
  • A selection of terrible jokes and one-liners
  • An awkward situation

Buy A Number

Using the Nexmo CLI, buy a new number for the app:

Clone The Repository

In any directory clone a copy of the code from our nexmo-community repository on GitHub:

Then change to the directory to access the code:

Open this festive package of wonder up in your editor, and we’ll get on with the configuration.

Start It Up

To configure this app, it needs to be reachable from the outside world. Use Ngrok to expose port 3000 and note down the https URL you are given:

If you haven’t used Ngrok before follow the guide in this blog post to get up and running.

Configuration

The first piece to configure is the .env.sample file. Start by renaming it to .env.

Add all the following pieces of information:

Next up is the application specific detail. Set that up using the CLI:

This command will set up a new Messages & Dispatch application on your account. It outputs the Application ID to the screen and will also write a file called private.key into the directory you’re currently in. Both are needed for the next step of the config:

Finally, add in your new SMS capable number:

With all those fields filled out you can save your .env and close it.

Linking Numbers & Setting Callbacks

The app you have cloned has two endpoints in it:

  • /inbound receives new SMS messages
  • /status is a a required URL for any Messages & Dispatch application, it receives read receipts and other information about the messages you send

So that the app can receive SMS messages, your number needs to know about your app. You do this by providing it with a callback URL:

Once that is set, connect your application to the number as well:

That’s it. Set up complete!

Fire Up The Festive Cheer

Nexmo now knows where everything is going and how to route new messages over to your application. There’s only one thing left to do:

Once the server is running, ensure that your Ngrok connection is still up and running on the same URL you used in the callbacks and then SMS the word ‘awkward’ to your new number.

Numbers in action

Where Next?

Your next steps are to deploy this app to a server. Heroku is an excellent choice for this and the app won’t require any code changes to work there.

Remember, when you deploy the app elsewhere you will need to update the callbacks for the SMS number, and both the URLs for your Messages & Dispatch application.

The CLI commands you need to do this are:

Then you’re good to go.

Do You Want It To Be Even Easier?

If you’re looking for an even quicker route to playing with the code for this application, you can remix it on Glitch by clicking the button below:



remix button

Leave a Reply

Your email address will not be published.