@@ -191,64 +191,64 @@ export class BusinessStartupService extends ChannelStartupService {
191191 return content ;
192192 }
193193
194- private messageTextJson ( received : any ) {
195- // Verificar que received y received.messages existen
196- if ( ! received || ! received . messages || received . messages . length === 0 ) {
197- this . logger . error ( 'Error: received object or messages array is undefined or empty' ) ;
198- return null ;
199- }
200-
201- const message = received . messages [ 0 ] ;
202- let content : any ;
203-
204- // Verificar si es un mensaje de tipo sticker, location u otro tipo que no tiene text
205- if ( ! message . text ) {
206- // Si no hay texto, manejamos diferente según el tipo de mensaje
207- if ( message . type === 'sticker' ) {
208- content = { stickerMessage : { } } ;
209- } else if ( message . type === 'location' ) {
210- content = { locationMessage : {
211- degreesLatitude : message . location ?. latitude ,
212- degreesLongitude : message . location ?. longitude ,
213- name : message . location ?. name ,
214- address : message . location ?. address ,
215- } } ;
216- } else {
217- // Para otros tipos de mensajes sin texto, creamos un contenido genérico
218- this . logger . log ( `Mensaje de tipo ${ message . type } sin campo text` ) ;
219- content = { [ message . type + 'Message' ] : message [ message . type ] || { } } ;
194+ private messageTextJson ( received : any ) {
195+ // Verificar que received y received.messages existen
196+ if ( ! received || ! received . messages || received . messages . length === 0 ) {
197+ this . logger . error ( 'Error: received object or messages array is undefined or empty' ) ;
198+ return null ;
220199 }
200+
201+ const message = received . messages [ 0 ] ;
202+ let content : any ;
221203
222- // Añadir contexto si existe
223- if ( message . context ) {
224- content = { ...content , contextInfo : { stanzaId : message . context . id } } ;
204+ // Verificar si es un mensaje de tipo sticker, location u otro tipo que no tiene text
205+ if ( ! message . text ) {
206+ // Si no hay texto, manejamos diferente según el tipo de mensaje
207+ if ( message . type === 'sticker' ) {
208+ content = { stickerMessage : { } } ;
209+ } else if ( message . type === 'location' ) {
210+ content = { locationMessage : {
211+ degreesLatitude : message . location ?. latitude ,
212+ degreesLongitude : message . location ?. longitude ,
213+ name : message . location ?. name ,
214+ address : message . location ?. address ,
215+ } } ;
216+ } else {
217+ // Para otros tipos de mensajes sin texto, creamos un contenido genérico
218+ this . logger . log ( `Mensaje de tipo ${ message . type } sin campo text` ) ;
219+ content = { [ message . type + 'Message' ] : message [ message . type ] || { } } ;
220+ }
221+
222+ // Añadir contexto si existe
223+ if ( message . context ) {
224+ content = { ...content , contextInfo : { stanzaId : message . context . id } } ;
225+ }
226+
227+ return content ;
225228 }
226229
227- return content ;
228- }
229-
230- // Si el mensaje tiene texto, procesamos normalmente
231- if ( ! received . metadata || ! received . metadata . phone_number_id ) {
232- this . logger . error ( 'Error: metadata or phone_number_id is undefined' ) ;
233- return null ;
234- }
235-
236- if ( message . from === received . metadata . phone_number_id ) {
237- content = {
238- extendedTextMessage : { text : message . text . body } ,
239- } ;
240- if ( message . context ) {
241- content = { ...content , contextInfo : { stanzaId : message . context . id } } ;
230+ // Si el mensaje tiene texto, procesamos normalmente
231+ if ( ! received . metadata || ! received . metadata . phone_number_id ) {
232+ this . logger . error ( 'Error: metadata or phone_number_id is undefined' ) ;
233+ return null ;
242234 }
243- } else {
244- content = { conversation : message . text . body } ;
245- if ( message . context ) {
246- content = { ...content , contextInfo : { stanzaId : message . context . id } } ;
235+
236+ if ( message . from === received . metadata . phone_number_id ) {
237+ content = {
238+ extendedTextMessage : { text : message . text . body } ,
239+ } ;
240+ if ( message . context ) {
241+ content = { ...content , contextInfo : { stanzaId : message . context . id } } ;
242+ }
243+ } else {
244+ content = { conversation : message . text . body } ;
245+ if ( message . context ) {
246+ content = { ...content , contextInfo : { stanzaId : message . context . id } } ;
247+ }
247248 }
249+
250+ return content ;
248251 }
249-
250- return content ;
251- }
252252
253253 private messageContactsJson ( received : any ) {
254254 const message = received . messages [ 0 ] ;
0 commit comments