|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
/** |
|
|
|
|
* EVENTOS GERADOS PELO USUARIO DA APLICACAO |
|
|
|
|
*/ |
|
|
|
|
$(function(){ |
|
|
|
|
$(function () { |
|
|
|
|
connect(ws) |
|
|
|
|
notifications() |
|
|
|
|
/** |
|
|
|
@ -18,7 +18,7 @@ $(function(){
|
|
|
|
|
/** FIM VOICE RECORDER */ |
|
|
|
|
|
|
|
|
|
/** EVENTOS DE CLICK NO BODY */ |
|
|
|
|
$("body").mouseup(function(){
|
|
|
|
|
$("body").mouseup(function () { |
|
|
|
|
$('#uploadfiles').fadeOut('slow') |
|
|
|
|
}); |
|
|
|
|
|
|
|
|
@ -34,33 +34,33 @@ $(function(){
|
|
|
|
|
startChannelMessage() |
|
|
|
|
|
|
|
|
|
/** INICIA O CHAT NO FINAL DA CONVERSA */ |
|
|
|
|
$('.chats').on('click', function(){ |
|
|
|
|
$('.chats').on('click', function () { |
|
|
|
|
scrollDown() |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** ENVIA AS MSG PELO ENTER */ |
|
|
|
|
$('#fieldsendmessage').bind('keyup', function(ev){ |
|
|
|
|
if(ev.keyCode == 13 && $(this).val().trim().length > 0){ |
|
|
|
|
$('#fieldsendmessage').bind('keyup', function (ev) { |
|
|
|
|
if (ev.keyCode == 13 && $(this).val().trim().length > 0) { |
|
|
|
|
sendMessage() |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
$('#fieldsendmessage').on('keyup', () => { |
|
|
|
|
if($(this).val().trim().length == 0){ |
|
|
|
|
if ($(this).val().trim().length == 0) { |
|
|
|
|
$(this).val('') |
|
|
|
|
} |
|
|
|
|
resizeSendMsg() |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
$('.type-message-bar-right').on('click',() => { |
|
|
|
|
$('.type-message-bar-right').on('click', () => { |
|
|
|
|
sendMessage() |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
$('#imgclip').on('click', function(){ |
|
|
|
|
$('#imgclip').on('click', function () { |
|
|
|
|
modalStart() |
|
|
|
|
$("#uploadimage").val('') |
|
|
|
|
$('#uploadfile').val('') |
|
|
|
|
if($('#uploadfiles').is(':hidden')){ |
|
|
|
|
if ($('#uploadfiles').is(':hidden')) { |
|
|
|
|
$('#uploadfiles').fadeIn('slow') |
|
|
|
|
} else { |
|
|
|
|
$('#uploadfiles').fadeOut('slow') |
|
|
|
@ -69,10 +69,10 @@ $(function(){
|
|
|
|
|
|
|
|
|
|
$('#footer-content-right').on('click', '#footersend', () => { |
|
|
|
|
sendMedia(mediaRecorder) |
|
|
|
|
$('#modalselect').css({display: 'none'}) |
|
|
|
|
$('#modalselect').css({ display: 'none' }) |
|
|
|
|
}) |
|
|
|
|
supervisorAgente() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -82,7 +82,7 @@ $(function(){
|
|
|
|
|
const selectNotification = (id) => { |
|
|
|
|
marcarMensagemVista(id) |
|
|
|
|
|
|
|
|
|
listaMensagem(id).then(() => { |
|
|
|
|
listaMensagem(id).then(async () => { |
|
|
|
|
let uniqueid |
|
|
|
|
let number |
|
|
|
|
let name |
|
|
|
@ -90,41 +90,35 @@ const selectNotification = (id) => {
|
|
|
|
|
let protocolo |
|
|
|
|
|
|
|
|
|
const dataRequest = JSON.parse(localStorage.getItem('obj_contact')) |
|
|
|
|
<<<<<<< HEAD |
|
|
|
|
|
|
|
|
|
listarAtendimentoAgente(localStorage.getItem('my_uniqueid')) |
|
|
|
|
======= |
|
|
|
|
listarAtendimentoAgente(localStorage.getItem('id_empresa'), localStorage.getItem('my_uniqueid')) |
|
|
|
|
>>>>>>> 1e181ff (ajustes de funcionalidades) |
|
|
|
|
const allNotifications = JSON.parse(localStorage.getItem('obj_notification')) |
|
|
|
|
const atendimentos = await buscarAtendimento(id); |
|
|
|
|
|
|
|
|
|
console.log(allNotifications) |
|
|
|
|
|
|
|
|
|
hideButtons(false) |
|
|
|
|
allNotifications.data.forEach(e => { |
|
|
|
|
$('#' + e.uniqueid.replace('.', `\\.`)).removeClass('select-notification') |
|
|
|
|
if(e.uniqueid == id && e.status == 0){ |
|
|
|
|
if (e.uniqueid == id && e.status == 0) { |
|
|
|
|
hideButtons(true) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
$('#' + id.replace('.', `\\.`)).addClass('select-notification') |
|
|
|
|
|
|
|
|
|
allNotifications.data.forEach(e => { |
|
|
|
|
if(e.uniqueid == id && e.status == 0){ |
|
|
|
|
if (e.uniqueid == id && e.status == 0) { |
|
|
|
|
hideButtons(true) |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
if(dataRequest.data.length > 0){ |
|
|
|
|
if (dataRequest.data.length > 0) { |
|
|
|
|
dataContact = dataRequest.data.filter(e => { |
|
|
|
|
if(id.trim() == e.uniqueid){ |
|
|
|
|
if (id.trim() == e.uniqueid) { |
|
|
|
|
return true |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
allNotifications.data.forEach(e => { |
|
|
|
|
if(id === e.uniqueid){ |
|
|
|
|
if (id === e.uniqueid) { |
|
|
|
|
uniqueid = e.uniqueid |
|
|
|
|
name = e.nome |
|
|
|
|
number = e.cliente_id |
|
|
|
@ -136,25 +130,21 @@ const selectNotification = (id) => {
|
|
|
|
|
localStorage.removeItem('session_uniqueid') |
|
|
|
|
localStorage.setItem('session_uniqueid', uniqueid) |
|
|
|
|
localStorage.setItem('session_window', number) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$('.chat-window-contact-name').text(name) |
|
|
|
|
$('.chat-window-contact-status').text('Protocolo: ' + protocolo) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** REMOVE AS MSG NA E CONSTRIO A TELA NOVAMENTE (EVITAR DUPLICAR) */ |
|
|
|
|
$('.chat-window .sender').remove() |
|
|
|
|
$('.chat-window .receiver').remove() |
|
|
|
|
$('.chat-window .events').remove() |
|
|
|
|
alertNotification(localStorage.getItem('session_uniqueid'),'remove') |
|
|
|
|
alertNotification(localStorage.getItem('session_uniqueid'), 'remove') |
|
|
|
|
|
|
|
|
|
dataContact.forEach(e => { |
|
|
|
|
dataContact.forEach((e) => { |
|
|
|
|
const datesend = e.msg_date ? converdata(new Date(e.msg_date).getTime()) : 'algumas horas'; |
|
|
|
|
<<<<<<< HEAD |
|
|
|
|
let typesend = localStorage.getItem('my_uniqueid') == e.src ? 'sender': 'receiver' |
|
|
|
|
======= |
|
|
|
|
let typesend = localStorage.getItem('my_uniqueid') == e.dst ? 'receiver' : 'sender' |
|
|
|
|
>>>>>>> 1e181ff (ajustes de funcionalidades) |
|
|
|
|
let typesend = atendimentos.data[0].cliente_id == e.dst ? 'sender' : 'receiver' |
|
|
|
|
|
|
|
|
|
if(e.type == 'text'){ |
|
|
|
|
if (e.type == 'text') { |
|
|
|
|
$('.chat-window').append(` |
|
|
|
|
<div class="${typesend}"> |
|
|
|
|
<span class="${typesend}-message">${e.content}</span> |
|
|
|
@ -164,7 +154,14 @@ const selectNotification = (id) => {
|
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(e.type == 'finish' || e.type == 're_start'){ |
|
|
|
|
if (e.type == 'transfer') { |
|
|
|
|
$('.chat-window').append(` |
|
|
|
|
<div class="events"> |
|
|
|
|
<span class="events-message">${e.content} por ${e.profile_name}, ${datesend}.</span> |
|
|
|
|
</div>`) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (e.type == 'finish' || e.type == 're_start') { |
|
|
|
|
$('.chat-window').append(` |
|
|
|
|
<div class="events"> |
|
|
|
|
<span class="events-message">${e.content}</span> |
|
|
|
@ -172,39 +169,37 @@ const selectNotification = (id) => {
|
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(e.type != 'text'){ |
|
|
|
|
if (e.type != 'text') { |
|
|
|
|
const sendobj = { |
|
|
|
|
filename: e.file_name, |
|
|
|
|
id_provedor: e.id_provedor,
|
|
|
|
|
type: e.type,
|
|
|
|
|
mimetype: e.mimetype,
|
|
|
|
|
id_provedor: e.id_provedor, |
|
|
|
|
type: e.type, |
|
|
|
|
mimetype: e.mimetype, |
|
|
|
|
from: typesend |
|
|
|
|
} |
|
|
|
|
messageTypeMedia(sendobj) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(e.de == localStorage.getItem('my_uniqueid')){ |
|
|
|
|
|
|
|
|
|
if (e.de == localStorage.getItem('my_uniqueid')) { |
|
|
|
|
const datereceived = e.datetime ? converdata(e.datetime) : 'algumas horas'; |
|
|
|
|
if(e.type == 'text'){ |
|
|
|
|
if (e.type == 'text') { |
|
|
|
|
$('.chat-window').append(` |
|
|
|
|
<div class="${typesend}"> |
|
|
|
|
<span class="${typesend}-message">${e.msg}</span> |
|
|
|
|
<br/> |
|
|
|
|
<span class="message-time">${datereceived}</span> |
|
|
|
|
</div>`) |
|
|
|
|
} else if (e.type == 'audio' || e.type == 'voice'){ |
|
|
|
|
const audio = `<audio controls>
|
|
|
|
|
<source src="data:audio/mpeg;base64,${e.msg}"></source> |
|
|
|
|
</audio>` |
|
|
|
|
} else if (e.type == 'audio' || e.type == 'voice') { |
|
|
|
|
const audio = `<audio controls><source src="data:audio/mpeg;base64,${e.msg}"></source></audio>` |
|
|
|
|
$('.chat-window').append(` |
|
|
|
|
<div class="${typesend}"> |
|
|
|
|
<span class="${typesend}-message">${audio}</span> |
|
|
|
|
<br/> |
|
|
|
|
<span class="message-time">${datereceived}</span> |
|
|
|
|
</div>`) |
|
|
|
|
} else if (e.type == 'document'){ |
|
|
|
|
} else if (e.type == 'document') { |
|
|
|
|
icontypes.forEach(l => { |
|
|
|
|
if(e.filename.indexOf(l) >= 0){ |
|
|
|
|
if (e.filename.indexOf(l) >= 0) { |
|
|
|
|
$('.chat-window').append(` |
|
|
|
|
<div class="${typesend}"> |
|
|
|
|
<span class="${typesend}-message message-column"> |
|
|
|
@ -216,9 +211,9 @@ const selectNotification = (id) => {
|
|
|
|
|
<br/> |
|
|
|
|
<span class="message-time">${datereceived}</span> |
|
|
|
|
</div>`) |
|
|
|
|
}
|
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
} else if (e.type == 'image'){ |
|
|
|
|
} else if (e.type == 'image') { |
|
|
|
|
const fileimg = `data:${e.mimetype};base64,` + e.msg |
|
|
|
|
$('.chat-window').append(` |
|
|
|
|
<div class="${typesend}"> |
|
|
|
@ -252,7 +247,7 @@ const sendMessage = (obj = {}) => {
|
|
|
|
|
let mimetype = obj.mimetype ? obj.mimetype : 'text' |
|
|
|
|
let filename = obj.filename ? obj.filename : Date.now() |
|
|
|
|
|
|
|
|
|
if(!sendContent){ |
|
|
|
|
if (!sendContent) { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -277,12 +272,12 @@ const sendMessage = (obj = {}) => {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(type != 'audio'){ |
|
|
|
|
if (type != 'audio') { |
|
|
|
|
dataSend.event.mensagem.file_name = filename |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
enviarMensagem(dataSend) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let msgContent = type == 'text' ? sendContent : obj.fileContent |
|
|
|
|
$('.chat-window').append(` |
|
|
|
|
<div class="sender"> |
|
|
|
@ -305,9 +300,9 @@ const viewMessage = (ev) => {
|
|
|
|
|
const sessionOpen = localStorage.getItem('session_uniqueid') |
|
|
|
|
const datesend = ev.event?.mensagem.datetime ? converdata(ev.event?.mensagem.datetime, true) : 'algumas horas'; |
|
|
|
|
|
|
|
|
|
if(ev.event?.mensagem.uniqueid == sessionOpen){ |
|
|
|
|
if (ev.event?.mensagem.uniqueid == sessionOpen) { |
|
|
|
|
marcarMensagemVista(sessionOpen) |
|
|
|
|
switch(ev.event?.mensagem.type){ |
|
|
|
|
switch (ev.event?.mensagem.type) { |
|
|
|
|
case 'text': |
|
|
|
|
$('.chat-window').append(` |
|
|
|
|
<div class="receiver"> |
|
|
|
@ -326,12 +321,12 @@ const viewMessage = (ev) => {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const mediaDownload = ["image", "voice", "document", "audio", "video", "sticker"] |
|
|
|
|
if(mediaDownload.indexOf(ev.event?.mensagem.type) >= 0){ |
|
|
|
|
if (mediaDownload.indexOf(ev.event?.mensagem.type) >= 0) { |
|
|
|
|
const sendobj = { |
|
|
|
|
filename: ev.event?.mensagem.file_name, |
|
|
|
|
id_provedor: ev.event?.mensagem.id_provedor,
|
|
|
|
|
type: ev.event?.mensagem.type,
|
|
|
|
|
mimetype: ev.event?.mensagem.mimetype,
|
|
|
|
|
id_provedor: ev.event?.mensagem.id_provedor, |
|
|
|
|
type: ev.event?.mensagem.type, |
|
|
|
|
mimetype: ev.event?.mensagem.mimetype, |
|
|
|
|
from: 'receiver' |
|
|
|
|
} |
|
|
|
|
messageTypeMedia(sendobj) |
|
|
|
@ -348,9 +343,9 @@ const viewMessage = (ev) => {
|
|
|
|
|
const receiveNotification = (data) => { |
|
|
|
|
let validate = null |
|
|
|
|
|
|
|
|
|
switch(data.event?.type){ |
|
|
|
|
switch (data.event?.type) { |
|
|
|
|
case "mensagem": |
|
|
|
|
if(data.event.mensagem.uniqueid != localStorage.getItem('session_uniqueid')){ |
|
|
|
|
if (data.event.mensagem.uniqueid != localStorage.getItem('session_uniqueid')) { |
|
|
|
|
notifyMe(data.event.contact.name, { |
|
|
|
|
body: data.event.mensagem.content, |
|
|
|
|
icon: `images/${data.event.mensagem.media}.png`, |
|
|
|
@ -358,27 +353,28 @@ const receiveNotification = (data) => {
|
|
|
|
|
}) |
|
|
|
|
soundNotification(`${path}/sound/notification.mp3`) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** VALIDA O NUMERO, VERIFICA SE O TEM ALGMA MSG INICIAL, SE JA TEVE UM NUMERO NA VERIFICACAO */ |
|
|
|
|
listarAtendimentoAgente(localStorage.getItem('id_empresa'), localStorage.getItem('my_uniqueid')) |
|
|
|
|
validate = JSON.parse(localStorage.getItem('obj_notification')) |
|
|
|
|
|
|
|
|
|
const vald = validate.data.filter((e) => { |
|
|
|
|
return data.event?.mensagem.uniqueid == e.uniqueid
|
|
|
|
|
return data.event?.mensagem.uniqueid == e.uniqueid |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
if(data.event?.contact.number != localStorage.getItem('session_window')){ |
|
|
|
|
if (data.event?.contact.number != localStorage.getItem('session_window')) { |
|
|
|
|
alertNotification(data.event.mensagem.uniqueid) |
|
|
|
|
}
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (data.event?.mensagem.uniqueid && data.event?.contact.number && vald.length == 0) { |
|
|
|
|
notifications( |
|
|
|
|
{
|
|
|
|
|
{ |
|
|
|
|
uniqueid: data.event?.mensagem.uniqueid, |
|
|
|
|
cliente_id: data.event?.contact.number,
|
|
|
|
|
context: data.event?.mensagem.media,
|
|
|
|
|
profile_name: data.event?.contact.name,
|
|
|
|
|
cliente_id: data.event?.contact.number, |
|
|
|
|
context: data.event?.mensagem.media, |
|
|
|
|
profile_name: data.event?.contact.name, |
|
|
|
|
data_reg: data.event?.mensagem.datetime, |
|
|
|
|
media: data.event?.mensagem.media, |
|
|
|
|
status: 1, |
|
|
|
|
action: 'mensagem', |
|
|
|
|
} |
|
|
|
@ -387,7 +383,7 @@ const receiveNotification = (data) => {
|
|
|
|
|
break |
|
|
|
|
case "actions": |
|
|
|
|
let obj |
|
|
|
|
switch(data.event.mensagem.type){ |
|
|
|
|
switch (data.event.mensagem.type) { |
|
|
|
|
case 'start': |
|
|
|
|
case 'transfer': |
|
|
|
|
case 'att_status': |
|
|
|
@ -395,7 +391,7 @@ const receiveNotification = (data) => {
|
|
|
|
|
break |
|
|
|
|
case 'finish': |
|
|
|
|
case 're_start': |
|
|
|
|
obj = {
|
|
|
|
|
obj = { |
|
|
|
|
uniqueid: data.event?.mensagem.uniqueid, |
|
|
|
|
action: data.event.mensagem.type, |
|
|
|
|
} |
|
|
|
@ -413,11 +409,11 @@ const receiveNotification = (data) => {
|
|
|
|
|
*/ |
|
|
|
|
const keepMensage = (ev) => { |
|
|
|
|
let msg = JSON.parse(localStorage.getItem('keep_msg')) |
|
|
|
|
if(!msg){ |
|
|
|
|
if (!msg) { |
|
|
|
|
msg = { data: [] } |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if(ev.event?.contact && ev.event?.mensagem.content){ |
|
|
|
|
if (ev.event?.contact && ev.event?.mensagem.content) { |
|
|
|
|
msg.data.push(ev) |
|
|
|
|
localStorage.removeItem('keep_msg'); |
|
|
|
|
localStorage.setItem('keep_msg', JSON.stringify(msg)) |
|
|
|
@ -427,37 +423,37 @@ const keepMensage = (ev) => {
|
|
|
|
|
/** |
|
|
|
|
* FUNCAO PARA CAPTURAR O ARQUIVO A SER ENVIADO |
|
|
|
|
*/ |
|
|
|
|
const sendMedia = (media = null) => { |
|
|
|
|
const sendMedia = (media = null) => { |
|
|
|
|
let rec |
|
|
|
|
let filename |
|
|
|
|
if($("#footer-content-left audio").length){ |
|
|
|
|
if(media.state == 'recording'){ |
|
|
|
|
if ($("#footer-content-left audio").length) { |
|
|
|
|
if (media.state == 'recording') { |
|
|
|
|
media.stop(); |
|
|
|
|
} |
|
|
|
|
let el = $("#footer-content-left audio")[0].src |
|
|
|
|
fileContent = $("#footer-content-left audio")[0].outerHTML |
|
|
|
|
sendMessage({ content: el.replace("data:", "").replace(/^.+,/, ""), type: 'audio', mimetype: 'audio/mpeg', fileContent }) |
|
|
|
|
return |
|
|
|
|
} else if($("#uploadfile")[0].files[0]) {
|
|
|
|
|
} else if ($("#uploadfile")[0].files[0]) { |
|
|
|
|
let el = $("#uploadfile")[0].files[0] |
|
|
|
|
rec = new Blob([el], { type : el.type }) |
|
|
|
|
rec = new Blob([el], { type: el.type }) |
|
|
|
|
let filesent = $("#myImg") |
|
|
|
|
filesent[0].id = Date.now() |
|
|
|
|
imgContent = filesent.css({'max-width': '60px'})[0].outerHTML |
|
|
|
|
imgContent = filesent.css({ 'max-width': '60px' })[0].outerHTML |
|
|
|
|
fileContent = `<a href="${URL.createObjectURL(rec)}" target="_blank">${imgContent}</a>` |
|
|
|
|
filename = el.name |
|
|
|
|
} else { |
|
|
|
|
rec = $("#uploadimage")[0].files[0] |
|
|
|
|
let filesent = $("#myImg") |
|
|
|
|
filesent[0].id = Date.now() |
|
|
|
|
fileContent = filesent.css({'max-width': '350px'})[0].outerHTML |
|
|
|
|
fileContent = filesent.css({ 'max-width': '350px' })[0].outerHTML |
|
|
|
|
$("#myImg").empty() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const file = new FileReader(); |
|
|
|
|
file.onload = function() { |
|
|
|
|
file.onload = function () { |
|
|
|
|
const typefile = rec.type.split("/")[0].indexOf('image') >= 0 ? rec.type.split("/")[0] : 'document' |
|
|
|
|
sendMessage({ content: file.result.replace("data:", "").replace(/^.+,/, ""), type: typefile, mimetype: rec.type, fileContent, filename }) |
|
|
|
|
} |
|
|
|
|
file.readAsDataURL(rec);
|
|
|
|
|
file.readAsDataURL(rec); |
|
|
|
|
} |