[Asterisk-Users] US$200 bounty for * paging feature

Jeb Campbell jebc at c4solutions.net
Wed Apr 20 06:33:19 MST 2005


Henry Devito wrote:
> I am already doing this with AGI, PERL, and PHP to set up the page 
> groups. I will release the code as open source if people are 
> interested.  I'm not the best PERL scripter in the world but it works.

Attached is the agi I'm using.  This is a modified script from a post on 
voip-info.  This works with our Cisco's that are setup like this: Line1 
- XXX and Line2 -- XXX_i (for intercom).

The modifications from the stock script are paging to SIP/XXX_i (not 
SIP/XXX), dynamic conferences based on original callerid, and playing 
the beeps (Cisco just answers so this gives users a warning).

There is code to see if SIP/XXX is in use, and if so not to call 
SIP/XXX_i, but the users wanted to see all pages so it is commented out.

Zones would be real easy with some arrays (as the conference is dynamic 
based on the person calling) and the variables are there to check inuse, 
etc.

extensions.conf:

[paging]
exten => *999,1,AGI(page.agi|${CALLERIDNUM})
exten => *999,2,Wait(1)
exten => *999,3,Playback(beep)
exten => *999,4,MeetMe(${CALLERIDNUM},dtqpA)
exten => *999,5,Hangup
[add-to-allcall]
exten => _X.,1,Playback(beep)
exten => _X.,2,MeetMe(${EXTEN},dmqpwx)
exten => _X.,3,Hangup

Really easy to modify.  Have fun.

Again this could be cleaner, but I got that other script working and 
haven't had the time or need to clean it up.

Jeb Campbell
jebc at c4solutions.net

-------------- next part --------------
#!/usr/bin/perl
#
#
# allcall.agi will add all your Polycom sip phones to a meet me 
# conference for use in office wide paging
#
# It takes arguments in the form of SIP/XXXX where XXXX is your 
# sip extension. (can be any number of digits) The first argument
# is the originating caller and additional arguments are any other
# phone lines you wish to exclude
#
use strict;
use File::Copy;

# A Few Variables to Set and Initialize
#
#
my $outgoing     = '/var/spool/asterisk/outgoing';
my $temp         = '/var/tmp';
my $asterisk     = '/usr/sbin/asterisk';
my $audio_out    = 'console/dsp';

my @bypass       = ();
my @meetme_calls = ();
my @rawsips      = ();
my @sips         = ();
my @intercoms    = ();

my $callerid     = "Error";

# Parse out the Sip phones to exclude
#
# This truly shows my lack of understanding of perl
#
foreach (@ARGV) {
    @bypass = split ( / /, $_ );
}

# This is our originating caller.  I need his
# callerid so that others will know who the paging
# pest is:
#
$callerid = $bypass[0];
$callerid =~ s-SIP/--g;

# Setup an array with all the sip phones
#
# I think I could use the Asterisk::AGI here
# and also the incominglimit in sip.conf to accomplish
# this, but I'm not that good.

@rawsips = `$asterisk -rx "sip show inuse"`;
chomp(@rawsips);
shift (@rawsips);
shift (@rawsips);
@rawsips = sort (@rawsips);

#Jeb
# split to sips and intercoms
@sips = grep ( /^\d{3,4} / , @rawsips );
@intercoms = grep ( /^\d{3,4}_i / , @rawsips );

# Now check each sip phone to see if it's in use and also
# against our exclude list.  If it passes both, it's 
# added to our array of calls to make

foreach (@sips) {
    my $sipphone = $1 if /(\d{3,4}) /;
    my $sipinuse = substr( $_, 16, 1 );
    unless ( grep ( /$sipphone/i, @bypass ) ) {
        #if ( grep ( /${sipphone}_i/i , @intercoms ) and $sipinuse == 0 ) {
        if ( grep ( /${sipphone}_i/i , @intercoms ) ) {
            push ( @meetme_calls, make_call("SIP/${sipphone}_i") );
            #push ( @meetme_calls, "SIP/${sipphone}_i" );
	}
    }
}

# The array is complete.  The push line is uncommented 
# if you want to add audio out to the intercom
#
#
# push ( @meetme_calls, make_call("$audio_out") );

# Now move each call file to the outgoing directory
#
# Here's some more perl ugly
# 
foreach my $call (@meetme_calls) {
    move( "$temp" . '/' . "$call", "$outgoing" . '/' . "$call" );
}

#print join("\n", at meetme_calls) . "\n";

exit 0;


sub make_call {    # makes the call file and returns the name
    my $stripslash = $_[0];
    $stripslash =~ s/\///g;
    my $tempcall = $temp . '/' . $stripslash . $$;
    my $callbase = $stripslash . $$;

    open( call, ">$tempcall" );

    print call << "EOF";
Channel: $_[0]
MaxRetries: 1
Retry: 0
RetryTime: 60
Context: add-to-allcall
Extension: $callerid 
Priority: 1 
SetVar: ALERT_INFO="Ring Answer"
CallerID: All-Call <$callerid>
EOF
    close(call);
    return $callbase;
}



More information about the asterisk-users mailing list