FIX: Bug de duplicação de mensganes no HubSoft consertado
This commit is contained in:
parent
0b66f26f60
commit
f64dafa2e1
@ -14,9 +14,6 @@ async function sendHubsoftMessage(atendimentoId, mensagem) {
|
||||
const url = `${hubsoft.atendimentosUrl}adicionar_mensagem/${atendimentoId}`
|
||||
const payload = { mensagem }
|
||||
|
||||
console.log('URL:', url)
|
||||
console.log('Payload:', payload)
|
||||
|
||||
|
||||
try {
|
||||
logInfo(`Enviando mensagem para atendimento HubSoft ${atendimentoId}`)
|
||||
@ -38,6 +35,36 @@ async function sendHubsoftMessage(atendimentoId, mensagem) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Encerra um atendimento no HubSoft
|
||||
*/
|
||||
async function close(atendimentoId, mensagem) {
|
||||
try {
|
||||
const token = await getAuthToken();
|
||||
|
||||
const response = await axios.put(`${hubsoft.atendimentosUrl}${atendimentoId}`, {
|
||||
"fechar_atendimento": true,
|
||||
"parametros_fechamento": {
|
||||
"descricao_fechamento": mensagem
|
||||
}
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
'Authorization': `Bearer ${token}`,
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
});
|
||||
return response.data;
|
||||
} catch (error) {
|
||||
logError(`Erro ao fechar atendimento ID ${atendimentoId}:`, error.response ? error.response.data : error.message);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
module.exports = {
|
||||
sendHubsoftMessage
|
||||
sendHubsoftMessage,
|
||||
close
|
||||
}
|
||||
|
||||
@ -2,7 +2,7 @@
|
||||
|
||||
const repository = require('../repositories/comment.repository')
|
||||
const { sanitizeGLPIComment } = require('../../../shared/utils/commentSanitizer')
|
||||
const { logInfo, logError, logWarn } = require('../../../shared/utils/logger')
|
||||
const { logInfo, logError, logWarning } = require('../../../shared/utils/logger')
|
||||
|
||||
async function sync({ glpiTicketId, glpiMessageId, rawContent }) {
|
||||
logInfo(`[COMMENTS][GLPI->HUB] Ticket ${glpiTicketId}`)
|
||||
@ -10,7 +10,7 @@ async function sync({ glpiTicketId, glpiMessageId, rawContent }) {
|
||||
try {
|
||||
const syncRecord = await repository.getSyncByGlpiId(glpiTicketId)
|
||||
if (!syncRecord?.hubsoft_ticket_id) {
|
||||
logWarn('[COMMENTS][GLPI->HUB] Ticket sem vínculo com Hubsoft')
|
||||
logWarning('[COMMENTS][GLPI->HUB] Ticket sem vínculo com Hubsoft')
|
||||
return
|
||||
}
|
||||
|
||||
@ -31,13 +31,18 @@ async function sync({ glpiTicketId, glpiMessageId, rawContent }) {
|
||||
content
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
await repository.insertSyncComment({
|
||||
source: 'glpi',
|
||||
syncDataId: syncRecord.id,
|
||||
sourceSystem: 'glpi',
|
||||
sourceCommentId: glpiMessageId,
|
||||
destinationCommentId: hubsoftMessageId,
|
||||
hubsoftTicketId: syncRecord.hubsoft_ticket_id,
|
||||
glpiTicketId,
|
||||
content,
|
||||
author: 'glpi-user',
|
||||
status: 'synced'
|
||||
})
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user