Have code. Will travel.

Integrate Banana Phone scripts

We now come to the conclusion of our Banana Phone build. The scripts are written in Python and will be stored in some new directories we will create within the 'banana' home directory. We'll then add the needed media files for Asterisk to play when a call is received, and finish out with setting up the database for remembering validated caller IDs and some test calls to make sure everything works.

Banana Phone directory structure

We have a few Python scripts to copy into our 'banana' user's home directory, so we will make a few more to better organize things. Let's move into the 'banana' user's home directory and create some more.

Login to your Asterisk server as 'banana', move into the'banana_phone' directory in 'banana' user's home directory and create the following:

importargparsefromCID_helpersimport*
parser = argparse.ArgumentParser()
parser.add_argument("cid", help="incoming caller id")
args = parser.parse_args()
####################################### --- check all the CID helpers ---## if they all are true, the CID is good for saving## input: caller ID string from Asterisk## output: text string "YES" or "NO"## --- if this output look weird, it's because it totally is. In order to # --- "massage" Asterisk into being scripted from the dialplan, we print out strings# --- and use the Shell() application in the dialplan to extract the echoed string # --- to return the value into a dialplan variable.# ---# --- This is way stable and I opted for this because shitty AGI locks up # #####################################
incoming_cid = args.cid
visible_number = cid_visible(incoming_cid)
good_length = valid_length(incoming_cid)
all_digits = valid_digits(incoming_cid)
non_repeat = non_repeating_cid(incoming_cid)
if visible_number and good_length and all_digits and non_repeat:
print'YES'else:
print'NO'

add_log.py

This saves caller ID info and time it came in to the CallLog table. We don't use it directly in any of the Banana Phone dialplan, but I can't leave this obvious feature out. You should always keep logs.

generate_auth_audio.py

Banana Phone generates audio clips with random 4-digit passwords embedded in them. The first part of that process starts with generating the 4-digit code audio and saving it to a place for later retrieval.

Audio files for Banana Phone

I don't think I can legally hand out copies of that song on my site, so we're just gonna use some royalty-free music courtesy of Bensound.com for the background music.

We also need some sound clips of the numbers 0 -9, and some explanatory intro speech and instructional speech, so I used Google's free Text-to-Speech service courtesy of soundoftext.com for those files.

Download and place the following files in the /home/banana/banana_phone/audio_clips/slns directory we made earlier:

The Banana Phone dialplan

This is where all Asterisk and our database scripts all come together to create our robocall blocker.

Here is a flow chart showing the logic flow for the Banana Phone dialplan.

I'm not doing any techno-sorcery here. It's really that simple.

Now actually getting Asterisk to do all those tricks is another story.

Asterisk has enough input flexibility within it's dialplan applications to where we can get programmatic call control without using AGI or AMI. And that's great, because the dialplan is the most stable programming option of the three.

* Please note: commands on the dialplan are meant to be on single lines, but the code highlighting generator I used put some of the longer ones on two lines. Just put them as single lines. Lines like 22/23, 25/26, 27/28, 49/50, etc. are supposed to be one line

Now here's the code for the Banana Phone dialplan. Open up /etc/asterisk/extensions.conf and replace our original, minimalist dialplan with this:

On line 18, replace "5555555555" with the 10-digit phone number of the phone line plugged into the Obi ATA.

There a couple subtle dialplan nuances used here, particularly when generating the audio files and when the caller is actually entering in the input from their phone. I will leave that for the reader to dissect if they feel so inclined. Google is your friend, and so is .

I also peppered in a bunch of NoOp() calls as debug messages you can see in the console.

Testing

Testing here is pretty straight forward.

Call the phone line attached to your Obi ATA

Follow the instructions

Input the code

See if it rings

If it does, call again, you shouldn't have to test twice

Debugging tips

I've tried to write an easy-to-follow tutorial, with little debug checks at the end of every section. However, it's easy to miss steps or forget stuff, so if your install doesn't work right the first time you try, go through these steps:

Are you able to see calls coming into Asterisk?

Try running the minimal dialplan from section 2 and see if calls come in. If not, try redoing the configurations on Asterisk and the Obi ATA until you can.

The Asterisk debug console is your friend. Use it to check how calls are being processed, where they mess up in the dialplan, and if your ATA is connected

When editing extensions.conf, you must reload the dialplan from the Asterisk debug console for changes to take affect. Remember to use this command at the debug console:

dialplan reload

Conclusions

That's it for making Banana Phone.

I'm a one-man army trying to fight phone scams. I'm also in the middle of commercializing my idea, so if this tutorial helped solve your robocall problem or you got some legitimate good information from this, please consider donating to the project. Beer money goes along way ;)