Email, video and other forms of communication are important, but nothing is as ubiquitous as voice devices. Create voice menus that enable a caller to navigate your directory and find information by simply calling into your main number. The ability to recognize DTMF digits means that you can enable simple, self service for customers. Zang provides a smooth and inexpensive way to do just that.
Here's how we did it.
We created a free trial account with Zang.io, but then we went ahead and spent the $10 for credit in order to buy a phone number to play with. The location of the phone number isn't important, but we were able to score a local virtual number.
The last step before we leave the Zang site is to copy the account SID and token.
Now that we picked up a phone number, account SID, and token, we can enter it in a DragToCode connector.
A direct route is https://www.dragtocode.com/connectors_view?action=Voice
We created a simple script to make a decision based on a digit. Here's the script:
The blocks lay out like this:
- start the call
- prepare to collect a digit anytime during the playing of announce.mp3 (or up to 15 seconds after) and place into a variable called "item"
- if the called person enters a 1, play a sweet sounding song
- otherwise, play the start of Beethoven's 5th symphony
- end the call
A caveat for making outbound calls is in formatting the phone number: format it for an international call. In the United States, this means preface your number with "+1" (like "+14152341234") and in the UK "+44" (like "+441143520352").
In addition to making calls, you can receive them too.
The only difference between them is that you don't start by making a call. That's it!
Configuring Zang For Incoming Calls
When we purchased the phone number, we skipped the part about configuring it for incoming. There are two ways to do that.
https://www.dragtocode.com/script/voice?token=[YOUR_TOKEN_HERE]Into Zang's interface:
Be sure to click save when you're done.
Breathlessly panic! It says voice in the URL! The reason why it says voice is that the voice and SMS interfaces are identical, so we re-use the URL.
Wait. How does this even work?
When Zang receives a call, it calls the URL you set with some extra information like the calling phone ("From" variable), caller ID name ("CallerName"), and the identification number ("CallSid"). DragToCode receives this like a input parameters from any internet form, and makes them available to the script. The response to this information is formatted as XML (Voice XML) back to Zang.
Multiple Calls In A Script
Performing multiple voice calls in a single script can be tricky. There are only 2 blocks that allow
script re-entrance: dial and gather. On an outbound call, we perform the blocks up to the dial block and
then wait for Zang to return the operation to us. Zang makes a request to restart the script at the next block.
A gather block is similar, waiting for Zang to make the restart request after the voice call has entered digits,
returning the digits entered with the rest of the script information.
On an inbound call, we expect the request to have come from Zang in the first place, providing the XML commands to perform next. When a gather block is encountered, we stop and wait for the restart. At the restart, we serve everything we have, until we encounter another dial or gather block.
Having two independent calls at the same time is not currently supported.
Why doesn't the debugger work well with calls?
A phone call is all about timing, while debugging is all about taking your time to analyze the results. These two ideas don't play well together. To debug your script, we recommend skipping over making the outbound call, setting up your variables on the right, clicking on the block after the call starts, and stepping through your script from there. When the rest of the script works, try an actual call.
Where's the rest of my log?
Because a voice call is re-entrant, we treat it as a separate request into the system. That means you will see a log execution for the first part of your script (up to the dial), another for the return from dialing, another for digit collection, and so on. At this point, we don't have a good method to tie the disparate requests and replies together, but we're working on it!
Now you can drag and drop to create voice menus and complex self-service avenues for your customers.
Give it a try and tell us about the great things you build!