fix: changes applied after technical lead code review
							parent
							
								
									bb25ec1f09
								
							
						
					
					
						commit
						210da8608d
					
				|  | @ -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); | ||||
|  |  | |||
|  | @ -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; | ||||
|   } | ||||
| } | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue