fix: changes applied after technical lead code review

analisando_gabriel-poc
Eduxavier88 2025-06-20 18:06:30 -03:00
parent bb25ec1f09
commit 210da8608d
2 changed files with 20 additions and 20 deletions

View File

@ -5,11 +5,11 @@ const { get, del } = require('../utils/redisClient')
const receiveTranscription = async (req, res) => {
try {
console.log('Payload recebido:', JSON.stringify(req.body, null, 2));
const { crmPhone, uniqueId, transcription, recordingUrl, companyId, clientTranscription, agentTranscription } = req.body;
console.log('=========> crmPhone: ', crmPhone, "===> uniqueId: ", uniqueId, "===> transcription: ", transcription, "===> recordingUrl: ", recordingUrl, "===> companyId: ", companyId )
@ -24,10 +24,7 @@ const receiveTranscription = async (req, res) => {
return res.status(400).json({ error: 'Campos obrigatórios ausentes.' });
}
console.log(`Recebida transcrição para crmPhone: ${crmPhone}, uniqueId: ${uniqueId}`);
console.log('Transcrição Resumo:', transcription);
console.log('Transcrição Cliente:', clientTranscription);
console.log('Transcrição Agente:', agentTranscription);
// 1. Buscar ticketId no Redis
const ticketId = await get(crmPhone);

View File

@ -130,21 +130,24 @@ Link da Gravação: ${recordingUrl}
* @returns {Promise<Object>} - Contato existente ou novo contato criado.
*/
async createContactIfNotExists(crmPhone) {
if (this?.crmFiles?.length > 0) {
const { crmRest: rest, authentication } = this.crmFiles[0].crm
let contact = await lookupContactByPhone(rest, authentication, crmPhone, companyId)
if (!contact.exist) {
contact = await createContact(companyId, rest, authentication, crmPhone)
}
console.log('========> contact', contact)
return contact
if (!this.crmFiles?.length) {
throw new Error(`Nenhuma configuração CRM encontrada para companyId: ${this.companyId}`);
}
return null
const { crmRest: rest, authentication } = this.crmFiles[0].crm;
let contact = await lookupContactByPhone(rest, authentication, crmPhone, this.companyId);
if (!contact?.exist) {
contact = await createContact(this.companyId, rest, authentication, crmPhone);
}
if (!contact || !contact.contactId) {
throw new Error(`Falha ao obter contactId para ${crmPhone}`);
}
console.log('========> contact', contact);
return contact;
}
}