[Freeswitch-users] Sharing: Call Intercept

Anthony Minessale anthony.minessale at gmail.com
Mon Jun 25 05:54:06 MSD 2012


Thanks for the positive comment. =D

BTW, that reminds me.  I added a new pickup endpoint that you might
want to have a look at as well.
It lets you add a special pickup endpoint to a forked dial so say you
are calling ext 1000, you can do

<action application="bridge" data="user/1000,pickup/1000"/>

Then from another call you can execute:

<action application="pickup" data="1000"/>
And your channel will be returned to that unanswered originate.

We should probably get it documented.


On Sat, Jun 23, 2012 at 9:29 AM, Frank Busalacchi Jr
<frankjr at mcpeekdodge.com> wrote:
> Over the last 6 months, I have received all kinds of support and help from
> the freeswitch community (both IRC and this list) in learning to control
> this incredible piece of software.  Im truly grateful, thanks everyone.
>
>
>
> I run freeswitch at my car dealership.  We have approximately 40 sip
> extensions, an ATT voip connection, and 6 analog outbound fax lines provided
> by freetdm.  Prior to freeswitch, I was running an old Lucent/Avaya Merlin
> "key" system.  One of the features of the Merlin was that it was pretty easy
> to do "directed callpick".  In essence, you would dial *7 + extension you
> wanted to pickup.  Provided the call was either on hold or ringing at that
> extension, you would pick it up.  When I first started using Freeswitch, I
> was very disappointed in the directed callpick.  Before I realized that the
> call pickup that was built into the sample dialplan was really just an
> example to show a simple possibility for using intercept.  I was convinced
> that it was a totally useful feature.  I couldn't believe that was as good
> as it got...  My problem with the directed pickup that is in the sample
> dialplan is that it can steal a live call right from another extension, as
> well as it really only works with the most recent call on that extension.
>
>
>
> Then I woke up, and rolled my own 8-) .  In an effort to provide just
> another example, I wanted to share the piece of code I've developed.  I will
> warn that this was the first perl script I have ever written, and probably
> is pretty ugly, but it seems to work perfectly in our environment.  Bottom
> line, do what you want with it...I'm just trying to help other beginner's
> like myself:
>
>
>
> To all beginners:  You will need to build and enable mod_perl for this to
> work...
>
>
>
> First, we need an entry in your XML dialplan to see the user's request to
> interecept a "held" or "ringing" extension.  The only 4 digit extensions at
> my company are internal ones so I match on ** + 4-digit-extension.
>
>
>
> In the xML dialplan:
>
>
>
>     <extension name="intercept-ext">
>       <condition field="destination_number" expression="^\*\*(\d{4})$">
>         <action application="answer"/>
>         <action application="perl"
> data="/usr/local/freeswitch/scripts/myintercept.pl $1"/>
>         <action application="sleep" data="2000"/>
>       </condition>
>     </extension>
>
> Then, we need the actual perl script:
>
> /usr/local/freeswitch/scripts/myintercept.pl:
>
>
> # This is code to allow us to use intercept to grab only calls that are on
> hold or ringing.
> #
> # by Frank Busalacchi 2012-06-13
>
> use strict;
> use Switch;
> use Data::Dumper;
> use XML::Simple;
> use POSIX qw(strftime);
> our $session;
>
> {
>     my $dest_target = $ARGV[0];
>
>     my $api = new freeswitch::API();
>     my $xml = new XML::Simple;
>     my $chan_xml = $xml->XMLin($api->executeString("show detailed_calls as
> xml"),KeyAttr => 'row', ForceArray => ['row']);
>
>     my %candidates;
>     my $result;
>
>     foreach my $row (@{$chan_xml->{row}}) {
>         if ($row->{callstate} eq "RINGING" && $row->{dest} eq $dest_target)
> {
>             $candidates{ $row->{created_epoch} - 1000 }  =
> $row->{call_uuid};     #In the case of a tie, we want to pickup ringing
> calls before held calls...
>             next;
>         }
>
>         elsif ($row->{callstate} eq "HELD" && $row->{b_sent_callee_num} eq
> $dest_target ) {
>             $candidates{ $row->{created_epoch} } = $row->{b_uuid};
>             next;
>         }
>
>         elsif ($row->{b_callstate} eq "HELD" && $row->{b_callee_num} eq
> $dest_target ) {
>             $candidates{ $row->{b_created_epoch} } = $row->{uuid};
>             next;
>         }
>     }
>
>     if( keys( %candidates ) == 0) {
>         $result = "[Intercept] No suitable channel to intercept on extension
> $dest_target.";
>         freeswitch::consoleLog("INFO","$result\n");
>     }
>
>     else {
>         my $user = $session->getVariable('caller_id_name');
>         my $cid_num = $session->getVariable('caller_id_number');
>
>         for my $winner ( sort keys %candidates ) {
>
>             my $uuid= $candidates{$winner};
>
>             $result = "[Intercept]User:$user" . "[" . "$cid_num" . "]
> intercepting Extension:$dest_target" . ".  UUID:" . "$uuid" . "\n";
>             freeswitch::consoleLog("INFO","$result\n");
>             $session->execute("intercept",$uuid);
>             last;
>         }
>     }
>     1;
> }
>
>
>
> Enjoy!
>
>
>
> -Frank
>
>
>
>
>
>
> _________________________________________________________________________
> Professional FreeSWITCH Consulting Services:
> consulting at freeswitch.org
> http://www.freeswitchsolutions.com
>
> 
> 
>
> Official FreeSWITCH Sites
> http://www.freeswitch.org
> http://wiki.freeswitch.org
> http://www.cluecon.com
>
> Join Us At ClueCon - Aug 7-9, 2012
>
> FreeSWITCH-users mailing list
> FreeSWITCH-users at lists.freeswitch.org
> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
> http://www.freeswitch.org
>



-- 
Anthony Minessale II

FreeSWITCH http://www.freeswitch.org/
ClueCon http://www.cluecon.com/
Twitter: http://twitter.com/FreeSWITCH_wire

AIM: anthm
MSN:anthony_minessale at hotmail.com
GTALK/JABBER/PAYPAL:anthony.minessale at gmail.com
IRC: irc.freenode.net #freeswitch

FreeSWITCH Developer Conference
sip:888 at conference.freeswitch.org
googletalk:conf+888 at conference.freeswitch.org
pstn:+19193869900



Join us at ClueCon 2011 Aug 9-11, 2011
More information about the FreeSWITCH-users mailing list