Refactory

main
Alan Oliveira 2024-12-13 22:14:11 -03:00
parent e4fc10ef5d
commit 1ec599bd92
30 changed files with 4411 additions and 5474 deletions

1
L
View File

@ -1 +0,0 @@
L

View File

@ -1,32 +0,0 @@
<?php
// Cria um servidor TCP
$server = new Swoole\Server("0.0.0.0", 4573);
// Define o callback para o evento de conexão recebida
$server->on("Connect", function ($server, $fd) {
echo "Cliente conectado: ID $fd\n";
});
// Define o callback para o evento de recebimento de dados
$server->on("Receive", function ($server, $fd, $reactor_id, $data) {
// Processa o fgId recebido
$fgId = trim($data);
if (empty($fgId)) {
$server->send($fd, "ERROR: fgId não fornecido\n");
} else {
// Envia uma resposta para o cliente
$response = "fgId recebido: $fgId\n";
echo $response; // Imprime no console do servidor
$server->send($fd, $response); // Envia resposta ao cliente
}
});
// Define o callback para o evento de desconexão
$server->on("Close", function ($server, $fd) {
echo "Cliente desconectado: ID $fd\n";
});
// Inicia o servidor
$server->start();

File diff suppressed because it is too large Load Diff

View File

@ -1,70 +0,0 @@
2024-12-12 13:48:24<hr><pre>Array
(
[fgId] => 7998
[logEnabled] => 1
[isXampp] => 1
)
</pre><br><pre>Array
(
[fgId] => 7998
[logEnabled] => 1
[isXampp] => 1
[fgItens] => Array
(
[1] => Array
(
[id] => 1
[idmaster] => 0
[cmd] => start
[value] => 7999
)
[2] => Array
(
[id] => 2
[idmaster] => 1
[cmd] => playaudio
[value] => welcome.wav
[value2] => 2
[value3] => 1
[value4] => false
)
[3] => Array
(
[id] => 3
[idmaster] => 2
[cmd] => timeout
[value] =>
)
[4] => Array
(
[id] => 4
[idmaster] => 3
[cmd] => playaudio
[value] => timeout.wav
[value2] => 2
[value3] => 1
[value4] => false
)
)
[fgItemStart] => Array
(
[id] => 1
[idmaster] => 0
[cmd] => start
[value] => 7999
)
)
</pre><br><hr>fgItemRun<br><br><pre>Array
(
[id] => 1
[idmaster] => 0
[cmd] => start
[value] => 7999
)
</pre><br>

View File

