@@ -288,15 +288,25 @@ export class BaileysStartupService extends ChannelStartupService {
288288 statusReason : ( lastDisconnect ?. error as Boom ) ?. output ?. statusCode ?? 200 ,
289289 } ;
290290
291+ try {
292+ const profilePic = await this . profilePicture ( this . client . user . id . replace ( / : \d + / , '' ) ) ;
293+ this . instance . profilePictureUrl = profilePic . profilePictureUrl ;
294+ } catch ( error ) {
295+ this . instance . profilePictureUrl = null ;
296+ }
297+
291298 this . sendDataWebhook ( Events . CONNECTION_UPDATE , {
292299 instance : this . instance . name ,
300+ wuid : this . client . user ?. id . replace ( / : \d + / , '' ) ,
301+ pictureUrl : this . instance . profilePictureUrl ,
302+ profileName : await this . getProfileName ( ) ,
293303 ...this . stateConnection ,
294304 } ) ;
295305 }
296306
297307 if ( connection === 'close' ) {
298308 const statusCode = ( lastDisconnect ?. error as Boom ) ?. output ?. statusCode ;
299- const codesToNotReconnect = [ DisconnectReason . loggedOut , DisconnectReason . forbidden , 402 , 406 ] ;
309+ const codesToNotReconnect = [ DisconnectReason . forbidden , 402 , 406 ] ;
300310 const shouldReconnect = ! codesToNotReconnect . includes ( statusCode ) ;
301311 if ( shouldReconnect ) {
302312 await this . connectToWhatsapp ( this . phoneNumber ) ;
@@ -538,6 +548,7 @@ export class BaileysStartupService extends ChannelStartupService {
538548 public async connectToWhatsapp ( number ?: string ) : Promise < WASocket > {
539549 try {
540550 this . loadSettings ( ) ;
551+ this . loadWebhook ( ) ;
541552 this . loadProxy ( ) ;
542553
543554 return await this . createClient ( number ) ;
@@ -908,23 +919,37 @@ export class BaileysStartupService extends ChannelStartupService {
908919 } ) ;
909920 }
910921
911- if ( isMedia ) {
912- const buffer = await downloadMediaMessage (
913- { key : received . key , message : received ?. message } ,
914- 'buffer' ,
915- { } ,
916- {
917- logger : P ( { level : 'error' } ) as any ,
918- reuploadRequest : this . client . updateMediaMessage ,
919- } ,
920- ) ;
922+ if ( this . localWebhook . enabled ) {
923+ if ( isMedia && this . localWebhook . webhookBase64 ) {
924+ const buffer = await downloadMediaMessage (
925+ { key : received . key , message : received ?. message } ,
926+ 'buffer' ,
927+ { } ,
928+ {
929+ logger : P ( { level : 'error' } ) as any ,
930+ reuploadRequest : this . client . updateMediaMessage ,
931+ } ,
932+ ) ;
921933
922- messageRaw . message . base64 = buffer ? buffer . toString ( 'base64' ) : undefined ;
934+ messageRaw . message . base64 = buffer ? buffer . toString ( 'base64' ) : undefined ;
935+ }
923936 }
924937
925938 this . logger . log ( messageRaw ) ;
926939
927- this . sendDataWebhook ( Events . MESSAGES_UPSERT , messageRaw ) ;
940+ let messageWebhook = messageRaw ;
941+ let picUrl ;
942+
943+ if ( received . key . remoteJid . includes ( '@s.whatsapp' ) ) {
944+ picUrl = ( await this . profilePicture ( received . key . remoteJid ) ) . profilePictureUrl ;
945+
946+ messageWebhook = {
947+ ...messageRaw ,
948+ profilePictureUrl : picUrl ,
949+ } ;
950+ }
951+
952+ this . sendDataWebhook ( Events . MESSAGES_UPSERT , messageWebhook ) ;
928953
929954 const contact = await this . prismaRepository . contact . findFirst ( {
930955 where : { remoteJid : received . key . remoteJid , instanceId : this . instanceId } ,
@@ -933,7 +958,6 @@ export class BaileysStartupService extends ChannelStartupService {
933958 const contactRaw : { remoteJid : string ; pushName : string ; profilePicUrl ?: string ; instanceId : string } = {
934959 remoteJid : received . key . remoteJid ,
935960 pushName : received . key . fromMe ? '' : received . key . fromMe == null ? '' : received . pushName ,
936- profilePicUrl : ( await this . profilePicture ( received . key . remoteJid ) ) . profilePictureUrl ,
937961 instanceId : this . instanceId ,
938962 } ;
939963
@@ -1665,18 +1689,20 @@ export class BaileysStartupService extends ChannelStartupService {
16651689 } ) ;
16661690 }
16671691
1668- if ( isMedia ) {
1669- const buffer = await downloadMediaMessage (
1670- { key : messageRaw . key , message : messageRaw ?. message } ,
1671- 'buffer' ,
1672- { } ,
1673- {
1674- logger : P ( { level : 'error' } ) as any ,
1675- reuploadRequest : this . client . updateMediaMessage ,
1676- } ,
1677- ) ;
1692+ if ( this . localWebhook . enabled ) {
1693+ if ( isMedia && this . localWebhook . webhookBase64 ) {
1694+ const buffer = await downloadMediaMessage (
1695+ { key : messageRaw . key , message : messageRaw ?. message } ,
1696+ 'buffer' ,
1697+ { } ,
1698+ {
1699+ logger : P ( { level : 'error' } ) as any ,
1700+ reuploadRequest : this . client . updateMediaMessage ,
1701+ } ,
1702+ ) ;
16781703
1679- messageRaw . message . base64 = buffer ? buffer . toString ( 'base64' ) : undefined ;
1704+ messageRaw . message . base64 = buffer ? buffer . toString ( 'base64' ) : undefined ;
1705+ }
16801706 }
16811707
16821708 this . logger . log ( messageRaw ) ;
0 commit comments