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

Posted by Pedram Mohammadi on July 26, 2016

tacode-tues-blog-wk2.jpg

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.Last week I continued 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 2 different 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 close it out by focusing on ‘voice.’ I’ll share the code for two apps: one for customized greetings, and another for screening incoming calls.

And, once again, 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.

Oh, and before I get to the apps—a quick note! We’ll be hosting our first Zang Meetup on August 3rd in Santa Clara, CA. If you’d like a chance to meet with one of our developers and walk through a bunch of SMS + voice apps, then register here for the free event.

Let’s Taco ’Bout the Apps

[#1] Customized Caller ID Greetings To Callers

There’s something about someone knowing my name before we’ve ever met...a little creepy, but mostly novel and it makes you feel sorta important! This app is all about providing a simple personalized greeting whenever someone calls into your Zang number. This can easily be implemented by obtaining the 'CallerName' attribute in the request parameters. Just copy the code below, add in a few things unique to your instance, and you’ll have a fully functional app.

First, here’s how it works:

  1. A customer places a call to your Zang number
  2. The number is matched to their name, which is on file
  3. They are presented with a personalized greeting
PHP Python Ruby
require_once('library/TelApi/InboundXML.php');
// Zang inbound XML document
$inbound_xml = new TelApi_InboundXML();
// Assign the CallerName request param to the caller_name variable
$caller_name = $_GET['CallerName'];
$inbound_xml->say(
  // Greet the incoming caller with their name
  "Hello {$caller_name}! Thanks for calling in!", array('voice' => 'man')
);

echo $inbound_xml;

from flask import Flask
from telapi import inboundxml
 
app = Flask(__name__)
 
@app.route('/caller/intro')
def ivr_intro():
# Assign the CallerName request param to the caller_name variable
caller_name = request.args.get("CallerName")
 
return '%s' % inboundxml.Response(
inboundxml.Say(
# Greet the incoming caller with their name
'Hello %s! Thanks for calling in!' % (caller_name)
))
 
if __name__ == '__main__':
app.run(debug=True)
def greeting
 
# Assign the CallerName request param to the caller_name
caller_name = params["CallerName"]
 
# Generate XML response
xml = Telapi::InboundXml.new do
# Greet the incoming caller with their name
Say("Hello #{caller_name}!", :voice => "man")
Say("Thanks for calling in!", :voice => "man")
end
 
respond_to do |format|
format.xml { render :xml => xml.response }
end
 
end
 
 Download PHP helper  Download Python helper  Download Ruby helper

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

Fresh salsa is key to a great taco, so here are some simple salsas that you can try the next time you make tacos:

Salsa verde - Cooked tomatillos and chilies

Salsa taquera - Tomatillos and chipotle chilies

Salsa roja - Cooked tomatoes, onion, garlic, chilies, and fresh cilantro

Salsa negra - Dried chilies, oil, and garlic

And yes, I never measure ingredients for my salsas… it makes it more interesting.


Now, time for app idea #2.


[#2] Screening Incoming Calls

Whether you’re an individual or working in an organization, telemarketers are the reason call screening exists. They’re the reason you ignore every call with no caller ID and the reason why, personally, I have my ringtone for calls on silent. The only problem is what happens when one of the next ‘suspect’ calls you receive is from a client? Ideally you’d want to answer it. With Zang, building call screening software can be done very easily. This, of course, is just one simple example, but could be expanded upon to create a more comprehensive system.

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

  1. You compile a list of ‘banned numbers’ (from online lists and your past experiences)
  2. Whenever a customer calls in, their number is compared to the list
  3. If the number matches a ‘banned number,’ the call is rejected, otherwise it is accepted

PHP Python Ruby
require_once('library/TelApi/InboundXML.php');
$inbound_xml = new TelApi_InboundXML();
// A banned number assigned to a variable
$banned_number = "+18005551234";
// Assign the CallerName request param to the caller_name
$call_from = $_GET['From'];
//Assign the CallerName request variable to caller_name
$caller_name = $_GET['CallerName'];
// If the number comes from a banned number, then reject it
if($call_from == $banned_number)
{
  $inbound_xml->reject(array( 'reason' => 'rejected' ));
}
// If number is not banned, answer call and greet caller
else
{
  $inbound_xml->say(
  'Hello $caller_name!
  Thanks for calling in!', array('voice' => 'man'));
}
echo $inbound_xml;
from flask import Flask, request
from telapi import inboundxml
 
@app.route('/call/intro')
def call_intro():
# A banned number assigned to a variable
banned_number = "+18005551234"
 
# Assign the number of the incoming call to a variable
call_from = request.args.get("From")
 
# Assign the name registered to the incoming caller to a variable
caller_name = request.args.get("CallerName")
 
# If the number comes from a banned number, then reject it
if call_from = banned_number:
return '%s' % inboundxml.Response(
inboundxml.Reject(reason = 'rejected')
)
else:
# If the number is not banned, answer the call and greet the caller
return '%s' % inboundxml.Response(
inboundxml.Say(
# Greet the incoming caller with their name
'Hello %s, Thanks for calling in!' % (caller_name)
))
def screening
 
# A banned number assigned to a variable
banned_number = "+18005551234"
# Assign the number of the incoming call to a variable
call_from = params["From"]
# Assign the name registered to the incoming caller to a variable
caller_name = params["CallerName"]
 
# If the number comes from a banned number, then reject it
if call_from == banned_number
xml = Telapi::InboundXml.new do
Reject(:reason => "rejected")
end
else
# If the number is not banned, answer and greet the caller
xml = Telapi::InboundXml.new do
Say("Hello #{caller_name}. Thanks for calling in.")
end
end
# Ruby used to generate an XML response
respond_to do |format|
format.xml { render :xml => xml.response }
end
end
 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

IMAGINE IT. BUILD IT.

Communicate better. 

Cloud communication technology that transforms your conversations — and your business.

 

Subscribe to Email Updates