@ -1,482 +0,0 @@
<?php
class AGIEntrada
{
private $globais = array();
private $injection = array();
public function __construct($injection, $globais = array())
{
$globais['logEnabled'] = !isset($globais['logEnabled']) ? false : $globais['logEnabled'];
$globais['isXampp'] = !isset($globais['isXampp']) ? false : $globais['isXampp'];
$this->globais = $globais;
$this->injection = $injection;
}
public function agiRunCmd($command)
{
return $this->injection['agiRunCmd']($command);
}
public function agiLog($texto)
{
return $this->injection['agiLog']($texto);
}
// --------------------------------------------------------------------------------------------------------------------------------
public function logStart()
{
if ($this->globais['logEnabled']) {
$texto = date("Y-m-d H:i:s") . "<hr>";
$fp = fopen('log.html', 'w');
fwrite($fp, $texto);
fclose($fp);
}
}
public function logAdd($texto)
{
if ($this->globais['logEnabled']) {
$fp = fopen('log.html', 'a');
fwrite($fp, $texto);
fclose($fp);
}
}
// --------------------------------------------------------------------------------------------------------------------------------
public function agiVarGet($varName = '')
{
$return = '';
if ($this->globais['isXampp']) {
$return = '';
} else {
//$cmd = 'GET VARIABLE UNIQUEID'; // 200 result=1 (1695911399.249)
//$cmd = 'GET VARIABLE CALLERID(all)'; // 200 result=1 ("" <2001>)
//$cmd = 'GET VARIABLE EXTEN'; // 200 result=1 (2501)
$cmd = '';
if ($varName == 'CALLERID') {
$cmd = 'GET VARIABLE CALLERID(all)';
} else {
$cmd = 'GET VARIABLE ' . $varName;
}
$response = $this->agiRunCmd($cmd);
if ($varName == 'CALLERID') {
if (substr($response, 0, 14) == '200 result=1 (') {
$explodido = explode('<', $response);
$return = substr($explodido[1], 0, -2);
}
} else {
$explodido = explode("(", $response);
if (count($explodido) > 1) {
$explodido = explode(")", $explodido[1]);
$return = $explodido[0];
}
}
}
return $return;
}
public function agiVarSet($varName = '', $varValue = '')
{
if ($this->globais['isXampp']) {
return '';
} else {
if ($varName == 'CALLERID') {
$varName = 'CALLERID(num)';
}
$return = $this->agiRunCmd('SET VARIABLE ' . $varName . ' ' . $varValue);
return $return;
}
}
// --------------------------------------------------------------------------------------------------------------------------------
public function fgItemRunPlayaudio($fgItem = array())
{
$this->logAdd("<hr>fgItemRunPlayaudio<br><br>");
$this->logAdd("<pre>" . print_r($fgItem, true) . "</pre><br>");
}
public function fgItemRun($fgItem = array())
{
$this->logAdd("<hr>fgItemRun<br><br>");
$this->logAdd("<pre>" . print_r($fgItem, true) . "</pre><br>");
if (count($fgItem) > 0) {
// if ($fgItem['cmd'] == 'agi.exec') {
// fgItemRunAgiExec($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'blacklist.check') {
// fgItemRunBlacklistCheck($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'blacklist.true') {
// fgItemRunBlacklistTrue($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'blacklist.false') {
// fgItemRunBlacklistFalse($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'callerid.change') {
// fgItemRunCalleridChange($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'cnpj.check') {
// fgItemRunCNPJCheck($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'cnpj.true') {
// fgItemRunCNPJCheckTrue($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'cnpj.false') {
// fgItemRunCNPJCheckFalse($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'condtempo.check') {
// fgItemRunCondTempoCheck($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'condtempo.true') {
// fgItemRunCondTempoCheckTrue($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'condtempo.false') {
// fgItemRunCondTempoCheckFalse($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'cpf.check') {
// fgItemRunCPFCheck($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'cpf.true') {
// fgItemRunCPFCheckTrue($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'cpf.false') {
// fgItemRunCPFCheckFalse($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'dialextension') {
// fgItemRunDialExtension($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'dialgroupextension') {
// fgItemRunDialGroupExtension($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'dialplan.checkvar') {
// fgItemRunDialplanCheckvar($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'dialplan.gosub') {
// fgItemRunDialplanGosub($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'dialplan.setvar') {
// fgItemRunDialplanSetvar($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'dialdigit') {
// fgItemRunDialdigit($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'digit') {
// fgItemRunDigit($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'digitinvalid') {
// fgItemRunDigitInvalid($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'expediente.check') {
// fgItemRunExpedienteCheck($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'expediente.false') {
// fgItemRunExpedienteFalse($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'expediente.true') {
// fgItemRunExpedienteTrue($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'feriado.check') {
// fgItemRunFeriadoCheck($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'feriado.false') {
// fgItemRunFeriadoFalse($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'feriado.true') {
// fgItemRunFeriadoTrue($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'ivr.redirect') {
// fgItemRunIVRRedirect($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'nomatch') {
// fgItemRunNoMatch($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'pesqsat') {
// fgItemRunPesqSat($fgItem);
// return;
// }
if ($fgItem['cmd'] == 'playaudio') {
$this->fgItemRunPlayaudio($fgItem);
return;
}
// if ($fgItem['cmd'] == 'queue') {
// fgItemRunQueue($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'queue.waitingcount') {
// fgItemRunQueueWaitingCount($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'queue.waitingcount-greater') {
// fgItemRunQueueWaitingCountGreater($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'queue.withcallback') {
// fgItemRunQueueWithCallback($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'queue.withcallback-noready') {
// fgItemRunQueueWithCallbackNoReady($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'record') {
// fgItemRunRecord($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'start') {
// fgItemRunStart($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'timeout') {
// fgItemRunTimeout($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'timeoutwithlimit') {
// fgItemRunTimeoutWithLimit($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'timeoutwithlimit.limit') {
// fgItemRunTimeoutWithLimitLimit($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'voicemail') {
// fgItemRunVoicemail($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'whitelist.check') {
// fgItemRunWhitelistCheck($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'whitelist.false') {
// fgItemRunWhitelistFalse($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'whitelist.true') {
// fgItemRunWhitelistTrue($fgItem);
// return;
// }
// if (isset($fgItem['defaultvalues']['cmd'])) {
// if ($fgItem['defaultvalues']['cmd'] == 'dialplan.checkvar') {
// fgItemRunDialplanCheckvar($fgItem);
// return;
// }
// if ($fgItem['defaultvalues']['cmd'] == 'dialplan.gosub') {
// fgItemRunDialplanGosub($fgItem);
// return;
// }
// if ($fgItem['defaultvalues']['cmd'] == 'dialplan.setvar') {
// fgItemRunDialplanSetvar($fgItem);
// return;
// }
// }
}
}
public function teste()
{
$this->agiLog($this->globais['fgId']);
}
function tocarFila($queueId, $timeout)
{
return $this->agiRunCmd('EXEC Queue Q' . $queueId . ',ctT,,,' . $timeout);
}
// --------------------------------------------------------------------------------------------------------------------------------
public function run()
{
$this->logStart();
$this->logAdd("<pre>".print_r($this->globais, true) . "</pre><br>");
// $this->agiLog(print_r($this->globais, true) . "\n");
$this->globais['fgItens'] = array();
$this->globais['fgItemStart'] = array();
if ($this->globais['fgId'] != '') {
// ...
if (file_exists('/etc/asterisk')) {
$target = '/var/www/html/fluxograma/data-json/' . $this->globais['fgId'] . '.json';
} else {
$target = 'dial/' . $this->globais['fgId'] . '.json';
}
if (file_exists($target)) {
$itens = file_get_contents($target);
$itens = json_decode($itens, true);
foreach ($itens as $item) {
$this->globais['fgItens'][$item['id']] = $item;
if ($item['cmd'] == 'start') {
$this->globais['fgItemStart'] = $item;
}
}
unset($itens);
}
}
$this->logAdd("<pre>".print_r($this->globais['fgItens'], true) . "</pre><br>");
$this->logAdd("<pre>".print_r($this->globais['fgItemStart'], true) . "</pre><br>");
// $this->agiLog(print_r($this->globais['fgItens'], true) . "\n");
if (count($this->globais['fgItemStart']) > 0) {
$this->globais['arrDtmf'] = array(
'35' => '#',
'42' => '*',
'48' => '0',
'49' => '1',
'50' => '2',
'51' => '3',
'52' => '4',
'53' => '5',
'54' => '6',
'55' => '7',
'56' => '8',
'57' => '9'
);
if ($this->globais['isXampp']) {
$this->globais['callerid'] = '1138118400';
$this->globais['uniqueid'] = date("Ymd") . "." . date("His");
$this->globais['digitado'] = '';
$host = 'localhost';
$user = 'root';
$password = '';
$database = 'hitpbx_homologacao';
$port = '3306';
$this->globais['db'] = mysqli_connect($host, $user, $password, $database, $port) or die('Erro de conexão com o banco de dados');
mysqli_set_charset($this->globais['db'], 'utf8');
$this->fgItemRun($this->globais['fgItemStart']);
} else {
$host = '172.31.187.152';
$user = 'appuser';
$password = 'nmvP$x23Vzb@T%Su';
$hostname = gethostname();
$hostname = str_replace('hitpbx-', 'hitpbx_', $hostname);
$database = $hostname;
if ($hostname == 'hitpbx-001') {
$database = 'hitpbx-001';
}
$port = '6033';
$this->globais['db'] = mysqli_connect($host, $user, $password, $database, $port) or die('Erro de conexão com o banco de dados');
mysqli_set_charset($this->globais['db'], 'utf8');
/*
logAdd("111<br>");
$query = "SELECT * FROM tab_ramal LIMIT 1";
$result = mysqli_query($db,$query);
logAdd($query."<br>");
$result = mysqli_query($GLOBALS['db'],$query);
logAdd($query."<br>");
*/
// ...
/*
$host = '172.31.187.150';
$dbcdr = mysqli_connect($host, $user, $password, $database, $port) or die('Erro de conexão com o banco de dados');
mysqli_set_charset($dbcdr, 'utf8');
$query = "
CREATE TABLE IF NOT EXISTS tab_ivr_log2 (
`id` INT NOT NULL AUTO_INCREMENT,
`uniqueid` VARCHAR(32) NOT NULL,
`did` TEXT NULL,
`quando` DATETIME NULL,
`fgitem_json` TEXT NULL,
`fgitem_result` TEXT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
";
$result = mysqli_query($dbcdr,$query);
*/
// ...
$response = $this->agiRunCmd('EXEC NOOP HITAGI');
$response = $this->agiRunCmd('ANSWER');
$response = $this->agiRunCmd('EXEC WAIT 1');
$response = $this->agiRunCmd('EXEC PLAYBACK beep');
$response = $this->agiRunCmd('EXEC WAIT 1');
$this->globais['digitado'] = '';
$this->globais['callerid'] = $this->agiVarGet('CALLERID');
$this->globais['uniqueid'] = $this->agiVarGet('UNIQUEID');
$response = $this->agiVarSet('AGIDID', $this->globais['fgId']);
$cmd = 'EXEC QUEUELOG NONE,' . $this->globais['uniqueid'] . ',NONE,INFO|IVRSTART';
$response = $this->agiRunCmd($cmd);
$cmd = 'EXEC QUEUELOG NONE,' . $this->globais['uniqueid'] . ',NONE,INFO|IVRAPPEND|->' . $this->globais['fgId'];
$response = $this->agiRunCmd($cmd);
$this->fgItemRun($this->globais['fgItemStart']);
// 1353461660|1353461627.33271|NONE|NONE|INFO|IVRHANGUP|
//$cmd = 'EXEC QUEUELOG NONE,' . $GLOBALS['uniqueid'] . ',NONE,NONE,INFO|IVRHANGUP';
//$response = agiRunCmd($cmd);
// $response = agiRunCmd('HANGUP');
}
}
/*
$this->teste();
$this->globais['nomeFila'] = '10';
$response = $this->tocarFila($this->globais['nomeFila'], 1);
echo "\n" . $response . "\n";
*/
}
}

View File

@ -1,32 +0,0 @@
[
{
"id": "1",
"idmaster": "0",
"cmd": "start",
"value": "7999"
},
{
"id": "2",
"idmaster": "1",
"cmd": "playaudio",
"value": "welcome.wav",
"value2": "2",
"value3": "1",
"value4": "false"
},
{
"id": "3",
"idmaster": "2",
"cmd": "timeout",
"value": ""
},
{
"id": "4",
"idmaster": "3",
"cmd": "playaudio",
"value": "timeout.wav",
"value2": "2",
"value3": "1",
"value4": "false"
}
]

View File

@ -1,53 +0,0 @@
[
{
"id": "1",
"idmaster": "0",
"cmd": "start",
"value": "7999"
},
{
"id": "2",
"idmaster": "1",
"cmd": "playaudio",
"value": "welcome.wav",
"value2": "2",
"value3": "1",
"value4": "false"
},
{
"id": "3",
"idmaster": "2",
"cmd": "timeout",
"value": ""
},
{
"id": "4",
"idmaster": "3",
"cmd": "playaudio",
"value": "timeout.wav",
"value2": "2",
"value3": "1",
"value4": "false"
},
{
"id": "5",
"idmaster": "2",
"cmd": "dialdigit",
"value": ""
},
{
"id": "6",
"idmaster": "2",
"cmd": "digit",
"value": "2"
},
{
"id": "7",
"idmaster": "6",
"cmd": "playaudio",
"value": "digit-2.wav",
"value2": "2",
"value3": "1",
"value4": "false"
}
]

