Automate Asterisk to auto dial a number for testing

October 14, 2015 by Pat - Comments - - 3 min read

O'Brien LabsRecently, we brought in a new voicemail system at work, and we needed a way to reliably test it. The idea was to have a human call in every 30 minutes and leave a simple “testing 1, 2, 3” voicemail. To me that seemed rather cumbersome for someone to remember to do this every 30 minutes. So I began to think of a way to automate this. That’s when I had the idea for Asterisk to do this for me.

To get a fully working Asterisk system up in a short amount of time, and to make it as painless as possible, I started out with the Incredible PBX for CentOS. I was ready to go in about 30 minutes with a fully working Asterisk PBX system. I used Google Voice as my outgoing call trunk, which again was just to get things going as quickly as I could.

Once the Asterisk system was online, taking and making phone calls, I setup the automation. Essentially I have a crontab setup to make a call every 30 minutes. The voice and content of the call uses Google Text to Speech to say “Hello, this is a test, and the time is ".

For starters I setup extension 6090 in /etc/asterisk/extensions_custom.conf. Extension 6090 also uses the AMD tool to detect whether we’re talking to an answering machine or a human. In my case, it’s 100% a machine that I’m calling – however I thought it would be neat to play tricks on my co-workers every now and then.

exten => 6090,1,Answer
exten => 6090,2,Background(en_US/silence/1)
exten => 6090,n,Set(CDR(userfield)="Voicemail Automated Test")
exten => 6090,n,AMD()
exten => 6090,n,NoOp(${AMDSTATUS})
exten => 6090,n,GotoIf($[${AMDSTATUS}=HUMAN]?humn:mach)
exten => 6090,n(mach),WaitForSilence(700)
;exten => 6090,n(mach),WaitForSilence(4500,2,16)
;exten => 6090,n,Wait(3)
exten => 6090,n(proceed),agi(googletts.agi,"Hello! The time now is",en)
exten => 6090,n(proceed),SayUnixTime(,EST5EDT,ABdYIMp)
exten => 6090,n(proceed),agi(googletts.agi,"This is a test of the voicemail system. Goodbye.",en)
exten => 6090,n,Wait(1)
exten => 6090,n,Hangup()
exten => 6090,n(humn),agi(googletts.agi,"This is a test of the voicemail system. Goodbye.",en)
exten => 6090,n,Hangup()

Once done reload the asterisk dialplan:

asterisk -rx "dialplan reload"

Then, create the automatic outgoing script. Here’s what I used. Replace the Channel information with your proper trunk info. Create /root/automaticDialer/

Channel: Motif/<yourgooglevoicetrunkID>/<number you want to call>
CallerID: Voicemail <your caller id>
Extension: 6090
Context: test-voicemail
MaxRetries: 2
RetryTime: 60
WaitTime: 30
Priority: 2

Once you’ve created that, test it out by copying to the outgoing spool folder. This command will also launch the Asterisk console so you can see what’s going on (in case there’s any errors).

cp /root/automaticDialer/ /var/spool/asterisk/outgoing/ && asterisk -rvvvvvvvv

If the call completes, then you’re good to go! Now just create a simple cron task to do what you just did every 30 minutes.

crontab -e
0,30 * * * * /bin/cp /root/automaticDialer/ /var/spool/asterisk/outgoing/ > /dev/null 2>&1

There you have it. This is how I have Asterisk automatically test our new voicemail system every 30 minutes.

Disclosure: Some of the links on this website are affiliate links. This means that, at zero cost to you, I will earn an affiliate commission if you click through the link and finalize a purchase.
Share this post: