TaCode Tuesdays: 8 Simple Ways You Can Use SMS And Voice (Series 2 of 4)

Posted by Pedram Mohammadi on July 12, 2016


8 Simple Ways You Can Use SMS And Voice (Series 2 of 4)

Welcome back to TaCode Tuesdays! This is the only place you can find snippets of code for use in your very own text/voice apps, along with a weekly dose of taco puns. 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 also a fan of open source. My goal is to 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—no coding ability required. This week I’m going to share 2 super simple, but incredibly useful, apps: one for business-call forwarding, and one for creating conference calls instantly.

Last week I kicked off our new series called “8 Simple Ways You Can Use SMS And Voice,” which is, of course, part of our “TaCode Tuesdays” feature. In case you missed it, check out last week’s post for an outline of our first 2 apps, and if you’d like to learn how to get started on Zang, take a look at our very first post.

This week I’m going to share the code for two apps: one for recording and transcribing phone calls, and another for creating a professional-sounding IVR (interactive voice response) menu.

And there’s more: Each bit of code will be presented in three different coding languages. If you know a particular language, then the code is there for you to use and expand upon. If you’re not familiar with any of these languages, then no problem - each example comes with a “Helper Library” so you’ll be able to make sense of the code that we’re providing.

Let’s Taco ’Bout the Apps

[#1] Record incoming calls and have them transcribed to text

The ability to record incoming calls and have them transcribed into easily readable and searchable text can be pretty valuable. For many businesses and individuals it’s a vital business function and serves as a way to capture important information and reference it at a later date.

With Zang, it’s easy to make this happen… just two simple steps, in fact. The first step involves crafting an inbound XML document (check out how to do that in this post) that receives the incoming phone call (via a Zang number) and records the conversation. The second step sets up a callback script to receive the resulting transcription, which is housed in another, separate document.

To show you an example of this, we've broken the process into two necessary pieces of code. You'll notice that part two, which is the callback script, simply receives the transcription and echoes it (outputs it). However, you could easily expand upon this example. For instance, the transcription could be emailed to participants on the call, stored in a searchable database or even saved via SMS.

Here’s how the app works. You’ll find the code (PHP, Python and Ruby) examples below:

  1. A customer places a call to your Zang number
  2. The call audio is recorded, then transcribed
PHP Python Ruby
'Receive Call' Script (Part 1)


// Save the following file as start_recording.php 
$inbound_xml = new TelApi_InboundXML(); 
// Use 'Say' element to acknowledge that the call is being recorded 
$inbound_xml->say('The following call is being recorded.'); 
// Use 'Record' element to record the call 
'action' => 'http://yourdomain.com/record-my-call-action-example',
'method' => 'POST',
'playBeep' => 'true',
'timeout' => '30',
'transcribe' => 'true',
// URL where the transcription text is sent for further processing
'transcribeCallback' => 'http://yourdomain.com/transcribe_call.php'
echo $inbound_xml;

# Save the following as start_recording.py 
from flask import Flask
from telapi import inboundxml 
app = Flask(__name__) 
def start_recording():
return "%s" % inboundxml.Response(
# Let user know that the following call is being recorded
'The following call is being recroded' % (caller_name)
action = 'http://yourdomain.com/record-my-call-action-example',
method = 'POST',
finishOnKey = '#',
transribe = 'true',
transcribeCallback = 'http://yourdomain.com/records/transcribe_call'

if __name__ == "__main__":
class RecordsController < ApplicationController def record_incoming_calls xml = Telapi::InboundXml.new do # Let user know that the following call is being recorded Say('The following call is being recorded.', :voice => 'man')
# In this example, this channel is being used for debugging HTTP requests
:action => 'http://yourdomain.com/record-my-call-action-example',
:method => 'POST',
:playBeep => 'true',
:timeout => '30',
:transcribe => 'true',
# This is the URL where the transcription is sent for further processing
:transcribeCallback => 'http://blog-post.herokuapp.com/records/transcribe_call',
:finishOnKey => '#')
respond_to do |format|
format.xml { render :xml => xml.response }
 Download PHP helper  Download Python helper  Download Ruby helper

PHP Python Ruby
'Callback' Script (Part 2)


// Save the following file as transcribe_call.php

// Assign the transcription text to a variable
$transcription = $_GET['TranscriptionText'];

// Output the transcription text
echo "This is the transcription text: {$transcription}";

# Save the following file as transcribe_call.py
from flask import Flask, flask
from telapi import inboundxml

app = Flask(__name__)

@app.route("/transcribe_call", methods=['GET', 'POST'])
def transcribe_call():
# Assign the transcription text to a variable
if request.method == 'POST':
transcription = request.form.get("TranscriptionText")
transcription = request.args.get("TranscriptionText")
return 'This is the transcription text: %s' % (transcription)
if __name__ == "__main__":

# Action URL where the transcription is sent
def transcribe_call 
render :nothing => true

# Assigning the transcription text to a parameter

transcription = params["TranscriptionText"] 

# Outputting the transcription text
puts = "The following is the text from the transcription."
puts transcription 

 Download PHP helper  Download Python helper  Download Ruby helper


Before I move on to the next app, here’s your taco tip for the week:

Don’t forget to heat up your tortillas (assuming you’re going the soft-shell route...hey, I’m not judging). Heating the tortillas makes them soft and pliable, so they won’t crack, just make sure you don’t use a microwave, otherwise they’ll get soggy and you’re going to have a bad time.

[#2] A professional sounding IVR (interactive voice response) menu

IVR, or interactive voice response, is, quite simply, an app that allows a computer to talk to a human...no seriously.  

In our example, when a customer calls your Zang number, this app will enable the caller to communicate with your IVR app with the simple press of a button.

Below is sample IVR that offers callers the option to be transferred to three different departments. If you want to take it a step further, you could set  up an "ivr-user-response" script on your server to do whatever you'd like for each extension, such as routing the calls to voicemail or to a specific individual's phone.

Here’s how it works - you’ll find the code (PHP, Python and Ruby) below:

  1. A customer calls into your Zang number
  2. A voice (via text-to-speech) presents the caller with menu options
  3. The caller chooses an item via a corresponding button press
PHP Python Ruby
IVR Menu Script
from flask import Flask
from somewhere import ivr
app = Flask(__name__)
def ivr_intro():
response = ivr.Gather(
Say('If you would like to reach sales, press 1.'),
Say('If you would like to reach accounting, press 2.'),
Say('If you would like to reach legal, press 3.'),
action = 'http://yourdomain.com/ivr-user-response.py',
method = 'GET',
numDigits = 1,
finishOnKey = '#',
timeout = '10'
return "%s" % response
if __name__ == '__main__':
 Download PHP helper  Download Python helper  Download Ruby helper


If you have any thoughts about the apps or just want to share a taco tip of your own, you can comment below. Be sure to check in again next week for the next installment of TaCode Tuesdays. If you want a reminder, sign up to get notifications of new blog posts. Something to look forward to for next week: I’ll be sharing code for multiple apps once again!

Topics: Communication Apps, Ideas, TaCode Tuesday, cPaaS