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 url = `${hubsoft.atendimentosUrl}adicionar_mensagem/${atendimentoId}`
|
||||||
const payload = { mensagem }
|
const payload = { mensagem }
|
||||||
|
|
||||||
console.log('URL:', url)
|
|
||||||
console.log('Payload:', payload)
|
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
logInfo(`Enviando mensagem para atendimento HubSoft ${atendimentoId}`)
|
logInfo(`Enviando mensagem para atendimento HubSoft ${atendimentoId}`)
|
||||||
@ -38,6 +35,36 @@ async function sendHubsoftMessage(atendimentoId, mensagem) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
/**
|
||||||
sendHubsoftMessage
|
* 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,
|
||||||
|
close
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
const repository = require('../repositories/comment.repository')
|
const repository = require('../repositories/comment.repository')
|
||||||
const { sanitizeGLPIComment } = require('../../../shared/utils/commentSanitizer')
|
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 }) {
|
async function sync({ glpiTicketId, glpiMessageId, rawContent }) {
|
||||||
logInfo(`[COMMENTS][GLPI->HUB] Ticket ${glpiTicketId}`)
|
logInfo(`[COMMENTS][GLPI->HUB] Ticket ${glpiTicketId}`)
|
||||||
@ -10,7 +10,7 @@ async function sync({ glpiTicketId, glpiMessageId, rawContent }) {
|
|||||||
try {
|
try {
|
||||||
const syncRecord = await repository.getSyncByGlpiId(glpiTicketId)
|
const syncRecord = await repository.getSyncByGlpiId(glpiTicketId)
|
||||||
if (!syncRecord?.hubsoft_ticket_id) {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,13 +31,18 @@ async function sync({ glpiTicketId, glpiMessageId, rawContent }) {
|
|||||||
content
|
content
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
await repository.insertSyncComment({
|
await repository.insertSyncComment({
|
||||||
source: 'glpi',
|
syncDataId: syncRecord.id,
|
||||||
|
sourceSystem: 'glpi',
|
||||||
sourceCommentId: glpiMessageId,
|
sourceCommentId: glpiMessageId,
|
||||||
destinationCommentId: hubsoftMessageId,
|
destinationCommentId: hubsoftMessageId,
|
||||||
hubsoftTicketId: syncRecord.hubsoft_ticket_id,
|
hubsoftTicketId: syncRecord.hubsoft_ticket_id,
|
||||||
glpiTicketId,
|
glpiTicketId,
|
||||||
content,
|
content,
|
||||||
|
author: 'glpi-user',
|
||||||
status: 'synced'
|
status: 'synced'
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user