TaCode Tuesdays: Free Zang Code to Kickstart your SMS or Voice App

TaCode Tuesdays: Free Zang Code to Kickstart your SMS or Voice App

Hello world!

Welcome to the first ever post of ‘TaCode Tuesdays.’ This will be a weekly blog where, you guessed it… every Tuesday, I’ll walk through examples of simple code that you can use in your very own text and voice apps. I’m a developer here at Zang and not only am I a big fan of tacos (if that wasn’t already apparent), I’m a fan of open-source, and regardless of your coding ability, my goal is share a new app idea each week that you’re free to use ‘as is’ or modify and use as the basis for your next app.

This week, I want to talk about SMS (short message service) or text messaging – the most widely used app on smartphones in the United States. It’s a pretty common app that almost any company can use to give their customers a ‘voice’ – take OwnerListens, for example, a company that enables customers to privately text (via ‘masked’ numbers) business owners with their praise or complaints.

Let’s Get Started (signup for a free account on zang.io) 

Time to build a simple SMS app with a ‘voice’ twist. First, here’s how it works:

This app could eventually enable a customer to check the status of their order and then receive a text with a link to the most up-to-date info on that item. Or the caller could be able to navigate the call using voice or dialing commands, with the end result that they receive an SMS with perhaps, a link to a support ticket. The possibilities are pretty wild and if you want to get info on those kind of examples, check out these docs – but, for now, let’s get back to our example.

1) To begin, either signup (free) or login. You will need to fill in some basic contact information, and create a username and password.

2) After you’ve signed up and logged in, you can purchase a phone number with the free credits in your account. This phone number is the number that your customers will be calling.

3) Now, click on ‘Create Document’ – this is the document that will house the first part of your application.

4) Next, it’s time to code or just copy the code…I’m not judging!

The Code n’ Stuff

Once you’ve created the first document, rename it by going to ‘document settings’ – let’s go with ‘Incoming Call Handler’, then save. Now, create a second, separate doc to handle the outgoing SMS flow (the second part of this app) let’s go with ‘Outgoing SMS Script.’ Make note of the Public URL for this second doc or ‘script,’ (you’ll find it just above the editor) since you’ll need to include it in your ‘Incoming Call Handler’ script.

Here’s the code for handling the incoming call – the bit you’ll be adding to your first doc, the one we called ‘Incoming Call Handler‘:

<Gather action=’ENTER YOUR PUBLIC URL FOR THE ‘OUTGOING SMS SCRIPT’ HERE’ method=’GET’ numDigits=’1′>
<Say voice=’man’>Welcome to your first Zang app!</Say>

Note that the ‘Say’ function is used for text-to-speech. You can enter any text to customize your app. You’ll be coming back to this code soon, to add in the Public URL of your second document ‘Outoging SMS Script.’

Next, here’s the code to add to your second doc, the one we called ‘Outgoing SMS Script’:

<Say voice=”woman”>
The application is sending you an SMS!
<Sms from=”{{To}}” to=”{{From}}”>
Good job! Your first Zang app is now working!
<Say voice=”woman”>
We hope to see your application on the Zang app store soon.
<Say voice=”woman”>Good bye</Say>

Note that the variables ‘To’ and ‘From’ are predefined (refer to the API Docs for more info) and you can change the speech to whatever you’d like. Also, now’s a good time to add the Public URL of the ‘Outgoing SMS Script’ to your first doc’s code (the one we named ‘Incoming Call Handler’).

5) All that’s left is to navigate to ‘Numbers’, and select ‘Manage Numbers’.

Here you’ll see the number you purchased earlier, click on that and paste the Public URL of ‘Incoming Call Handler’ app (found back under the ‘Incoming Call Handler’ document) – save and you’re done.

Now, the outgoing SMS portion of the app will work by default, since we didn’t define the SMS tag in our code (if you have no clue what I’m saying, don’t worry – neither do I).

And that’s it! Now you have a working app on Zang – anyone can call your Zang number, listen to some info, and then recieve a text covering…well, whatever.

If you have any thoughts about the app or maybe you’re just a burrito person (totally fine with me, although we know where my allegiances lie), you can comment below. Be sure to check in again next week for TaCode Tuesday, if you want a reminder, sign up to get notifications of when we post new blogs. All I can say is that I’ll be sharing code for multiple apps, so look forward to that.