@@ -153,6 +153,7 @@ import {
153153} from 'fs' ;
154154import { createProxyAgents } from '../../utils/proxy' ;
155155import { fetchLatestBaileysVersionV2 } from '../../utils/wa-version' ;
156+ import { getJidUser , getUserGroup } from '../../utils/extract-id' ;
156157
157158type InstanceQrCode = {
158159 count : number ;
@@ -844,14 +845,17 @@ export class WAStartupService {
844845 continue ;
845846 }
846847
848+ const user = getJidUser ( m . key ) ;
849+ const group = getUserGroup ( m . key , m ?. participant ) ;
850+
847851 messagesRaw . push ( {
848852 keyId : m . key . id ,
849853 keyFromMe : m . key . fromMe ,
850854 pushName : m ?. pushName || m . key . remoteJid . split ( '@' ) [ 0 ] ,
851- keyRemoteJid : m . key ?. remoteJid ,
852- keyLid : m . key ?. [ 'senderLid' ] || m . key ?. [ 'senderPn' ] ,
853- keyParticipant : m ?. participant || m . key ?. participant ,
854- keyParticipantLid : m . key ?. [ 'participantLid' ] || m . key ?. [ 'participantPn' ] ,
855+ keyRemoteJid : user ?. jid ,
856+ keyLid : user ?. lid ,
857+ keyParticipant : group ?. jid ,
858+ keyParticipantLid : group ?. lid ,
855859 messageType,
856860 content : m . message [ messageType ] as PrismType . Prisma . JsonValue ,
857861 messageTimestamp : timestamp ,
@@ -874,7 +878,7 @@ export class WAStartupService {
874878 messages,
875879 type,
876880 } : {
877- messages : proto . IWebMessageInfo [ ] ;
881+ messages : WAMessage [ ] ;
878882 type : MessageUpsertType ;
879883 } ) => {
880884 for ( const received of messages ) {
@@ -925,15 +929,17 @@ export class WAStartupService {
925929 }
926930 }
927931
932+ const user = getJidUser ( received . key ) ;
933+ const group = getUserGroup ( received . key , received ?. participant ) ;
934+
928935 const messageRaw = {
929936 keyId : received . key . id ,
930937 keyFromMe : received . key . fromMe ,
931938 pushName : received . pushName ,
932- keyRemoteJid : received . key ?. remoteJid ,
933- keyLid : received . key ?. [ 'senderLid' ] || received . key ?. [ 'senderPn' ] ,
934- keyParticipant : received ?. participant || received . key ?. participant ,
935- keyParticipantLid :
936- received . key ?. [ 'participantLid' ] || received . key ?. [ 'participantPn' ] ,
939+ keyRemoteJid : user ?. jid ,
940+ keyLid : user ?. lid ,
941+ keyParticipant : group ?. jid ,
942+ keyParticipantLid : group ?. lid ,
937943 messageType,
938944 content : JSON . parse (
939945 JSON . stringify ( received . message [ messageType ] ) ,
@@ -1242,11 +1248,8 @@ export class WAStartupService {
12421248 }
12431249
12441250 private createJid ( number : string ) : string {
1245- if (
1246- number . includes ( '@g.us' ) ||
1247- number . includes ( '@s.whatsapp.net' ) ||
1248- number . includes ( '@lid' )
1249- ) {
1251+ const regexp = new RegExp ( / ^ \d + @ ( s .w h a t s a p p .n e t | g .u s | l i d | b r o a d c a s t | n e w s l e t t e r ) $ / i) ;
1252+ if ( regexp . test ( number ) ) {
12501253 return number ;
12511254 }
12521255
0 commit comments