View File

@ -1,100 +0,0 @@
Array
(
[fgId] => 7998
[logEnabled] => 1
[isxampp] => 1
[isXampp] =>
)
Array
(
[1] => Array
(
[id] => 1
[idmaster] => 0
[cmd] => start
[value] => 7999
)
[2] => Array
(
[id] => 2
[idmaster] => 1
[cmd] => playaudio
[value] => welcome.wav
[value2] => 2
[value3] => 1
[value4] => false
)
[3] => Array
(
[id] => 3
[idmaster] => 2
[cmd] => timeout
[value] =>
)
[4] => Array
(
[id] => 4
[idmaster] => 3
[cmd] => playaudio
[value] => timeout.wav
[value2] => 2
[value3] => 1
[value4] => false
)
)
Array
(
[fgId] => 7998
[logEnabled] => 1
[isxampp] => 1
[isXampp] =>
)
Array
(
[1] => Array
(
[id] => 1
[idmaster] => 0
[cmd] => start
[value] => 7999
)
[2] => Array
(
[id] => 2
[idmaster] => 1
[cmd] => playaudio
[value] => welcome.wav
[value2] => 2
[value3] => 1
[value4] => false
)
[3] => Array
(
[id] => 3
[idmaster] => 2
[cmd] => timeout
[value] =>
)
[4] => Array
(
[id] => 4
[idmaster] => 3
[cmd] => playaudio
[value] => timeout.wav
[value2] => 2
[value3] => 1
[value4] => false
)
)

View File

@ -1,54 +0,0 @@
<?php
require_once 'AGIEntrada.php';
function agiRunCmdWrapper($stdin, $stdout)
{
return function ($command) use ($stdin, $stdout) {
$texto = "-----> EXECUTAR COMANDO $command";
return $texto;
};
}
function agiLogWrapper($logEnabled)
{
return function ($texto) use ($logEnabled) {
if ($logEnabled) {
$filename = str_replace('.php', '-log.txt', __FILE__);
$fp = fopen($filename, 'a');
fwrite($fp, $texto);
fclose($fp);
}
};
}
// --------------------------------------------------------------------------------------------------------------------------------
$stdin = fopen('php://stdin', 'r');
$stdout = fopen('php://stdout', 'w');
$fgId = (isset($argv[1])) ? $argv[1] : ''; // DID
$logEnabled = true;
$isXampp = (file_exists('C:\xampp'));
$appdir = dirname(__FILE__);
chdir($appdir);
date_default_timezone_set('America/Bahia');
$agientrada = new AGIEntrada(
array(
'agiRunCmd' => agiRunCmdWrapper($stdin, $stdout),
'agiLog' => agiLogWrapper($logEnabled)
),
array(
'fgId' => $fgId,
'logEnabled' => $logEnabled,
'isXampp' => $isXampp
)
);
$agientrada->run();
fclose($stdin);
fclose($stdout);
exit();

View File

@ -1,62 +0,0 @@
2024-12-12 13:50:55<hr><pre>Array
(
[fgId] => 7998
[logEnabled] => 1
[isXampp] => 1
)
</pre><br><pre>Array
(
[1] => Array
(
[id] => 1
[idmaster] => 0
[cmd] => start
[value] => 7999
)
[2] => Array
(
[id] => 2
[idmaster] => 1
[cmd] => playaudio
[value] => welcome.wav
[value2] => 2
[value3] => 1
[value4] => false
)
[3] => Array
(
[id] => 3
[idmaster] => 2
[cmd] => timeout
[value] =>
)
[4] => Array
(
[id] => 4
[idmaster] => 3
[cmd] => playaudio
[value] => timeout.wav
[value2] => 2
[value3] => 1
[value4] => false
)
)
</pre><br><pre>Array
(
[id] => 1
[idmaster] => 0
[cmd] => start
[value] => 7999
)
</pre><br><hr>fgItemRun<br><br><pre>Array
(
[id] => 1
[idmaster] => 0
[cmd] => start
[value] => 7999
)
</pre><br>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,109 @@
<?php
namespace Hit\Ami;
class ArquivoRemoto
{
public $ip;
public $port;
public function __construct()
{
$this->ip = 'localhost';
$this->port = '8083';
}
public function runCURL($args = array())
{
$arr['url'] = isset($args['url']) ? $args['url'] : '';
$arr['port'] = isset($args['port']) ? $args['port'] : '';
$arr['postfields'] = isset($args['postfields']) ? $args['postfields'] : '';
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_PORT => $arr['port'],
CURLOPT_URL => $arr['url'],
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => $arr['postfields'],
CURLOPT_HTTPHEADER => array(
"Content-Type: application/json",
"User-Agent: insomnia/2023.5.8"
),
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
return array('error' => "cURL Error #:" . $err);
}
$arr = json_decode($response, true);
if (json_last_error() != JSON_ERROR_NONE) {
return array('error' => 'cURL response not JSON');
} else {
return $arr;
}
}
public function pegar($args = array())
{
$url = 'http://' . $this->ip . ':' . $this->port . '/pegar';
$arr = array();
$arr['auth'] = isset($args['auth']) ? $args['auth'] : '80889736666668f4e2b9008ec15f5ca5';
$arr['filedir'] = isset($args['filedir']) ? $args['filedir'] : '';
$arr['filename'] = isset($args['filename']) ? $args['filename'] : '';
$postfields = json_encode($arr);
unset($arr);
$argssend = array();
$argssend['url'] = $url;
$argssend['port'] = $this->port;
$argssend['postfields'] = $postfields;
return $this->runCURL($argssend);
}
public function salvar($args = array())
{
$url = 'http://' . $this->ip . ':' . $this->port . '/salvar';
$arr = array();
$arr['auth'] = isset($args['auth']) ? $args['auth'] : '80889736666668f4e2b9008ec15f5ca5';
$arr['filedir'] = isset($args['filedir']) ? $args['filedir'] : '';
$arr['filename'] = isset($args['filename']) ? $args['filename'] : '';
$arr['filebase64'] = isset($args['filebase64']) ? $args['filebase64'] : '';
$postfields = json_encode($arr);
unset($arr);
$argssend = array();
$argssend['url'] = $url;
$argssend['port'] = $this->port;
$argssend['postfields'] = $postfields;
return $this->runCURL($argssend);
}
public function excluir($args = array())
{
$url = 'http://' . $this->ip . ':' . $this->port . '/excluir';
$arr = array();
$arr['auth'] = isset($args['auth']) ? $args['auth'] : '80889736666668f4e2b9008ec15f5ca5';
$arr['filedir'] = isset($args['filedir']) ? $args['filedir'] : '';
$arr['filename'] = isset($args['filename']) ? $args['filename'] : '';
$postfields = json_encode($arr);
unset($arr);
$argssend = array();
$argssend['url'] = $url;
$argssend['port'] = $this->port;
$argssend['postfields'] = $postfields;
return $this->runCURL($argssend);
}
}

View File

@ -1,14 +1,20 @@
{
"name": "hit/ami",
"autoload": {
"psr-4": {
"Hit\\Ami\\": "src/"
"name": "hitlabs/hitagi",
"type": "project",
"autoload": {
"psr-4": {
"Hitlabs\\Hitagi\\": "classes/"
}
},
"authors": [
{
"name": "HIT"
}
],
"require": {
"swoole/ide-helper": "~5.0.0",
"vlucas/phpdotenv": "^5.6",
"firebase/php-jwt": "^6.10",
"guzzlehttp/guzzle": "^7.9"
}
},
"require": {
"swoole/ide-helper": "~5.0.0",
"vlucas/phpdotenv": "^5.6",
"firebase/php-jwt": "^6.10",
"guzzlehttp/guzzle": "^7.8"
}
}
}

