The App that Texts You Back

Lauren Petersen
3 min readAug 31, 2017

The conversation isn’t seamless, but I created an app that will respond to your text messages.

The app’s functionality is simple: when you text this phone number, the app will reply with a dynamic response. Unfortunately, the app has a difficult time maintaining a steady thread of conversation, and it replies a little too quickly to be human… but it still works, and it could be useful in a few situations.

How it was made

The phone number was easy to acquire through Twilio, which also took care of most of the grunt work behind SMS sending and receiving. This Twilio documentation provided an easy-to-use code that dispatches a text in response to a received SMS. So, in order for the code to function, all I needed to do was two things: I needed the app to recognize when it receives a text, and I needed to write a method that would determine what message should be included in the response to the user.

In order for my app to know when it receives a text, it needed to be initiated by a webhook, or a user-created HTTP callback. However, when I ran my app on localhost, there was no way that my app could respond to webhooks — it needed to be connected to the web, where it would be possible for an external source to initiate an HTTP request.

Enter ngrok. Ngrok is a free program that creates a secure tunnel to localhost. In other words, it creates a secure public URL that links to a local webserver. Through ngrok, I was able to create a public URL to my app while it ran on localhost, which therefore enabled the app to receive the necessary HTTP request from an incoming text message. I just had to set up the ngrok forwarding address within the settings of my Twilio account:

ngrok creating a public url for my app (which was running on localhost port 4567)
Updating my Twilio account settings (the ‘receive_sms’ is what I named the POST request within my app)

So receiving a message — and being able to send one back — was taken care of. The last thing I needed to do was create a method that would write an appropriate message in response to the content received. Ultimately, I was able to develop responses through Cleverbot API, the beloved internet chatbot that mostly speaks in non sequiturs but people seem to enjoy anyways. The API was free, and it was easy to hook up with my app: I could just give Cleverbot the content from the received text message, and it would spit back a (somewhat relevant) response. I then included Cleverbot’s response in the dispatched SMS response.

How it could be used

Well, Cleverbot doesn’t make a great conversation partner — it changes the subject far too frequently. However, this app could be used in a couple situations. for one, someone could use this app to appear distracted and evade an uncomfortable person or situation. Also, of course, it could be used as a (rather mean) joke…

--

--