@@ -984,12 +984,20 @@ export class WAStartupService {
984984 if (
985985 key . remoteJid !== 'status@broadcast' &&
986986 ! key ?. remoteJid ?. match ( / ( : \d + ) / ) &&
987- ! key . fromMe
987+ key . fromMe
988988 ) {
989+ this . logger . verbose ( 'Message update is valid' ) ;
990+
989991 let pollUpdates : any ;
990992 if ( update . pollUpdates ) {
993+ this . logger . verbose ( 'Poll update found' ) ;
994+
995+ this . logger . verbose ( 'Getting poll message' ) ;
991996 const pollCreation = await this . getMessage ( key ) ;
997+ this . logger . verbose ( pollCreation ) ;
998+
992999 if ( pollCreation ) {
1000+ this . logger . verbose ( 'Getting aggregate votes in poll message' ) ;
9931001 pollUpdates = getAggregateVotesInPollMessage ( {
9941002 message : pollCreation as proto . IMessage ,
9951003 pollUpdates : update . pollUpdates ,
@@ -1005,6 +1013,8 @@ export class WAStartupService {
10051013 pollUpdates,
10061014 } ;
10071015
1016+ this . logger . verbose ( message ) ;
1017+
10081018 this . logger . verbose ( 'Sending data to webhook in event MESSAGES_UPDATE' ) ;
10091019 await this . sendDataWebhook ( Events . MESSAGES_UPDATE , message ) ;
10101020
@@ -1367,21 +1377,27 @@ export class WAStartupService {
13671377 ) ;
13681378 } ) ( ) ;
13691379
1370- const messageRaw : proto . IWebMessageInfo = {
1380+ const messageRaw : MessageRaw = {
13711381 key : messageSent . key ,
1372- messageTimestamp : Long . isLong ( messageSent . messageTimestamp )
1373- ? messageSent . messageTimestamp ?. toNumber ( )
1374- : messageSent . messageTimestamp ,
13751382 pushName : messageSent . pushName ,
1376- broadcast : messageSent . broadcast ,
1377- status : 2 ,
13781383 message : { ...messageSent . message } ,
1384+ messageType : getContentType ( messageSent . message ) ,
1385+ messageTimestamp : messageSent . messageTimestamp as number ,
1386+ owner : this . instance . name ,
1387+ source : getDevice ( messageSent . key . id ) ,
13791388 } ;
13801389
1381- this . client . ev . emit ( 'messages.upsert' , {
1382- messages : [ messageRaw ] ,
1383- type : 'notify' ,
1384- } ) ;
1390+ this . logger . log ( messageRaw ) ;
1391+
1392+ this . logger . verbose ( 'Sending data to webhook in event SEND_MESSAGE' ) ;
1393+ await this . sendDataWebhook ( Events . SEND_MESSAGE , messageRaw ) ;
1394+
1395+ this . logger . verbose ( 'Inserting message in database' ) ;
1396+ await this . repository . message . insert (
1397+ [ messageRaw ] ,
1398+ this . instance . name ,
1399+ this . configService . get < Database > ( 'DATABASE' ) . SAVE_DATA . NEW_MESSAGE ,
1400+ ) ;
13851401
13861402 return messageSent ;
13871403 } catch ( error ) {
@@ -1628,15 +1644,15 @@ export class WAStartupService {
16281644 const hash = `${ number } -${ new Date ( ) . getTime ( ) } ` ;
16291645 this . logger . verbose ( 'Hash to image name: ' + hash ) ;
16301646
1631- const outputPath = `${ join ( process . cwd ( ) , 'temp' , `${ hash } .webp` ) } ` ;
1647+ const outputPath = `${ join ( this . storePath , 'temp' , `${ hash } .webp` ) } ` ;
16321648 this . logger . verbose ( 'Output path: ' + outputPath ) ;
16331649
16341650 if ( isBase64 ( image ) ) {
16351651 this . logger . verbose ( 'Image is base64' ) ;
16361652
16371653 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 , / , '' ) ;
16381654 const imageBuffer = Buffer . from ( base64Data , 'base64' ) ;
1639- imagePath = `${ join ( process . cwd ( ) , 'temp' , `temp-${ hash } .png` ) } ` ;
1655+ imagePath = `${ join ( this . storePath , 'temp' , `temp-${ hash } .png` ) } ` ;
16401656 this . logger . verbose ( 'Image path: ' + imagePath ) ;
16411657
16421658 await sharp ( imageBuffer ) . toFile ( imagePath ) ;
@@ -1652,7 +1668,7 @@ export class WAStartupService {
16521668 this . logger . verbose ( 'Getting image from url' ) ;
16531669
16541670 const imageBuffer = Buffer . from ( response . data , 'binary' ) ;
1655- imagePath = `${ join ( process . cwd ( ) , 'temp' , `temp-${ hash } .png` ) } ` ;
1671+ imagePath = `${ join ( this . storePath , 'temp' , `temp-${ hash } .png` ) } ` ;
16561672 this . logger . verbose ( 'Image path: ' + imagePath ) ;
16571673
16581674 await sharp ( imageBuffer ) . toFile ( imagePath ) ;
@@ -1710,8 +1726,8 @@ export class WAStartupService {
17101726 if ( isURL ( audio ) ) {
17111727 this . logger . verbose ( 'Audio is url' ) ;
17121728
1713- outputAudio = `${ join ( process . cwd ( ) , 'temp' , `${ hash } .mp4` ) } ` ;
1714- tempAudioPath = `${ join ( process . cwd ( ) , 'temp' , `temp-${ hash } .mp3` ) } ` ;
1729+ outputAudio = `${ join ( this . storePath , 'temp' , `${ hash } .mp4` ) } ` ;
1730+ tempAudioPath = `${ join ( this . storePath , 'temp' , `temp-${ hash } .mp3` ) } ` ;
17151731
17161732 this . logger . verbose ( 'Output audio path: ' + outputAudio ) ;
17171733 this . logger . verbose ( 'Temp audio path: ' + tempAudioPath ) ;
@@ -1725,12 +1741,11 @@ export class WAStartupService {
17251741 this . logger . verbose ( 'Getting audio from url' ) ;
17261742
17271743 fs . writeFileSync ( tempAudioPath , response . data ) ;
1728- this . logger . verbose ( 'Temp audio created' ) ;
17291744 } else {
17301745 this . logger . verbose ( 'Audio is base64' ) ;
17311746
1732- outputAudio = `${ join ( process . cwd ( ) , 'temp' , `${ hash } .mp4` ) } ` ;
1733- tempAudioPath = `${ join ( process . cwd ( ) , 'temp' , `temp-${ hash } .mp3` ) } ` ;
1747+ outputAudio = `${ join ( this . storePath , 'temp' , `${ hash } .mp4` ) } ` ;
1748+ tempAudioPath = `${ join ( this . storePath , 'temp' , `temp-${ hash } .mp3` ) } ` ;
17341749
17351750 this . logger . verbose ( 'Output audio path: ' + outputAudio ) ;
17361751 this . logger . verbose ( 'Temp audio path: ' + tempAudioPath ) ;
0 commit comments