Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

UI Expand
titleHow can I add incoming call rules?
Code Block
php
php
<?php
/* Disable cache */
ini_set('soap.wsdl_cache_enabled', 0);
 
/* Configure variables */  
 
/* IP of the VoipNow server (including port) */
$IP = "192.168.14.30"; //CHANGE 
 
/* Version of the VoipNow product */
$VERSION = '3.0.0'; //CHANGE 
 
/* Authentication token*/
$TOKEN= '1|n_xOgmCNHc_KLnvOh0T_N8yGM8sX.p05|1|B~GqASQvCd.dpq6tjtV.dmkzk6pX~Dnp'; //CHANGE    
 
/* Extended number of the extension you want to add incoming call rules to */
$EXTENDEDNUMBER = '0007*001'; //CHANGE
 
/* Id of the time interval you want to assign to the rule 
 * the available ids are the actions of the options of the select which allows you to choose a time interval in the VoipNow interface (from Extension page >> Incoming call rules) */
$INTERVALID = '111'; //CHANGE

/* set SSL context options */
$streamContext = stream_context_create(array(
    'ssl' => array(
        'verify_peer' => false,
        'verify_peer_name' => false,
        'allow_self_signed' => true
     )
));
 
/* Create SOAP client based on WSDL, with trace for debugging */
$client = new SoapClient('https://' . $IP . '/soap2/schema/' . $VERSION . '/voipnowservice.wsdl', array('trace' => 1, 'exceptions' => 1, 'stream_context' => $streamContext));
  
/* Create authentication headers */
$auth = new stdClass();
$auth->accessToken= $TOKEN;
 
$userCredentials = new SoapVar($auth, SOAP_ENC_OBJECT, 'http://4psa.com/HeaderData.xsd/' . $VERSION);
 
$header = new SoapHeader('http://4psa.com/HeaderData.xsd/' . $VERSION, 'userCredentials', $userCredentials, false);

$client->__setSoapHeaders(array($header));
 
/**
 * This function computes a random search report for properties like: 'flow', 'type', 'disposion', 'hangupCause'
 *
 * @param numeric $intervalID time interval ID
 * @param numeric $step how many groups of records can be added once. should be at least 1
 *
 * @return array a search query array
 */
function computeCallRules($intervalID, $step = 1) {
    $actions = array('busy', 'congestion', 'hangup', 'transfer', 'cascade', 'authenticate', 'setCallPriority');
 
    //Rule matches the criteria: o for Match: 0, -1 for Does not match, 1 for Is anonymous and 2 for Is any. Default value: 0
    $matches = array('0' => '0', //Match
                     '1' => '-1', //Does not match
                     '2' => '1', //Is anonymous
                     '3' => '2', //Is any
                    );
    //Extension status. 0 for Does not matter, 1 for Registered, -1 for Not Registered.
    $extensionStatuses = array('0' => '0', //Does not matter
                               '1' => '1', //Registered
                               '2' => '-1', // Not Registered.
                              );
   
    $call_rules = array();
    if ($step >= 1) {
        for($i = 0; $i < $step; $i++) {
            foreach ($actions as $action) {
                $_rule =  array(
                                'match' => $matches[rand(0,3)],
                                'number' => rand(10000,1000000),
                                'position' => '2',
                                'key' => rand(10,100),
                                'intervalID' => $intervalID,
                                );
  
                switch ($action) {
                    case 'transfer':
                        $_rule += array(
                                        'toNumbers' => array(
                                                            'transferNumber' => '11111',
                                                            'ring' => rand(3,59),
                                                            'call' => rand(0,1),
                                                            'askForCaller' => rand(0,1),
                                                            'transferFromCallee' =>(rand(3,100)%2 == 1) ? 1:0,
                                                            ),
										/*
										                                        /*
                                        'toVoicemail' => array(
												 			                                                            'transferNumber' => array('0003*001'),
															),	
										                                                            ),	
                                        */
                                        'callStatus' => rand(0,3), //Call status. 0 for Does not matter, 1 for Not Answered, 2 for Rejected, 3 for Busy
                                        'extensionStatus' => $extensionStatuses[rand(0,2)],
                                        'final' => rand(0,1),
                                    );
                    break;
         
                    case 'cascade':
                    $_rule += array(
                                    'toNumbers' => array(
                                                        'number' => '2222',
                                                        'ringAfter' => '22',
                                                        ),
                                    'ring' => rand(3,59),
                                    'final' => rand(0,1),
                                    );
                     break;
         
                    case 'authenticate':
                    $_rule = array(
                                    'password' => '111',
                                    'soundID' => '1112222222222',
                                    'final' => '1',
                                );
                    break;
         
                    case 'setCallPriority':
                    $_rule = array(
                                   'priority' => '1',
                                );
                     break;
         
                    default:
                    break;
                }
 
                $call_rules[][$action] = $_rule;
            }
        }
    }
     
    return $call_rules;
}
 
try {
    $callRule = array(
        'extendedNumber' => $EXTENDEDNUMBER,
        'rule' => computeCallRules($INTERVALID)
    );
   $result = $client->AddCallRulesIn($callRule);
  // $result = $client->GetTimeIntervals(array('ID' => 1));
} catch (SoapFault $exception) {
    echo "ERROR: <br/>" . $exception->getMessage() . "<br/><br/>";
}
 
echo "REQUEST:<br/>" . htmlentities($client->__getLastRequest()) . "<br/><br/>";
echo "RESPONSE:<br/>" . htmlentities($client->__getLastResponse()) . "<br/>";
?>

...

Except where otherwise noted, content in this space is licensed under a Creative Commons Attribution 4.0 International.