Hosted Vicidial server starts from $39 Contact Us Buy Now!

asterisk/vicidial random callerid

Estimated read time: 2 min

 How to set Random Callerid in asterisk(vicidial goautodial freepbx)


asterisk random

Why Random callerid setting required

           In call centers sometimes they need to show random callerids for each call, which are generated by autodiallers or predictive diallers ,so customers wont see that call is from same center.
in this blog i will show two methods to set random callerid  in asterisk or vicidial or goautodial based diallers, pbx.

Option 1 : using  RAND function in asterisk 

       RAND Function can be used in a scenario , if you have a range of DID's  like  40004001 to 40004999
pick any one number randomly within this range and set it has callerid.

Before entering the dialplan , let me explain little bit about RAND function

Asterisk Function RAND

Synopsis:

Choose a random number within a range

Description:

RAND(min,max)

choose a random number between min and max , min default to 0 if not specified,  while max may be upto 2147483647

Lets get in to dialplan

For eg:  consider the DID range as 40004001 to 40004999

those who use plain asterisk setup use the below dialplan

exten => _9X.,1,Set(CALLERID(num)=${RAND(40004001,40004999)})
exten => _9X.,2,Dial(SIP/VOIPTRUNK/${EXTEN:1})
exten => _9X.,3,Hangup()

Note:
for vicidail /goautodial you have to use below dialplan

exten => _9X.,1,AGI(agi://127.0.0.1:4577/call_log)
exten => _9X.,2,Set(CALLERID(num)=${RAND(40004001,40004999)})
exten => _9X.,3,Dial(SIP/VOIPTRUNK/${EXTEN:1},,Tto)
exten => _9X.,4,Hangup()


Option 2 :  Using php AGI script 

            This method can be used were you have  numbers ie: not in range,  numbers are placed in a txt file, from which a  random number will be filtered and set as callerid.

note: you must have PHPAgi  installed in your pbx server under agi directory
phpagi download link clickhere

1a.  Download the PhpAgi from this link to your windows desktop
1b.  Use winscp Copy the file to /var/lib/asterisk/agi-bin  directory.
1c.  use putty to login to linux /asterisk server
1d . cd /var/lib/asterisk/agi-bin/
1e.  tar -xvzf phpagi-2.20.tgz
1f.   chmod -R 777 phpagi-2.20

1G. create a file named randomcid.php  under  /var/lib/asterisk/agi-bin
   
  cd /var/lib/asterisk/agi-bin
 vi randomcid.php

2. copy the below script and paste in randomcid.php
  
#!/usr/bin/php
<?php
    include 'phpagi-2.20/phpagi.php';
    $agi = new AGI();
    $numbers = file('/var/lib/asterisk/agi-bin/cids-list.txt');
    $cid = array_rand($numbers, 1);
     //return trim($numbers[$cid[0]]);
    $newCID = trim($numbers[$cid]);
    //echo $newCID;
    $agi->set_variable("CALLERID(num)", $newCID);

?>

3. create a file named cids-list.txt    under /var/lib/asteisk/agi-bin
    and fill you numbers in a single column 
    vi /var/lib/asterisk/agi-bin/cids-list.txt

4. now we will write a dialplan with AGI function 

     for plain asterisk
     exten => _9X.,1,AGI(randomcid.php)
  exten => _9X.,2,Dial(SIP/VOIPTRUNK/${EXTEN:1})
  exten => _9X.,3,Hangup

     for Vicidial or goautodial 

  exten => _9X.,1,AGI(agi://127.0.0.1:4577/call_log)
  exten => _9X.,2,AGI(randomcid.php)
  exten => _9X.,3,Dial(SIP/VOIPTRUNK/${EXTEN:1},,tTo)
  exten => _9X.,4,Hangup


****************************************
Also see:

Post a Comment

Cookie Consent
We serve cookies on this site to analyze traffic, remember your preferences, and optimize your experience.