How to set random callerid in vicidial and asterisk

Topic: Vicidial Random caller ID or CID Groups

    If you are using Vicidial or any other Asterisk based dialer  and you are looking for the option how to set random caller ID in round robin or random, then this post is for you. In this Article I have provided the options to set the random caller-id either using the Asterisk Dialplan or Asterisk AGI script or using the Vicidial Cid Groups


vicidial random caller-id with cid groups
How to add Random Caller ID in vicidial

Why Random Caller ID?

    There are couple of reasons to set a Random caller-id or auto rotate the caller-id, the First Reason is The TrueCaller App in which a customer can mark a Caller-id as SPAM which reflect to others who using the Same App which will pop up as spam before attending the call,
 Next Reason in Call centers they need to Call leads multiple times throughout the day without using the same number every time
 Next Reason some times the telco blocks the calls received from same callerid over a short period of time.

Vicidial Random Caller-id Options

    Vicidial is an enterprise class, open source, contact center suite in use by many large call centers around the world. VICIdial has a full featured predictive dialer.  It is capable of inbound, outbound, and blended phone call handling. 

    In Vicidial the Random callerid can be achived using the follwing options
1. Vicidial CID Group settings 
2. Asterisk Dialplan with Rand Function
3. Asterisk AGI script and text file with list of numbers

Vicidial CID Groups

    Vicidial latest version support the option called CID group, which is similar to the Campaign AC-CID, but you can use same CID group  across multiple Campaigns.
With CID Group you can set CID state wise , Area code wise if both these option is not selected then all the CID's will be rotated with every calls ,like random callerid .

Steps to enable CID Group

Navigate to ADMIN > SYSTEM SETTINGS , make sure below option is enabled by setting the value to 1
Enable CID Groups and Campaign Areacode CID :1
once enabled Navigate to  ADMIN > CID GROUPS

add a CID Group and fill the below values
CID Group ID: 10001
CID Group Note: Random callerid
CID Group Type: NONE
Admin User Group: All Admin User Groups
Submit
in the Next section add your CID one by one with Description and press ADD button
Followed to that click CHECKBOX under ACTIVE column to activate this CID 
either select select all to activate all CID's and press SUBMIT CHANGES

Next Go to your campaign detail view and enable this new CID Group from the dropdown.
CID GROUP: 10001
once select press SUBMIT 

Asterisk RAND function 

       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()

Random Callerid with asterisk AGI script 

            This method can be used were you have  numbers that is not in range,  numbers are placed in a txt file, from which a  random number will be filtered and set as caller-id.

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

https://sourceforge.net/projects/phpagi/files/

a.  Download the PhpAgi from above link to your windows desktop
b.  Use winscp Copy the file to /var/lib/asterisk/agi-bin  directory.
c.  use putty to login to linux /asterisk server
d . cd /var/lib/asterisk/agi-bin/

e.  tar -xvzf phpagi-2.20.tgz
f.   chmod -R 777 phpagi-2.20
g. 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

Conclusion:

    Hope this article is helpful in setting the random Caller ID in vicidial or any asterisk based dialers. For any professional support reach me on skype or telegram id: striker24x7

5 Comments
  • Ajit Kumar
    Ajit Kumar April 4, 2022 at 11:39 AM

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

  • Anonymous
    Anonymous August 4, 2022 at 8:53 PM

    I have cluster setup so where this needs to be done? In every Asterisk server or Web Server?

    • Ajit Kumar
      Ajit Kumar August 4, 2022 at 10:34 PM

      yes every asterisk server which used to dialout via carrier

  • Touseef
    Touseef September 12, 2023 at 12:10 AM

    This comment has been removed by the author.

  • Touseef
    Touseef September 12, 2023 at 12:11 AM

    This comment has been removed by the author.

Add Comment
comment url