Showing posts with label asterisk. Show all posts
Showing posts with label asterisk. Show all posts

Thursday, September 06, 2012

Using Blacklists, Google Contact Synchronization and Opencnam In Asterisk

I use Broadvoice who has had problems with passing callerid data to me since April 24, 2012 with no resolution as of the writing of this post on September 6, 2012.  I guess that only way that I can resolve issues with them is to dump them.  Yes, I'm calling you out Broadvoice.

I've been able to work around Broadvoice and their horrible technical support and engineering.

I've implemented a callerid solution in asterisk using the following:


  • Manual Database Entries for Blacklisting
  • Google Contact Synchronization
  • Opencnam Lookups



Blacklisting

I add political, charity, religious organizations and businesses that I've had dealings with that I never want to talk to again to a blacklist.  They don't follow do-not call rules here in the US.

Connect to the asterisk console using asterisk -r

Add the number the database.  I add the number with and without the country code because callerid comes in differently 

database put blacklist 6305392500 1
database put blacklist 16305392500 1

Google Contact Synchronization

I followed the instructions on the PBX in a Flash Forums below to setup the script.


I modified the python script to take out the plus symbol and also remove the the country code.  I planned on using the google contacts for caller id for Google Voice as well as from my voip provider.

# Insert the number into the cidname database, reinsert the country code if defined.
            #os.system("/usr/sbin/asterisk -rx \'database put cidname +%s%s \"%s\"\'" % (country_code,phone.text,entry.title.text))
            os.system("/usr/sbin/asterisk -rx \'database put cidname %s%s \"%s\"\'" % (country_code,phone.text,entry.title.text))
            os.system("/usr/sbin/asterisk -rx \'database put cidname %s \"%s\"\'" % (phone.text,entry.title.text))



Added A Crontab Entry That Runs Every 30 Minutes
0,30 * * * * /usr/local/bin/python /usr/local/bin/googlecontacts.py > /dev/null 2>&1




Opencnam Lookup

Here's the cnam.agi.  I made it an executable and added it to /usr/share/asterisk/agi-bin/.  Your install may be different.  You'll need the curl binary to make it work.  I also log the cnam transactions in a temporary log file.


cnam.agi 

#!/bin/bash

cidnum=$1
TODAY=$(date)
name=`curl -s -X GET https://api.opencnam.com/v1/phone/$cidnum?format=PBX`

echo $TODAY >> /tmp/cnam.log
echo $cidnum >> /tmp/cnam.log
echo $name >> /tmp/cnam.log
echo "" >> /tmp/cnam.log

if [ -n "$name"  ]; then

echo "SET VARIABLE lookupname \"${name}\""
read RESPONSE

exit 0

else

exit 1

fi




Here's everything in the extensions.conf



[from-broadvoice]
exten => _X!,1,GotoIf(${DB_EXISTS(blacklist/${CALLERID(num)})}?blacklisted,s,1)
exten => _X!,n,Set(CALLERID(name)=${DB(cidname/${CALLERID(num)})})
exten => _X!,n,GotoIf($["${CALLERID(name)}" = ""]?blank)
exten => _X!,n,Dial(SIP/holla,30,tr)
exten => _X!,n,Voicemail(holla)
exten => _X!,n,Playback(vm-goodbye)
exten => _X!,n,Hangup()
exten => _X!,n(blank),NoOp(cnam.agi)
exten => _X!,n,AGI(cnam.agi,${CALLERID(num)})
exten => _X!,n,Set(CALLERID(name)=${lookupname})
exten => _X!,n,Dial(SIP/holla)
exten => _X!,n,Voicemail(holla)
exten => _X!,n,Playback(vm-goodbye)
exten => _X!,n,Hangup()

[from-googlevoice]
exten => _X!,1,NoOp(Call from Google Voice)
exten => _X!,n,Set(CALLERID(num)=${CUT(EXTEN,/,2)})
exten => _X!,n,Set(CALLERID(name)=${DB(cidname/${CALLERID(num)})})
exten => _X!,n,GotoIf($["${CALLERID(name)}" = ""]?blank)
exten => _X!,n,Dial(SIP/holla,30,D(:1))
exten => _X!,n,Hangup()
exten => _X!,n(blank),NoOp(cnam.agi)
exten => _X!,n,AGI(cnam.agi,${CALLERID(num):1})
exten => _X!,n,Set(CALLERID(name)=${lookupname})
exten => _X!,n,Dial(SIP/holla,30,D(:1))
exten => _X!,n,Hangup()

[blacklisted]
exten => s,1,Wait(2)
exten => s,n,Playback(ss-noservice)
exten => s,n,Wait(1)
exten => s,n,Hangup()

Saturday, May 26, 2012

Adding Music on Hold Via The Logitech Media Server



Adding Music on Hold Via The Logitech Media Server (aka Squeezebox Server)

I had an AHA moment this morning when I thought about my abismal music on hold situation on my asterisk server.   I checked my logs for the first time in awhile and found out that people waiting on hold hadn't been receiving music while on hold for quite some time because I migrated to a different mount point for a new raid array.


I did a little research and found out this article (Using Slimserver for Music on Hold )that I could already use the  Logitech Media Server's mp3 stream to loop thru a playlist of selected songs.



Here's how it works.


mkdir /var/lib/asterisk/mohmp3-dummy
touch /var/lib/asterisk/mohmp3-dummy/dummy.mp3

Install mpg123 if you don't have it already
Edit your musiconhold.conf. and note the location of mpg123.

[default]
mode=custom
dir=/var/lib/asterisk/mohmp3-dummy {COMMENT}daab{/COMMENT}
application=/usr/bin/mpg123 -q -r 8000 -f 8192 -s --mono http://localhost:9000/stream.mp3



Reload asterisk
asterisk -rx 'reload'


Go to your Logitech Media Server/Squeezebox server's website.   Usually http://ip:9000.  Click on the player pulldown and you should see an entry for mpg123 from ipaddress.


From there  start creating a playlist and don't forget to save it and set it on repeat.