@@ -1367,21 +1367,43 @@ export class WAStartupService {
13671367 ) ;
13681368 } ) ( ) ;
13691369
1370- const messageRaw : proto . IWebMessageInfo = {
1370+ // const messageRaw: proto.IWebMessageInfo = {
1371+ // key: messageSent.key,
1372+ // messageTimestamp: Long.isLong(messageSent.messageTimestamp)
1373+ // ? messageSent.messageTimestamp?.toNumber()
1374+ // : messageSent.messageTimestamp,
1375+ // pushName: messageSent.pushName,
1376+ // broadcast: messageSent.broadcast,
1377+ // status: 2,
1378+ // message: { ...messageSent.message },
1379+ // };
1380+
1381+ // this.client.ev.emit('messages.upsert', {
1382+ // messages: [messageRaw],
1383+ // type: 'notify',
1384+ // });
1385+
1386+ const messageRaw : MessageRaw = {
13711387 key : messageSent . key ,
1372- messageTimestamp : Long . isLong ( messageSent . messageTimestamp )
1373- ? messageSent . messageTimestamp ?. toNumber ( )
1374- : messageSent . messageTimestamp ,
13751388 pushName : messageSent . pushName ,
1376- broadcast : messageSent . broadcast ,
1377- status : 2 ,
13781389 message : { ...messageSent . message } ,
1390+ messageType : getContentType ( messageSent . message ) ,
1391+ messageTimestamp : messageSent . messageTimestamp as number ,
1392+ owner : this . instance . name ,
1393+ source : getDevice ( messageSent . key . id ) ,
13791394 } ;
13801395
1381- this . client . ev . emit ( 'messages.upsert' , {
1382- messages : [ messageRaw ] ,
1383- type : 'notify' ,
1384- } ) ;
1396+ this . logger . log ( messageRaw ) ;
1397+
1398+ this . logger . verbose ( 'Sending data to webhook in event MESSAGES_UPSERT' ) ;
1399+ await this . sendDataWebhook ( Events . MESSAGES_UPSERT , messageRaw ) ;
1400+
1401+ this . logger . verbose ( 'Inserting message in database' ) ;
1402+ await this . repository . message . insert (
1403+ [ messageRaw ] ,
1404+ this . instance . name ,
1405+ this . configService . get < Database > ( 'DATABASE' ) . SAVE_DATA . NEW_MESSAGE ,
1406+ ) ;
13851407
13861408 return messageSent ;
13871409 } catch ( error ) {
@@ -1628,15 +1650,15 @@ export class WAStartupService {
16281650 const hash = `${ number } -${ new Date ( ) . getTime ( ) } ` ;
16291651 this . logger . verbose ( 'Hash to image name: ' + hash ) ;
16301652
1631- const outputPath = `${ join ( process . cwd ( ) , 'temp' , `${ hash } .webp` ) } ` ;
1653+ const outputPath = `${ join ( this . storePath , 'temp' , `${ hash } .webp` ) } ` ;
16321654 this . logger . verbose ( 'Output path: ' + outputPath ) ;
16331655
16341656 if ( isBase64 ( image ) ) {
16351657 this . logger . verbose ( 'Image is base64' ) ;
16361658
16371659 const base64Data = image . replace ( / ^ d a t a : i m a g e \/ ( j p e g | p n g | g i f ) ; b a s e 6 4 , / , '' ) ;
16381660 const imageBuffer = Buffer . from ( base64Data , 'base64' ) ;
1639- imagePath = `${ join ( process . cwd ( ) , 'temp' , `temp-${ hash } .png` ) } ` ;
1661+ imagePath = `${ join ( this . storePath , 'temp' , `temp-${ hash } .png` ) } ` ;
16401662 this . logger . verbose ( 'Image path: ' + imagePath ) ;
16411663
16421664 await sharp ( imageBuffer ) . toFile ( imagePath ) ;
@@ -1652,7 +1674,7 @@ export class WAStartupService {
16521674 this . logger . verbose ( 'Getting image from url' ) ;
16531675
16541676 const imageBuffer = Buffer . from ( response . data , 'binary' ) ;
1655- imagePath = `${ join ( process . cwd ( ) , 'temp' , `temp-${ hash } .png` ) } ` ;
1677+ imagePath = `${ join ( this . storePath , 'temp' , `temp-${ hash } .png` ) } ` ;
16561678 this . logger . verbose ( 'Image path: ' + imagePath ) ;
16571679
16581680 await sharp ( imageBuffer ) . toFile ( imagePath ) ;
@@ -1710,8 +1732,8 @@ export class WAStartupService {
17101732 if ( isURL ( audio ) ) {
17111733 this . logger . verbose ( 'Audio is url' ) ;
17121734
1713- outputAudio = `${ join ( process . cwd ( ) , 'temp' , `${ hash } .mp4` ) } ` ;
1714- tempAudioPath = `${ join ( process . cwd ( ) , 'temp' , `temp-${ hash } .mp3` ) } ` ;
1735+ outputAudio = `${ join ( this . storePath , 'temp' , `${ hash } .mp4` ) } ` ;
1736+ tempAudioPath = `${ join ( this . storePath , 'temp' , `temp-${ hash } .mp3` ) } ` ;
17151737
17161738 this . logger . verbose ( 'Output audio path: ' + outputAudio ) ;
17171739 this . logger . verbose ( 'Temp audio path: ' + tempAudioPath ) ;
@@ -1725,12 +1747,11 @@ export class WAStartupService {
17251747 this . logger . verbose ( 'Getting audio from url' ) ;
17261748
17271749 fs . writeFileSync ( tempAudioPath , response . data ) ;
1728- this . logger . verbose ( 'Temp audio created' ) ;
17291750 } else {
17301751 this . logger . verbose ( 'Audio is base64' ) ;
17311752
1732- outputAudio = `${ join ( process . cwd ( ) , 'temp' , `${ hash } .mp4` ) } ` ;
1733- tempAudioPath = `${ join ( process . cwd ( ) , 'temp' , `temp-${ hash } .mp3` ) } ` ;
1753+ outputAudio = `${ join ( this . storePath , 'temp' , `${ hash } .mp4` ) } ` ;
1754+ tempAudioPath = `${ join ( this . storePath , 'temp' , `temp-${ hash } .mp3` ) } ` ;
17341755
17351756 this . logger . verbose ( 'Output audio path: ' + outputAudio ) ;
17361757 this . logger . verbose ( 'Temp audio path: ' + tempAudioPath ) ;
0 commit comments