November 10, 2019

Handling SMS replies with Textbelt

Since 2012, Textbelt has been a self-described "outgoing SMS API".  I'm excited to announce that we've added the ability to receive inbound SMS for free.

In the interest of keeping the API as simple as possible, all we've done is add a single new parameter to your SMS POST request, replyWebhookUrl:

{
  "phone": "(408) 555-5555",
  "message": "Hello world",
  "key": "abc123",
  "replyWebhookUrl": "http://my-webhook-url.com/xyz",
}

When you include this parameter, any response to the SMS will be forwarded to the specified webhook as a POST request with the following body:

{
  "fromNumber": "+1408555555",
  "text": "Here is my reply"
}

This is a quick and easy way.

Demo

Let's try it for ourselves.  We'll be using webhook.site, a service that is very handy for testing out webhooks.  By loading the site, we are assigned a temporary webhook URL and all requests will be printed on the screen (you can also do this with a command-line based service such as ngrok).

In my case, my temporary webhook is http://webhook.site/6971657b-c131-46da-a262-b2ea4f950edb

I'll issue the following curl command from my terminal:

curl -X POST https://textbelt.com/text \
       --data-urlencode phone='4085555555' \
       --data-urlencode message='Is there anybody out there?' \
       -d replyWebhookUrl='http://webhook.site/6971657b-c131-46da-a262-b2ea4f950edb ' \
       -d key=my-textbelt-key-123

I get the message on my phone:

And send my reply:

My response shows up in the webhook console!

And that's it.  You can use this same principle to write your own web app that can follow up on a response or handle it in any way that you like.

When you are developing your own web app and want to test it, I recommend a tool like ngrok to route webhooks directly to your locally running app.

Good luck and have fun!