diff --git a/asterisk/var_lib_asterisk/scripts/integracao/abdAgi.php b/asterisk/var_lib_asterisk/scripts/integracao/abdAgi.php
index 6247f0f..fea5718 100755
--- a/asterisk/var_lib_asterisk/scripts/integracao/abdAgi.php
+++ b/asterisk/var_lib_asterisk/scripts/integracao/abdAgi.php
@@ -449,7 +449,7 @@ if ($agi->get_variable('MEMBERINTERFACE', true) || $evento == 'ABANDON') {
$query = "SELECT itgm_id FROM pbx_integracao_reg a, pbx_integracao_metodo b WHERE b.itgm_id_pai = a.reg_id_metodo AND b.evento = 2 AND a.reg_uniqueid = '{$arg1}'";
$result = pg_query($query);
$idMetodo = pg_fetch_assoc($result)['itgm_id'];
-
+ $nomeMetodo = '';
$pathIntegra = "/var/lib/asterisk/scripts/integracao/custom/";
if ($idMetodo && ExecuteCustom($idMetodo, $nomeMetodo)) {
diff --git a/include/util/funcoesApl.php b/include/util/funcoesApl.php
index e29b0bd..ccbb5cd 100755
--- a/include/util/funcoesApl.php
+++ b/include/util/funcoesApl.php
@@ -396,7 +396,8 @@ function VerificaCadastroMenu($conn) {
if (UseModVendas()) {
$menuUsuario[] = array('215', 'mnDashboard', '1', 'Dashboard ' . MenuVendas(), 'index.php?idProg=358', '', '173', '1', '0', '', '358');
}
-
+
+ $menuUsuario[] = array('214', 'mnSimplesChat', '1', 'ChannelChat', 'index.php?idProg=355', '', '1', '1', '0', '', '355');
$menuUsuario[] = array('217', 'mnSimplesChatAdm', '0', 'Administrador SimplesChat', 'index.php?idProg=359', '', '1', '1', '0', '', '359');
$menuUsuario[] = array('218', 'mnSimplesChatSup', '0', 'Supervisor SimplesChat', 'index.php?idProg=360', '', '1', '1', '0', '', '360');
$menuUsuario[] = array('219', 'mnSimplesChatAgt', '0', 'Agente SimplesChat', 'index.php?idProg=361', '', '1', '1', '0', '', '361');
diff --git a/integracao/simpleschat/connect.php b/integracao/simpleschat/connect.php
index 929b4f9..ba476c7 100644
--- a/integracao/simpleschat/connect.php
+++ b/integracao/simpleschat/connect.php
@@ -1,60 +1,130 @@
encrypt($jsoninfo);
- $jsStartup[] = sprintf('window.open("%s", "popupWindow", "width=1450, height=950, resizable=NO,scrollbars=YES");', $url);
- } else {
- $jsStartup[] = "alert('Não foi possível conenctar ao Simples Chat! Verifique as informações antes de conectar.');";
- }
- }
-
- $smarty->assign("options", getQueue($chatApi));
- $smarty->assign("jsonApp", json_encode(
- [
- 'matricula' => GetMatricula(),
- 'server_api' => $_SESSION['prm_chat_api'],
- 'server_ws' => $_SESSION['prm_sk_host_chat'],
- 'supervisor' => IsSupervisor($dbcon)
- ]
- ));
-
- GetTemplate($smarty, 'simpleschat/connect.tpl');
-
- function getQueue($chatApi) {
- $response = json_decode(request("{$chatApi}/integracao/media/api/agente/listarFilas"));
- $option = null;
- foreach ($response->data as $v) {
- $option .= "";
- }
- return $option;
- }
-
- function loginQueue($chatApi, $dac) {
- $json = ['id_fila' => $dac, "matricula" => GetMatricula()];
- $response = json_decode(request("{$chatApi}/integracao/media/api/agente/entrar", $json));
- if ($response->status == 'success' || strpos($response->message, 'autenticado') !== false) {
- return true;
- }
+ $numbers = number($chatApi, $_SESSION['SSTokenChat']);
+ $info = [
+ "token" => $_SESSION['SSTokenChat'],
+ "id_number" => $numbers[0]['id'],
+ "id_empresa" => $numbers[0]['id_empresa'],
+ "servidor" => $_SESSION['prm_chat_api'],
+ "websocket" => $_SESSION['prm_sk_host_chat'],
+ "matricula" => $matricula,
+ "fila" => $request['selectqueue'],
+ "expire" => strtotime('+1 days', time())
+ ];
+
+ $token = $crypt->encrypt(json_encode($info, true));
+ $url = $chatApi . ":8001/index.php?t=" . $token;
+ $jsStartup[] = sprintf('window.open("%s", "popupWindow", "width=1450, height=950, resizable=NO,scrollbars=YES");', $url);
+ }
+} catch (Exception $ex) {
+ $jsStartup[] = sprintf("alert('%s')", $ex->getMessage());
+}
+
+$smarty->assign("options", $options);
+$smarty->assign("jsonApp", json_encode(
+ [
+ 'matricula' => GetMatricula(),
+ 'server_api' => $_SESSION['prm_chat_api'],
+ 'server_ws' => $_SESSION['prm_sk_host_chat'],
+ 'supervisor' => IsSupervisor($dbcon)
+ ]
+));
+
+GetTemplate($smarty, 'simpleschat/connect.tpl');
+
+function number($chatApi, $token)
+{
+ $response = curl("{$chatApi}/api/v1/number", null, $token);
+ if (!$response['data']) {
+ throw new Exception('Não foi encontrar os números.');
+ }
+ return $response['data'];
+}
+
+function queues($chatApi, $token)
+{
+ $response = curl("{$chatApi}/api/v1/filas", null, $token);
+ $option = null;
+
+ if (!$response['data']) {
+ throw new Exception('Não foi possível listar as filas.');
+ }
+
+ foreach ($response['data'] as $v) {
+ $option .= "";
+ }
+ return $option;
+}
+
+function login($chatApi, $email)
+{
+ $json = json_encode(['email' => $email, "matricula" => md5(GetMatricula())]);
+ $response = curl("{$chatApi}/access/login", $json);
+
+ if ($response['status'] == 'success' || strpos($response['message'], 'autenticado') !== false) {
+ return $response['data']['token'];
+ }
+ throw new Exception('Não foi possível gerar o token.');
+}
+
+function curl($url, $params = null, $token = null)
+{
+ $curl = curl_init();
+ curl_setopt($curl, CURLOPT_URL, $url);
+ curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
+ curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
+
+ if ($params) {
+ curl_setopt($curl, CURLOPT_POST, true);
+ curl_setopt($curl, CURLOPT_POSTFIELDS, $params);
+ }
+
+ curl_setopt($curl, CURLOPT_TIMEOUT, 30);
+
+ $header[] = 'Content-Type:application/json';
+ if ($token) {
+ $header[] = 'Authorization: Bearer ' . $token;
+ }
+
+ curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
+ $content = curl_exec($curl);
+ if (curl_errno($curl)) {
+ curl_close($curl);
return false;
}
+ $info = curl_getinfo($curl);
+
+ if ($info['http_code'] == 403) {
+ unset($_SESSION['SSTokenChat']);
+ }
+ curl_close($curl);
- function request($url, $post = []) {
- $curl = "curl -s -k ";
- if ($post) {
- $curl .= sprintf(" -X POST -d '%s' ", json_encode($post));
- }
- $curl .= $url;
+ return json_decode($content, true);
+}
- $response = shell_exec($curl);
- return $response;
- }
\ No newline at end of file
+function getEmailAgente($dbcon, $matricula)
+{
+ $query = "SELECT email FROM pbx_usuarios WHERE matricula = '$matricula';";
+ $result = pg_query($dbcon, $query);
+ return pg_fetch_assoc($result);
+}