@@ -567,6 +567,12 @@ export class ChatwootService {
567567 }
568568
569569 public async createConversation ( instance : InstanceDto , body : any ) {
570+ if ( ! body ?. key ) {
571+ this . logger . warn ( 'body.key is null or undefined in createConversation' ) ;
572+ this . logger . warn ( 'Full body object:' , JSON . stringify ( body , null , 2 ) ) ;
573+ return null ;
574+ }
575+
570576 const isLid = body . key . previousRemoteJid ?. includes ( '@lid' ) && body . key . senderPn ;
571577 const remoteJid = body . key . remoteJid ;
572578 const cacheKey = `${ instance . instanceName } :createConversation-${ remoteJid } ` ;
@@ -1938,6 +1944,12 @@ export class ChatwootService {
19381944 }
19391945
19401946 if ( event === 'messages.upsert' || event === 'send.message' ) {
1947+ if ( ! body ?. key ) {
1948+ this . logger . warn ( 'body.key is null or undefined' ) ;
1949+ this . logger . warn ( 'Full body object:' , JSON . stringify ( body , null , 2 ) ) ;
1950+ return ;
1951+ }
1952+
19411953 if ( body . key . remoteJid === 'status@broadcast' ) {
19421954 return ;
19431955 }
@@ -2260,10 +2272,16 @@ export class ChatwootService {
22602272 }
22612273
22622274 if ( event === 'messages.edit' || event === 'send.message.update' ) {
2275+ if ( ! body ?. key ?. id ) {
2276+ this . logger . warn ( 'body.key.id is null or undefined in messages.edit' ) ;
2277+ this . logger . warn ( 'Full body object:' , JSON . stringify ( body , null , 2 ) ) ;
2278+ return ;
2279+ }
2280+
22632281 const editedText = `${
22642282 body ?. editedMessage ?. conversation || body ?. editedMessage ?. extendedTextMessage ?. text
22652283 } \n\n_\`${ i18next . t ( 'cw.message.edited' ) } .\`_`;
2266- const message = await this . getMessageByKeyId ( instance , body ? .key ? .id ) ;
2284+ const message = await this . getMessageByKeyId ( instance , body . key . id ) ;
22672285 const key = message . key as {
22682286 id : string ;
22692287 fromMe : boolean ;
0 commit comments