@@ -643,19 +643,32 @@ export class WAStartupService {
643643 remoteJid : chat . remoteJid ,
644644 } ,
645645 } )
646- . then ( ( result ) =>
647- this . repository . chat
648- . update ( {
649- where : {
650- id : result . id ,
651- } ,
652- data : {
653- content : chat . content ,
654- updatedAt : new Date ( ) ,
655- } ,
656- } )
657- . catch ( ( err ) => this . logger . error ( err ) ) ,
658- )
646+ . then ( ( result ) => {
647+ if ( result ?. id ) {
648+ this . repository . chat
649+ . update ( {
650+ where : {
651+ id : result . id ,
652+ } ,
653+ data : {
654+ content : chat . content ,
655+ updatedAt : new Date ( ) ,
656+ } ,
657+ } )
658+ . catch ( ( err ) => this . logger . error ( err ) ) ;
659+ } else {
660+ this . repository . chat
661+ . create ( {
662+ data : {
663+ remoteJid : chat . remoteJid ,
664+ content : chat . content ,
665+ updatedAt : new Date ( ) ,
666+ instanceId : this . instance . id ,
667+ } ,
668+ } )
669+ . catch ( ( err ) => this . logger . error ( err ) ) ;
670+ }
671+ } )
659672 . catch ( ( err ) => this . logger . error ( err ) ) ;
660673 } ) ;
661674 } ,
@@ -1263,7 +1276,7 @@ export class WAStartupService {
12631276 await this . client . sendPresenceUpdate ( 'paused' , recipient ) ;
12641277 }
12651278
1266- const messageSent : PrismType . Message = await ( async ( ) => {
1279+ const messageSent : Partial < PrismType . Message > = await ( async ( ) => {
12671280 let q : proto . IWebMessageInfo ;
12681281 if ( quoted ) {
12691282 q = {
@@ -1314,7 +1327,6 @@ export class WAStartupService {
13141327 this . client . ev . emit ( 'messages.upsert' , { messages : [ m ] , type : 'notify' } ) ;
13151328
13161329 return {
1317- id : undefined ,
13181330 keyId : m . key . id ,
13191331 keyFromMe : m . key . fromMe ,
13201332 keyRemoteJid : m . key . remoteJid ,
@@ -1335,7 +1347,7 @@ export class WAStartupService {
13351347 } ) ( ) ;
13361348 if ( this . databaseOptions . DB_OPTIONS . NEW_MESSAGE ) {
13371349 const { id } = await this . repository . message . create ( {
1338- data : messageSent ,
1350+ data : messageSent as PrismType . Message ,
13391351 } ) ;
13401352 messageSent . id = id ;
13411353 }
0 commit comments