Last active
June 15, 2021 21:47
-
-
Save eduardomazolini/57e40ba56ed46f9607a90923cfc188ff to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/php -q | |
## Local | |
# /usr/local/elastix/addons_scripts | |
<?php | |
function curl_post_json($url, $post = NULL, $options = array(), $userpass = NULL) | |
{ | |
$post_string = $post; | |
$defaults = array( | |
CURLOPT_CUSTOMREQUEST => "POST", | |
CURLOPT_URL => $url, | |
CURLOPT_RETURNTRANSFER => 1, | |
CURLOPT_FORBID_REUSE => 1, | |
CURLOPT_TIMEOUT => 4, | |
CURLOPT_POSTFIELDS => $post_string, | |
CURLOPT_SSL_VERIFYPEER => 0, | |
CURLOPT_HTTPHEADER => array( | |
'Content-Type: application/json', | |
'Content-Length: ' . strlen($post_string) | |
) | |
); | |
$ch = curl_init(); | |
curl_setopt_array($ch, ($options + $defaults)); | |
if (isset($userpass)) { | |
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); | |
curl_setopt($ch, CURLOPT_USERPWD, $userpass); | |
} | |
if( ! $result = curl_exec($ch)) | |
{ | |
trigger_error(curl_error($ch)); | |
} | |
curl_close($ch); | |
return $result; | |
} | |
if ($argv[1] == "--parameters"){ | |
echo "uniqueid"."\n"; | |
echo "answer" . "\n"; | |
echo "src" . "\n"; | |
echo "dst" . "\n"; | |
echo "billsec" . "\n"; | |
echo "dstchannel" . "\n"; | |
echo "disposition" . "\n"; | |
echo "accountcode" . "\n"; | |
echo "channel" . "\n"; | |
echo "dial_trunk" . "\n"; | |
echo "callerid_name" . "\n"; | |
} else { | |
$args = implode(" ",$argv); | |
$ki = strrpos($args, " -k"); | |
$ji = strrpos($args, " -j"); | |
$ii = strrpos($args, " -i"); | |
$hi = strrpos($args, " -h"); | |
$gi = strrpos($args, " -g"); | |
$fi = strrpos($args, " -f"); | |
$ei = strrpos($args, " -e"); | |
$di = strrpos($args, " -d"); | |
$ci = strrpos($args, " -c"); | |
$bi = strrpos($args, " -b"); | |
$ai = strrpos($args, " -a"); | |
$a = substr($args,$ai+3,$bi-$ai-3); | |
$b = substr($args,$bi+3,$ci-$bi-3); | |
$c = substr($args,$ci+3,$di-$ci-3); | |
$d = substr($args,$di+3,$ei-$di-3); | |
$e = substr($args,$ei+3,$fi-$ei-3); | |
$f = substr($args,$fi+3,$gi-$fi-3); | |
$g = substr($args,$gi+3,$hi-$gi-3); | |
$h = substr($args,$hi+3,$ii-$hi-3); | |
$i = substr($args,$ii+3,$ji-$ii-3); | |
$j = substr($args,$ji+3,$ki-$ji-3); | |
$k = substr($args,$ki+3); | |
// echo "A: " . $a . "\n"; | |
// echo "B: " . $b . "\n"; | |
// echo "C: " . $c . "\n"; | |
// echo "D: " . $d . "\n"; | |
// echo "E: " . $e . "\n"; | |
// echo "F: " . $f . "\n"; | |
// echo "G: " . $g . "\n"; | |
// echo "H: " . $h . "\n"; | |
// echo "I: " . $i . "\n"; | |
// echo "J: " . $j . "\n"; | |
// echo "K: " . $k . "\n"; | |
if($g == "NO ANSWER") { | |
$log = fopen('teste.log', 'a'); | |
} else { | |
$log = fopen('teste-answer.log', 'a'); | |
} | |
fwrite($log, date("d/m/Y H:i:s") . " G: " . $g . " A:" . $a . " B:" . $b . " C:" . $c . " D:" . $d . " E:" . $e . " F:" . $f . " H:" . $h . " I:" . $i . " J:" . $j . " K:" . $k . "\n"); | |
fclose($log); | |
$plantao="N"; | |
if($d == "801") $setor="no atendimento"; | |
elseif($d == "802") $setor="no suporte"; | |
elseif($d == "803") $setor="pra pedir ajuda em campo"; | |
elseif($d == "804") {$setor="no plantão do Plantonista1"; $plantao="S";} | |
elseif($d == "805") {$setor="no plantão do Plantonista2"; $plantao="S";} | |
if(isset($setor) && $g == "NO ANSWER") { | |
echo date("d/m/Y H:i:s") . " - Por favor retornar para ".$k." telefone ".$c." a pessoa queria falar ".$setor."\n"; | |
$post_string = '{"value1":"'.'Por favor, retornar para '.$k.' telefone '.$c.' a pessoa queria falar '.$setor.'. Ligou as: ' . date("d/m/Y H:i:s") . '"}'; | |
// curl_post_json('https://maker.ifttt.com/trigger/noanswer/with/key/<KEY>',$post_string); | |
exec('/usr/local/elastix/addons_scripts/lostcall.py '. '"'.date("d/m/Y H:i:s").'"' .' "'.$k.'" '.$c.' "'.$setor .'" '. $e . ' False',$output,$ret); | |
} elseif ( $g == "NO ANSWER" ) { | |
echo date("d/m/Y H:i:s") . " A:" . $a . " B:" . $b . " C:" . $c . " D:" . $d . " E:" . $e . " F:" . $f . " H:" . $h . " I:" . $i . " J:" . $j . " K:" . $k; | |
} elseif ($plantao == "S" && $g == "ANSWERED" ) { | |
echo date("d/m/Y H:i:s") . " - 0 ".$k." telefone ".$c." conseguiu falar ".$setor."\n"; | |
$post_string = '{"value1":"'.'(like) O '.$k.' telefone '.$c.' conseguiu falar '.$setor.'. Ligou as: ' . date("d/m/Y H:i:s") . '. A conversa durou: ' . $e . ' segundos"}'; | |
// curl_post_json('https://maker.ifttt.com/trigger/noanswer/with/key/<KEY>',$post_string); | |
exec('/usr/local/elastix/addons_scripts/lostcall.py '. '"'.date("d/m/Y H:i:s").'"' .' "'.$k.'" '.$c.' "'.$setor .'" '. $e . ' True',$output,$ret); | |
} | |
} | |
fwrite($log, "LOG: ".$output); | |
fclose($log); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment