Station to Station intercom WITHOUT *80 prefix, use your one touch/blf keys, etc :)


I work for a company that installs NEC DSX & Samsung OfficeServ systems and is looking at starting to offer Asterisk as an option as well. My boss has stated that if you could not press the BLF key for an extension and have the called party immediately go off hook and just start talking (ie intercom) that it would be a deal breaker for most of his clients. So i came up with this solution…

create a directory under /var/www/html called “custom” and put the following into a file called intercom.php -

$link = mysql_connect(‘localhost’, ‘asteriskuser’, ‘amp109’);
if (!$link) {
die('Not Connected : ’ . mysql_error());

$db = mysql_select_db(‘asterisk’, $link);
if (!$db) {
die ('Can’t use foo : ’ . mysql_error());

$dst = $_GET[‘dst’];
$src = $_GET[‘src’];


$query=“SELECT * from devices where (id=’$src’)”;
$result=mysql_query($query,$link) or Die(‘Query Failed : ’ . mysql_error());
while ($row=mysql_fetch_array($result)) {
$q2="SELECT * from devices where (id=’$dst’)";
$res2=mysql_query($q2,$link) or Die('Query Failed : ’ . mysql_error());
if ($nr>0) {
echo $output;

then, edit extensions.conf to add the following macro -

exten => s,1,Macro(user-callerid,)
exten => s,n,Set(dialnumber=${ARG3})
exten => s,n,GotoIf($["${DB(DND/${dialnumber})}" = “YES”]?end)
exten => s,n,GotoIf($["${DB(AMPUSER/${dialnumber}/intercom/${AMPUSER})}" = “allow” ]?allow)
exten => s,n,GotoIf($["${DB(AMPUSER/${dialnumber}/intercom/${AMPUSER})}" = “deny” ]?nointercom)
exten => s,n,GotoIf($["${DB(AMPUSER/${dialnumber}/intercom)}" = “disabled” ]?nointercom)
exten => s,n(allow),Set(DEVICES=${DB(AMPUSER/${dialnumber}/device)})
exten => s,n,GotoIf($["${DEVICES}" = “” ]?end)
exten => s,n,Set(PLAYBEEP=TRUE)
exten => s,n,Macro(autoanswer,${DEVICES})
exten => s,n(nointercom),Noop(Intercom disallowed by ${dialnumber})

then edit the macro-dial from -

exten => s,1,GotoIf($["${MOHCLASS}" = “”]?dial)
exten => s,n,SetMusicOnHold(${MOHCLASS})
exten => s,n(dial),AGI(dialparties.agi)
exten => s,n,NoOp(Returned from dialparties with no extensions to call and DIALSTATUS: ${DIALSTATUS})

exten => s,n+2(normdial),Dial(${ds}) ; dialparties will set the priority to 10 if $ds is not null

to read instead -

exten => s,1,Set(PLAYBEEP=FALSE)
exten => s,2,GotoIf($["${MOHCLASS}" = “”]?dial)
exten => s,n,SetMusicOnHold(${MOHCLASS})
exten => s,n(dial),Set(DOINTERCOM=${CURL(http://localhost/custom/intercom.php?dst=${ARG3}&src=${CALLERID(num)} )})
exten => s,n,GotoIf($["${DOINTERCOM}"=“ALLOW”]?dointercom:dialagi)
exten => s,n(dointercom),Macro(sta2sta,${ARG1},${ARG2},${ARG3})
exten => s,n(dialagi),AGI(dialparties.agi)
exten => s,n,NoOp(Returned from dialparties with no extensions to call and DIALSTATUS: ${DIALSTATUS})

exten => s,n+2(normdial),GotoIf($["${PLAYBEEP}"=“TRUE”]?dialicom:dialnoicom)
exten => s,n(dialicom),Set(ds=${ds}A(beep))
exten => s,n(dialnoicom),Dial(${ds})

What this does is if you dial an internal extension and they allow intercom (using FreePBX’s *54 and *55 feature codes) it will check via intercom.php to see if the calling AND called parties are both on the local pbx, by checking the devices table in the Freepbx mysql database, and if they are, it then checks the * internal database that FreePBX uses for allowing/disallowing intercom calls, if all conditions are met, and intercom is indeed allowed, it will add the SIP headers to make the receiving phone auto answer after 0 rings and play a beep sound to the called party to alert them to the intercom call, if intercom is not allowed it will simply ring the receiving phone. If the called number is NOT on the local pbx, it will simply place the call as usual… I need some real world tests of this so those that wish may put this in place and let me know how it works for you. I would welcome the feedback, and I’m hoping this can make it into the FreePBX standard install as I would hate to have to modify each and every system i install to enable this type of functionality, it really is a standard feature on just about every other phone system on the market today. It would be a shame for somebody to get some proprietary pbx just because Asterisk/FreePBX lacked this very basic feature :slight_smile:


Andrew Miffleton
Telecommunications Technician,
DFW Business Telephones
1260 Shiloh Rd.
Plano, TX 75074
(972)424-4242 x455

That is Awesome! I shall give it a try!