2
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "7cccddac512163c6eaa2449701d7945d",
"content-hash": "f78189202e95f3ab065c8f4b6d13b25b",
"packages": [
{
"name": "firebase/php-jwt",

View File

@ -28,5 +28,12 @@
"value2": "2",
"value3": "1",
"value4": "false"
}
},
{
"id": "5",
"idmaster": "4",
"cmd": "queue",
"value": "13",
"value2": "5"
}
]

1147
docs/manual-json.txt 100644

File diff suppressed because it is too large Load Diff

View File

@ -2,6 +2,7 @@
require __DIR__ . 'vendor/autoload.php';
require __DIR__ . 'includes/wrapper-swoole.php';
use Hitlabs\Hitagi\AGIEntrada;
use Swoole\Runtime;
use Swoole\Table;
use Swoole\Server;
@ -37,7 +38,7 @@ $server->on("receive", function ($server, $fd, $reactor_id, $data) {
'agi' => 1,
'data' => '',
));
$agi = new \Hit\Ami\AGIEntrada(
$agi = new AGIEntrada(
array(
'agiRunCmd' => agiRunCmdSwooleWrapper($fd, $server),
'agiLog' => function ($info) {

View File

@ -3,27 +3,26 @@
require 'vendor/autoload.php';
require 'includes/wrapper-noswoole.php';
use Hitlabs\Hitagi\AGIEntrada;
$stdin = fopen('php://stdin', 'r');
$stdout = fopen('php://stdout', 'w');
$fgId = (isset($argv[1])) ? $argv[1] : ''; // DID
$logEnabled = true;
$isXampp = (file_exists('C:\xampp'));
$isXampp = file_exists('C:\xampp');
$asteriskip = ''; // 177.107.205.248
$appdir = dirname(__FILE__);
chdir($appdir);
date_default_timezone_set('America/Bahia');
$agientrada = new \Hit\Ami\AGIEntrada(
$agientrada = new AGIEntrada(
array(
'agiRunCmd' => agiRunCmdWrapper($stdin, $stdout),
'agiLog' => agiLogWrapper($logEnabled)
'agiLog' => agiLogWrapper()
),
array(
'fgId' => $fgId,
'asteriskip' => '177.107.205.248',
'asteriskip' => $asteriskip,
'logEnabled' => $logEnabled,
'appdir' => $appdir,
'isXampp' => $isXampp

View File

@ -7,33 +7,26 @@ function agiRunCmdWrapper($stdin, $stdout)
// return $texto;
$return = '';
fwrite($stdout, $command . "\n");
fflush($stdout);
while ($line = fgets($stdin)) {
$return.= $line;
if (strpos($line, 'result=') !== false) {
if (substr($line,0,22) != '100 result=0 Trying...') {
break;
}
}
}
$return = trim($return);
return $return;
};
}
function agiLogWrapper($logEnabled)
{
return function ($texto, $options = array()) use ($logEnabled) {
if ($logEnabled) {
$target = 'log' . DIRECTORY_SEPARATOR . 'log.txt';
$texto .= PHP_EOL;
if (isset($options['new'])) {
file_put_contents($target, $texto);
} else {
file_put_contents($target, $texto, FILE_APPEND);
fwrite($stdout, $command . "\n");
fflush($stdout);
while ($line = fgets($stdin)) {
$return .= $line;
if (strpos($line, 'result=') !== false) {
if (substr($line, 0, 22) != '100 result=0 Trying...') {
break;
}
}
}
$return = trim($return);
return $return;
};
}
function agiLogWrapper()
{
return function ($texto) {
$target = 'log' . DIRECTORY_SEPARATOR . 'log.txt';
$texto = trim($texto) . PHP_EOL;
file_put_contents($target, $texto, FILE_APPEND);
};
}

View File

@ -1,73 +1,51 @@
2024-12-12 15:38:34<hr><pre>Array
2024-12-13 22:07:35<hr><pre>Array
(
[fgId] => 7998
[fgId] => 8999
[asteriskip] =>
[logEnabled] => 1
[appdir] => C:\xampp\htdocs\hit\gitea\hitagi-entrada
[isXampp] => 1
)
</pre><br><pre>Array
(
[1] => Array
(
[id] => 1
[idmaster] => 0
[cmd] => start
[value] => 7999
)
[2] => Array
(
[id] => 2
[idmaster] => 1
[cmd] => playaudio
[value] => welcome.wav
[value2] => 2
[value3] => 1
[value4] => false
)
[3] => Array
(
[id] => 3
[idmaster] => 2
[cmd] => timeout
[value] =>
)
[4] => Array
(
[id] => 4
[idmaster] => 3
[cmd] => playaudio
[value] => timeout.wav
[value2] => 2
[value3] => 1
[value4] => false
)
)
</pre><br><pre>Array
</pre><br><hr>fgItemRun<br><pre>Array
(
[id] => 1
[idmaster] => 0
[cmd] => start
[value] => 7999
[value] => 8999
)
</pre><br><hr>fgItemRun<br><br><pre>Array
(
[id] => 1
[idmaster] => 0
[cmd] => start
[value] => 7999
)
</pre><br><hr>fgItemRun<br><br><pre>Array
</pre><br><hr>fgItemRun<br><pre>Array
(
[id] => 2
[idmaster] => 1
[cmd] => playaudio
[value] => welcome.wav
[value] => 32021341DIGITEOCPF.mp3
[value2] => 5
[value3] => 1
[value4] => false
)
</pre><br><hr>fgItemRun<br><pre>Array
(
[id] => 3
[idmaster] => 2
[cmd] => timeout
[value] =>
)
</pre><br><hr>fgItemRun<br><pre>Array
(
[id] => 4
[idmaster] => 3
[cmd] => playaudio
[value] => Agradecimento.wav
[value2] => 2
[value3] => 1
[value4] => false
)
</pre><br>
</pre><br><hr>fgItemRun<br><pre>Array
(
[id] => 5
[idmaster] => 4
[cmd] => queue
[value] => 13
[value2] => 5
)
</pre><br><hr>fgItemRunQueue<br><br>

View File

@ -1,40 +1,80 @@
2024-12-12 15:38:34
fgItemRunStart
===> fgItemRunStart <===
Array
(
[id] => 1
[idmaster] => 0
[cmd] => start
[value] => 7999
[value] => 8999
)
fgItemRunPlayaudio
===> fgItemRunPlayaudio <===
Array
(
[id] => 2
[idmaster] => 1
[cmd] => playaudio
[value] => welcome.wav
[value] => 32021341DIGITEOCPF.mp3
[value2] => 5
[value3] => 1
[value4] => false
)
===> agiRunCmd <===
SET VARIABLE AGIDIGITADO ""
200 result=1 (isXampp)
===> fgItemRunTimeout <===
Array
(
[id] => 3
[idmaster] => 2
[cmd] => timeout
[value] =>
)
===> fgItemRunPlayaudio <===
Array
(
[id] => 4
[idmaster] => 3
[cmd] => playaudio
[value] => Agradecimento.wav
[value2] => 2
[value3] => 1
[value4] => false
)
===> agiRunCmd <===
SET VARIABLE AGIDIGITADO ""
-----> EXECUTAR COMANDO SET VARIABLE AGIDIGITADO ""
digitado: 2
SET VARIABLE AGIDIGITADO 2
-----> EXECUTAR COMANDO SET VARIABLE AGIDIGITADO 2
Digitado não validado como ramal para usar "dialdigit"
Not found next icon "digit" or "dialdigit" or "digitinvalid"
200 result=1 (isXampp)
===> fgItemRunQueue <===
Array
(
[id] => 5
[idmaster] => 4
[cmd] => queue
[value] => 13
[value2] => 5
)
===> agiRunCmd <===
SET VARIABLE __AGIQUEUEID "Q13"
200 result=1 (isXampp)
===> agiRunCmd <===
SET VARIABLE __AGIQUEUENOME "SAC"
200 result=1 (isXampp)
===> agiRunCmd <===
SET VARIABLE MONITOR_FILENAME QUEUE_2024-12-13_22-07-35_20241213.220735_1138118400_8999
200 result=1 (isXampp)
===> agiRunCmd <===
SET VARIABLE __AGIRECORDNAME QUEUE_2024-12-13_22-07-35_20241213.220735_1138118400_8999
200 result=1 (isXampp)
===> agiRunCmd <===
GET FULL VARIABLE ${PJSIP_DIAL_CONTACTS(1001)}
200 result=1 (isXampp)
===> agiRunCmd <===
GET FULL VARIABLE ${PJSIP_DIAL_CONTACTS(SIP1001)}
200 result=1 (isXampp)
===> agiRunCmd <===
EXEC Dial isXampp&isXampp,30,Tt ""
200 result=1 (isXampp)
===> agiRunCmd <===
GET VARIABLE DIALSTATUS
200 result=1 (isXampp)
===> agiRunCmd <===
EXEC PLAYBACK /var/lib/asterisk/sounds/pt_BR/exten-unavail ""
200 result=1 (isXampp)

View File

@ -1,8 +0,0 @@
sonar.projectKey=my_project_key
sonar.projectName=My Project
sonar.projectVersion=1.0
sonar.sources=hitagi-entrada.php
sonar.language=php
sonar.host.url=http://localhost:9000

View File

@ -1,43 +0,0 @@
<?php
class AGIEntrada {
private $globais = array();
private $injection = array();
public function __construct($injection, $globais = array())
{
$this->globais = array();
$this->injection = $injection;
}
public function agiRunCmd ($command) {
return $this->injection['agiRunCmd']($command);
}
public function agiLog ($info) {
return $this->injection['agiLog']($info);
}
function tocarFila($queueId, $timeout) {
$this->agiRunCmd('EXEC Queue Q' . $queueId . ',ctT,,,' . 1);
}
public function run() {
$this->agiLog(
array(
'filename' => 'log.txt',
'txt' => "LOG ======> Iniciando o processamento da chamada",
)
);
// echo "LOG ======> Iniciando o processamento da chamada" . PHP_EOL;
// echo "LOG ======> Dados iniciais: " . $this->globais['initialData'] . PHP_EOL;
// $response = $this->agiRunCmd('EXEC NOOP HITAGI');
// $response = $this->agiRunCmd('ANSWER');
// $response = $this->agiRunCmd('EXEC PLAYBACK beep');
$this->globais['nomeFila'] = '10';
$response = $this->tocarFila($this->globais['nomeFila'], 1);
print_r("Retorno $response" . PHP_EOL);
}
}
?>

View File

@ -1,750 +0,0 @@
<?php
namespace Hit\Ami;
class AGIEntrada
{
private $globais = array();
private $injection = array();
public function __construct($injection, $globais = array())
{
$globais['logEnabled'] = !isset($globais['logEnabled']) ? false : $globais['logEnabled'];
$globais['appdir'] = !isset($globais['appdir']) ? dirname(__FILE__) : $globais['appdir'];
$globais['asteriskip'] = !isset($globais['asteriskip']) ? 'localhost' : $globais['asteriskip'];
$globais['isXampp'] = !isset($globais['isXampp']) ? false : $globais['isXampp'];
$this->globais = $globais;
$this->injection = $injection;
}
public function agiRunCmd($command)
{
return $this->injection['agiRunCmd']($command);
}
public function agiLog($texto, $options = array())
{
return $this->injection['agiLog']($texto, $options);
}
// --------------------------------------------------------------------------------------------------------------------------------
public function logStart()
{
if ($this->globais['logEnabled']) {
$texto = date("Y-m-d H:i:s") . "<hr>";
$target = $this->globais['appdir'] . DIRECTORY_SEPARATOR . 'log' . DIRECTORY_SEPARATOR . 'log.html';
$fp = fopen($target, 'w');
fwrite($fp, $texto);
fclose($fp);
}
}
public function logAdd($texto)
{
if ($this->globais['logEnabled']) {
$target = $this->globais['appdir'] . DIRECTORY_SEPARATOR . 'log' . DIRECTORY_SEPARATOR . 'log.html';
$fp = fopen($target, 'a');
fwrite($fp, $texto);
fclose($fp);
}
}
// --------------------------------------------------------------------------------------------------------------------------------
public function ivrGet()
{
$this->globais['fgItens'] = array();
$this->globais['fgItemStart'] = array();
if ($this->globais['fgId'] != '') {
if ($this->globais['asteriskip'] != '') {
// http://177.107.205.248/fluxograma/data-json/8999.json
$target = 'http://' . $this->globais['asteriskip'] . '/fluxograma/data-json/' . $this->globais['fgId'] . '.json';
} else {
if (file_exists('/etc/asterisk')) {
$target = '/var/www/html/fluxograma/data-json/' . $this->globais['fgId'] . '.json';
} else {
$target = 'dial/' . $this->globais['fgId'] . '.json';
}
}
$this->agiLog($target);
$itens = file_get_contents($target);
if ($itens !== false) {
$itens = json_decode($itens, true);
foreach ($itens as $item) {
$this->globais['fgItens'][$item['id']] = $item;
if ($item['cmd'] == 'start') {
$this->globais['fgItemStart'] = $item;
}
}
unset($itens);
}
}
}
// --------------------------------------------------------------------------------------------------------------------------------
public function agiVarGet($varName = '')
{
$return = '';
if ($this->globais['isXampp']) {
$return = '';
} else {
//$cmd = 'GET VARIABLE UNIQUEID'; // 200 result=1 (1695911399.249)
//$cmd = 'GET VARIABLE CALLERID(all)'; // 200 result=1 ("" <2001>)
//$cmd = 'GET VARIABLE EXTEN'; // 200 result=1 (2501)
$cmd = '';
if ($varName == 'CALLERID') {
$cmd = 'GET VARIABLE CALLERID(all)';
} else {
$cmd = 'GET VARIABLE ' . $varName;
}
$response = $this->agiRunCmd($cmd);
if ($varName == 'CALLERID') {
if (substr($response, 0, 14) == '200 result=1 (') {
$explodido = explode('<', $response);
$return = substr($explodido[1], 0, -2);
}
} else {
$explodido = explode("(", $response);
if (count($explodido) > 1) {
$explodido = explode(")", $explodido[1]);
$return = $explodido[0];
}
}
}
return $return;
}
public function agiVarSet($varName = '', $varValue = '')
{
if ($this->globais['isXampp']) {
return '';
} else {
if ($varName == 'CALLERID') {
$varName = 'CALLERID(num)';
}
$return = $this->agiRunCmd('SET VARIABLE ' . $varName . ' ' . $varValue);
return $return;
}
}
// --------------------------------------------------------------------------------------------------------------------------------
function fgItemGetChildrenFrom($fgItemFrom = array())
{
// $this->agiLog('fgItemGetChildrenFrom');
// $this->agiLog(print_r($fgItemFrom, true));
$return = array();
reset($this->globais['fgItens']);
foreach ($this->globais['fgItens'] as $fgItem) {
if ($fgItem['cmd'] != 'start') {
if ($fgItem['idmaster'] == $fgItemFrom['id']) {
$return[$fgItem['id']] = $fgItem;
}
}
}
return $return;
}
public function fgItemRun($fgItem = array())
{
// $this->agiLog('fgItemRun');
// $this->agiLog(print_r($fgItem, true) . "\n");
$this->logAdd("<hr>fgItemRun<br><br>");
$this->logAdd("<pre>" . print_r($fgItem, true) . "</pre><br>");
if (count($fgItem) > 0) {
// if ($fgItem['cmd'] == 'agi.exec') {
// fgItemRunAgiExec($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'blacklist.check') {
// fgItemRunBlacklistCheck($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'blacklist.true') {
// fgItemRunBlacklistTrue($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'blacklist.false') {
// fgItemRunBlacklistFalse($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'callerid.change') {
// fgItemRunCalleridChange($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'cnpj.check') {
// fgItemRunCNPJCheck($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'cnpj.true') {
// fgItemRunCNPJCheckTrue($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'cnpj.false') {
// fgItemRunCNPJCheckFalse($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'condtempo.check') {
// fgItemRunCondTempoCheck($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'condtempo.true') {
// fgItemRunCondTempoCheckTrue($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'condtempo.false') {
// fgItemRunCondTempoCheckFalse($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'cpf.check') {
// fgItemRunCPFCheck($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'cpf.true') {
// fgItemRunCPFCheckTrue($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'cpf.false') {
// fgItemRunCPFCheckFalse($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'dialextension') {
// fgItemRunDialExtension($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'dialgroupextension') {
// fgItemRunDialGroupExtension($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'dialplan.checkvar') {
// fgItemRunDialplanCheckvar($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'dialplan.gosub') {
// fgItemRunDialplanGosub($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'dialplan.setvar') {
// fgItemRunDialplanSetvar($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'dialdigit') {
// fgItemRunDialdigit($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'digit') {
// fgItemRunDigit($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'digitinvalid') {
// fgItemRunDigitInvalid($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'expediente.check') {
// fgItemRunExpedienteCheck($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'expediente.false') {
// fgItemRunExpedienteFalse($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'expediente.true') {
// fgItemRunExpedienteTrue($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'feriado.check') {
// fgItemRunFeriadoCheck($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'feriado.false') {
// fgItemRunFeriadoFalse($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'feriado.true') {
// fgItemRunFeriadoTrue($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'ivr.redirect') {
// fgItemRunIVRRedirect($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'nomatch') {
// fgItemRunNoMatch($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'pesqsat') {
// fgItemRunPesqSat($fgItem);
// return;
// }
if ($fgItem['cmd'] == 'playaudio') {
$this->fgItemRunPlayaudio($fgItem);
return;
}
// if ($fgItem['cmd'] == 'queue') {
// fgItemRunQueue($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'queue.waitingcount') {
// fgItemRunQueueWaitingCount($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'queue.waitingcount-greater') {
// fgItemRunQueueWaitingCountGreater($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'queue.withcallback') {
// fgItemRunQueueWithCallback($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'queue.withcallback-noready') {
// fgItemRunQueueWithCallbackNoReady($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'record') {
// fgItemRunRecord($fgItem);
// return;
// }
if ($fgItem['cmd'] == 'start') {
$this->fgItemRunStart($fgItem);
return;
}
if ($fgItem['cmd'] == 'timeout') {
$this->fgItemRunTimeout($fgItem);
return;
}
// if ($fgItem['cmd'] == 'timeoutwithlimit') {
// fgItemRunTimeoutWithLimit($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'timeoutwithlimit.limit') {
// fgItemRunTimeoutWithLimitLimit($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'voicemail') {
// fgItemRunVoicemail($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'whitelist.check') {
// fgItemRunWhitelistCheck($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'whitelist.false') {
// fgItemRunWhitelistFalse($fgItem);
// return;
// }
// if ($fgItem['cmd'] == 'whitelist.true') {
// fgItemRunWhitelistTrue($fgItem);
// return;
// }
// if (isset($fgItem['defaultvalues']['cmd'])) {
// if ($fgItem['defaultvalues']['cmd'] == 'dialplan.checkvar') {
// fgItemRunDialplanCheckvar($fgItem);
// return;
// }
// if ($fgItem['defaultvalues']['cmd'] == 'dialplan.gosub') {
// fgItemRunDialplanGosub($fgItem);
// return;
// }
// if ($fgItem['defaultvalues']['cmd'] == 'dialplan.setvar') {
// fgItemRunDialplanSetvar($fgItem);
// return;
// }
// }
}
}
function fgItemRunNextFrom($fgItemFrom = array())
{
// $this->agiLog('fgItemRunNextFrom');
// $this->agiLog(print_r($fgItemFrom, true));
$cmds_nonext = array();
$cmds_nonext[] = 'blacklist.false';
$cmds_nonext[] = 'blacklist.true';
$cmds_nonext[] = 'cnpf.false';
$cmds_nonext[] = 'cnpf.true';
$cmds_nonext[] = 'condtempo.false';
$cmds_nonext[] = 'condtempo.true';
$cmds_nonext[] = 'cpf.false';
$cmds_nonext[] = 'cpf.true';
$cmds_nonext[] = 'dialdigit';
$cmds_nonext[] = 'digit';
$cmds_nonext[] = 'expediente.false';
$cmds_nonext[] = 'expediente.true';
$cmds_nonext[] = 'feriado.false';
$cmds_nonext[] = 'feriado.true';
$cmds_nonext[] = 'nomatch';
$cmds_nonext[] = 'queue.waitingcount-greater';
$cmds_nonext[] = 'queue.withcallback-noready';
$cmds_nonext[] = 'timeout';
$cmds_nonext[] = 'timeoutwithlimit';
$cmds_nonext[] = 'timeoutwithlimit.limit';
$cmds_nonext[] = 'voicemail';
$cmds_nonext[] = 'whitelist.false';
$cmds_nonext[] = 'whitelist.true';
$run_next = true;
if (isset($fgItemFrom['idnext'])) {
if (isset($this->globais['fgItens'][$fgItemFrom['idnext']])) {
fgItemRun($this->globais['fgItens'][$fgItemFrom['idnext']]);
$run_next = false;
}
}
$fgItemChildren = $this->fgItemGetChildrenFrom($fgItemFrom);
foreach ($fgItemChildren as $fgItemChild) {
if (($run_next) && (!in_array($fgItemChild['cmd'], $cmds_nonext))) {
$this->fgItemRun($fgItemChild);
$run_next = false;
}
}
}
public function fgItemRunPlayaudio($fgItem = array())
{
$this->agiLog('===> fgItemRunPlayaudio');
$this->agiLog(print_r($fgItem, true));
$this->globais['digitado'] = '';
$cmd = 'SET VARIABLE AGIDIGITADO ""';
$this->agiLog($cmd);
$response = $this->agiRunCmd($cmd);
$this->agiLog($response);
if ($this->globais['isXampp']) {
$rnd = rand(1, 100);
if ($rnd >= 60) {
$this->globais['digitado'] = rand(0, 9);
} else if ($rnd >= 40) {
$this->globais['digitado'] = 'A';
} else if ($rnd >= 20) {
$this->globais['digitado'] = '1001';
} else {
$this->globais['digitado'] = '';
}
} else {
// Nome do arquivo sem a extensão
$explodido = explode('.', $fgItem['value']);
$audiofile = $explodido[0];
$digito_timeout = isset($fgItem['value2']) ? trim($fgItem['value2']) : 2;
$digito_timeout = !empty($digito_timeout) ? $digito_timeout : 0;
$digito_timeout = $digito_timeout * 1000; // segundos para milisegundos
$digito_qtd = isset($fgItem['value3']) ? $fgItem['value3'] : 1;
$digito_qtd = (!empty($digito_qtd)) ? $digito_qtd : '1';
// $digito_say = isset($fgItem['value4']) ? $fgItem['value4'] : 'false';
$cmd = 'GET DATA /var/lib/asterisk/sounds/cliente/' . $audiofile . ' ' . $digito_timeout . ' ' . $digito_qtd;
$this->agiLog($cmd);
$response = $this->agiRunCmd($cmd);
$this->agiLog($response);
// 200 result= (timeout)
// 200 result=4 (timeout)
if (strpos($response, '= (timeout)') === false) {
if (strpos($response, '(timeout)') !== false) {
$response = trim(str_replace('(timeout)', '', $response));
}
$explodido = explode('=', $response);
$this->globais['digitado'] = $explodido[1];
}
}
$this->agiLog("digitado: " . $this->globais['digitado']);
$run_next = true;
if ($this->globais['digitado'] == '') {
$fgItemChildren = $this->fgItemGetChildrenFrom($fgItem);
foreach ($fgItemChildren as $fgItemChild) {
if ($run_next) {
if ($fgItemChild['cmd'] == 'timeoutwithlimit') {
$this->fgItemRun($fgItemChild);
$run_next = false;
}
}
}
$fgItemChildren = $this->fgItemGetChildrenFrom($fgItem);
foreach ($fgItemChildren as $fgItemChild) {
if ($run_next) {
if ($fgItemChild['cmd'] == 'timeout') {
$this->fgItemRun($fgItemChild);
$run_next = false;
}
}
}
if ($run_next) {
$this->agiLog('Not found next icon "timeoutwithlimit" or "timeout"');
$this->agiLog('Goto next icon if exists...');
$this->fgItemRunNextFrom($fgItem);
}
$run_next = false;
} else {
$cmd = 'SET VARIABLE AGIDIGITADO ' . $this->globais['digitado'];
$this->agiLog($cmd);
$response = $this->agiRunCmd($cmd);
$this->agiLog($response);
$cmd = 'EXEC QUEUELOG NONE,' . $this->globais['uniqueid'] . ',NONE,INFO|IVRAPPEND|->' . $this->globais['digitado'];
$response = $this->agiRunCmd($cmd);
}
if ($run_next) {
$fgItemChildren = $this->fgItemGetChildrenFrom($fgItem);
foreach ($fgItemChildren as $fgItemChild) {
if ($run_next) {
if ($fgItemChild['cmd'] == 'digit') {
if ($fgItemChild['value'] == $this->globais['digitado']) {
$this->fgItemRun($fgItemChild);
$run_next = false;
}
}
}
}
}
if ($run_next) {
$tamanho = strlen($this->globais['digitado']);
if (($tamanho >= 3) && ($tamanho <= 4)) {
$fgItemChildren = $this->fgItemGetChildrenFrom($fgItem);
foreach ($fgItemChildren as $fgItemChild) {
if ($run_next) {
if ($fgItemChild['cmd'] == 'dialdigit') {
$this->fgItemRun($fgItemChild);
$run_next = false;
}
}
}
} else {
$this->agiLog('Digitado não validado como ramal para usar "dialdigit"');
}
}
if ($run_next) {
$fgItemChildren = $this->fgItemGetChildrenFrom($fgItem);
foreach ($fgItemChildren as $fgItemChild) {
if ($run_next) {
if ($fgItemChild['cmd'] == 'digitinvalid') {
$this->fgItemRun($fgItemChild);
$run_next = false;
}
}
}
}
if ($run_next) {
$this->agiLog('Not found next icon "digit" or "dialdigit" or "digitinvalid"');
$this->fgItemRunNextFrom($fgItem);
}
}
function fgItemRunStart($fgItem = array())
{
$this->agiLog('===> fgItemRunStart');
$this->agiLog(print_r($fgItem, true));
// queue_log
// 1353461650|1353461627.33271|NONE|NONE|INFO|IVRSTART|1234|5556777
// QueueLog(queuename,uniqueid,agent,event,[additionalinfo])
// $cmd = 'EXEC QUEUELOG NONE,' . $GLOBALS['uniqueid'] . ',NONE,NONE,INFO|IVRSTART|' . $GLOBALS['callerid'] . '|' . $GLOBALS['fgId'];
// ...
$this->fgItemRunNextFrom($fgItem);
}
function fgItemRunTimeout($fgItem = array())
{
$this->agiLog('===> fgItemRunTimeout');
$this->agiLog(print_r($fgItem, true));
$run_next = true;
$fgItemChildren = $this->fgItemGetChildrenFrom($fgItem);
foreach ($fgItemChildren as $fgItemChild) {
if ($run_next) {
if ($fgItemChild['cmd'] == 'voicemail') {
$this->agiLog('Found icon "voicemail"');
$this->fgItemRun($fgItemChild);
$run_next = false;
}
}
}
if ($run_next) {
$this->fgItemRunNextFrom($fgItem);
}
}
public function teste()
{
$this->agiLog($this->globais['fgId']);
}
function tocarFila($queueId, $timeout)
{
return $this->agiRunCmd('EXEC Queue Q' . $queueId . ',ctT,,,' . $timeout);
}
// --------------------------------------------------------------------------------------------------------------------------------
public function run()
{
$this->agiLog(date("Y-m-d H:i:s"), array('new' => true));
$this->logStart();
$this->logAdd("<pre>" . print_r($this->globais, true) . "</pre><br>");
$this->ivrGet();
$this->logAdd("<pre>" . print_r($this->globais['fgItens'], true) . "</pre><br>");
$this->logAdd("<pre>" . print_r($this->globais['fgItemStart'], true) . "</pre><br>");
if (count($this->globais['fgItemStart']) > 0) {
$this->globais['arrDtmf'] = array(
'35' => '#',
'42' => '*',
'48' => '0',
'49' => '1',
'50' => '2',
'51' => '3',
'52' => '4',
'53' => '5',
'54' => '6',
'55' => '7',
'56' => '8',
'57' => '9'
);
if ($this->globais['isXampp']) {
$this->globais['callerid'] = '1138118400';
$this->globais['uniqueid'] = date("Ymd") . "." . date("His");
$this->globais['digitado'] = '';
$host = 'localhost';
$user = 'root';
$password = '';
$database = 'hitpbx_homologacao';
$port = '3306';
$this->globais['db'] = mysqli_connect($host, $user, $password, $database, $port) or die('Erro de conexão com o banco de dados');
mysqli_set_charset($this->globais['db'], 'utf8');
$this->fgItemRun($this->globais['fgItemStart']);
} else {
$host = '172.31.187.152';
$user = 'appuser';
$password = 'nmvP$x23Vzb@T%Su';
$hostname = gethostname();
$hostname = str_replace('hitpbx-', 'hitpbx_', $hostname);
$database = $hostname;
if ($hostname == 'hitpbx-001') {
$database = 'hitpbx-001';
}
$port = '6033';
$this->globais['db'] = mysqli_connect($host, $user, $password, $database, $port) or die('Erro de conexão com o banco de dados');
mysqli_set_charset($this->globais['db'], 'utf8');
/*
logAdd("111<br>");
$query = "SELECT * FROM tab_ramal LIMIT 1";
$result = mysqli_query($db,$query);
logAdd($query."<br>");
$result = mysqli_query($this->globais['db'],$query);
logAdd($query."<br>");
*/
// ...
/*
$host = '172.31.187.150';
$dbcdr = mysqli_connect($host, $user, $password, $database, $port) or die('Erro de conexão com o banco de dados');
mysqli_set_charset($dbcdr, 'utf8');
$query = "
CREATE TABLE IF NOT EXISTS tab_ivr_log2 (
`id` INT NOT NULL AUTO_INCREMENT,
`uniqueid` VARCHAR(32) NOT NULL,
`did` TEXT NULL,
`quando` DATETIME NULL,
`fgitem_json` TEXT NULL,
`fgitem_result` TEXT NULL,
PRIMARY KEY (`id`))
ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8;
";
$result = mysqli_query($dbcdr,$query);
*/
// ...
$response = $this->agiRunCmd('EXEC NOOP HITAGI');
$response = $this->agiRunCmd('ANSWER');
$response = $this->agiRunCmd('EXEC WAIT 1');
$response = $this->agiRunCmd('EXEC PLAYBACK beep');
$response = $this->agiRunCmd('EXEC WAIT 1');
$this->globais['digitado'] = '';
$this->globais['callerid'] = $this->agiVarGet('CALLERID');
$this->globais['uniqueid'] = $this->agiVarGet('UNIQUEID');
$response = $this->agiVarSet('AGIDID', $this->globais['fgId']);
$cmd = 'EXEC QUEUELOG NONE,' . $this->globais['uniqueid'] . ',NONE,INFO|IVRSTART';
$response = $this->agiRunCmd($cmd);
$cmd = 'EXEC QUEUELOG NONE,' . $this->globais['uniqueid'] . ',NONE,INFO|IVRAPPEND|->' . $this->globais['fgId'];
$response = $this->agiRunCmd($cmd);
$this->fgItemRun($this->globais['fgItemStart']);
// 1353461660|1353461627.33271|NONE|NONE|INFO|IVRHANGUP|
//$cmd = 'EXEC QUEUELOG NONE,' . $GLOBALS['uniqueid'] . ',NONE,NONE,INFO|IVRHANGUP';
//$response = agiRunCmd($cmd);
// $response = agiRunCmd('HANGUP');
}
}
/*
$this->teste();
$this->globais['nomeFila'] = '10';
$response = $this->tocarFila($this->globais['nomeFila'], 1);
echo "\n" . $response . "\n";
*/
}
}

View File

@ -1 +0,0 @@
=>

2
vendor/autoload.php vendored
View File

@ -4,4 +4,4 @@
require_once __DIR__ . '/composer/autoload_real.php';
return ComposerAutoloaderInit7cccddac512163c6eaa2449701d7945d::getLoader();
return ComposerAutoloaderInit6629c2e9a27a691df05b9e008a8437de::getLoader();

View File

@ -12,7 +12,7 @@ return array(
'Psr\\Http\\Message\\' => array($vendorDir . '/psr/http-factory/src', $vendorDir . '/psr/http-message/src'),
'Psr\\Http\\Client\\' => array($vendorDir . '/psr/http-client/src'),
'PhpOption\\' => array($vendorDir . '/phpoption/phpoption/src/PhpOption'),
'Hit\\Ami\\' => array($baseDir . '/src'),
'Hitlabs\\Hitagi\\' => array($baseDir . '/classes'),
'GuzzleHttp\\Psr7\\' => array($vendorDir . '/guzzlehttp/psr7/src'),
'GuzzleHttp\\Promise\\' => array($vendorDir . '/guzzlehttp/promises/src'),
'GuzzleHttp\\' => array($vendorDir . '/guzzlehttp/guzzle/src'),

View File

@ -2,7 +2,7 @@
// autoload_real.php @generated by Composer
class ComposerAutoloaderInit7cccddac512163c6eaa2449701d7945d
class ComposerAutoloaderInit6629c2e9a27a691df05b9e008a8437de
{
private static $loader;
@ -24,15 +24,15 @@ class ComposerAutoloaderInit7cccddac512163c6eaa2449701d7945d
require __DIR__ . '/platform_check.php';
spl_autoload_register(array('ComposerAutoloaderInit7cccddac512163c6eaa2449701d7945d', 'loadClassLoader'), true, true);
spl_autoload_register(array('ComposerAutoloaderInit6629c2e9a27a691df05b9e008a8437de', 'loadClassLoader'), true, true);
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
spl_autoload_unregister(array('ComposerAutoloaderInit7cccddac512163c6eaa2449701d7945d', 'loadClassLoader'));
spl_autoload_unregister(array('ComposerAutoloaderInit6629c2e9a27a691df05b9e008a8437de', 'loadClassLoader'));
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
if ($useStaticLoader) {
require __DIR__ . '/autoload_static.php';
call_user_func(\Composer\Autoload\ComposerStaticInit7cccddac512163c6eaa2449701d7945d::getInitializer($loader));
call_user_func(\Composer\Autoload\ComposerStaticInit6629c2e9a27a691df05b9e008a8437de::getInitializer($loader));
} else {
$map = require __DIR__ . '/autoload_namespaces.php';
foreach ($map as $namespace => $path) {
@ -53,12 +53,12 @@ class ComposerAutoloaderInit7cccddac512163c6eaa2449701d7945d
$loader->register(true);
if ($useStaticLoader) {
$includeFiles = Composer\Autoload\ComposerStaticInit7cccddac512163c6eaa2449701d7945d::$files;
$includeFiles = Composer\Autoload\ComposerStaticInit6629c2e9a27a691df05b9e008a8437de::$files;
} else {
$includeFiles = require __DIR__ . '/autoload_files.php';
}
foreach ($includeFiles as $fileIdentifier => $file) {
composerRequire7cccddac512163c6eaa2449701d7945d($fileIdentifier, $file);
composerRequire6629c2e9a27a691df05b9e008a8437de($fileIdentifier, $file);
}
return $loader;
@ -70,7 +70,7 @@ class ComposerAutoloaderInit7cccddac512163c6eaa2449701d7945d
* @param string $file
* @return void
*/
function composerRequire7cccddac512163c6eaa2449701d7945d($fileIdentifier, $file)
function composerRequire6629c2e9a27a691df05b9e008a8437de($fileIdentifier, $file)
{
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

View File

@ -4,7 +4,7 @@
namespace Composer\Autoload;
class ComposerStaticInit7cccddac512163c6eaa2449701d7945d
class ComposerStaticInit6629c2e9a27a691df05b9e008a8437de
{
public static $files = array (
'7b11c4dc42b3b3023073cb14e519683c' => __DIR__ . '/..' . '/ralouphie/getallheaders/src/getallheaders.php',
@ -30,7 +30,7 @@ class ComposerStaticInit7cccddac512163c6eaa2449701d7945d
),
'H' =>
array (
'Hit\\Ami\\' => 8,
'Hitlabs\\Hitagi\\' => 15,
),
'G' =>
array (
@ -75,9 +75,9 @@ class ComposerStaticInit7cccddac512163c6eaa2449701d7945d
array (
0 => __DIR__ . '/..' . '/phpoption/phpoption/src/PhpOption',
),
'Hit\\Ami\\' =>
'Hitlabs\\Hitagi\\' =>
array (
0 => __DIR__ . '/../..' . '/src',
0 => __DIR__ . '/../..' . '/classes',
),
'GuzzleHttp\\Psr7\\' =>
array (
@ -117,9 +117,9 @@ class ComposerStaticInit7cccddac512163c6eaa2449701d7945d
public static function getInitializer(ClassLoader $loader)
{
return \Closure::bind(function () use ($loader) {
$loader->prefixLengthsPsr4 = ComposerStaticInit7cccddac512163c6eaa2449701d7945d::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit7cccddac512163c6eaa2449701d7945d::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit7cccddac512163c6eaa2449701d7945d::$classMap;
$loader->prefixLengthsPsr4 = ComposerStaticInit6629c2e9a27a691df05b9e008a8437de::$prefixLengthsPsr4;
$loader->prefixDirsPsr4 = ComposerStaticInit6629c2e9a27a691df05b9e008a8437de::$prefixDirsPsr4;
$loader->classMap = ComposerStaticInit6629c2e9a27a691df05b9e008a8437de::$classMap;
}, null, ClassLoader::class);
}

View File

@ -2,11 +2,11 @@
'root' => array(
'pretty_version' => '1.0.0+no-version-set',
'version' => '1.0.0.0',
'type' => 'library',
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'reference' => NULL,
'name' => 'hit/ami',
'name' => 'hitlabs/hitagi',
'dev' => true,
),
'versions' => array(
@ -55,10 +55,10 @@
'reference' => 'a70f5c95fb43bc83f07c9c948baa0dc1829bf201',
'dev_requirement' => false,
),
'hit/ami' => array(
'hitlabs/hitagi' => array(
'pretty_version' => '1.0.0+no-version-set',
'version' => '1.0.0.0',
'type' => 'library',
'type' => 'project',
'install_path' => __DIR__ . '/../../',
'aliases' => array(),
'reference' => NULL,