@@ -41,6 +41,7 @@ import makeWASocket, {
4141 AnyMessageContent ,
4242 BaileysEventMap ,
4343 BufferedEventData ,
44+ BufferJSON ,
4445 Chat ,
4546 ConnectionState ,
4647 Contact ,
@@ -123,7 +124,6 @@ import {
123124 GroupUpdateParticipantDto ,
124125} from '../dto/group.dto' ;
125126import Long from 'long' ;
126- import NodeCache from 'node-cache' ;
127127import {
128128 AuthState ,
129129 AuthStateProvider ,
@@ -150,6 +150,7 @@ import {
150150 writeFileSync ,
151151} from 'fs' ;
152152import { fetchLatestBaileysVersionV2 } from '../../utils/wa-version' ;
153+ import { toBase64 } from '../../utils/to-base64' ;
153154
154155type InstanceQrCode = {
155156 count : number ;
@@ -475,7 +476,7 @@ export class WAStartupService {
475476
476477 private async getMessage ( key : PrismType . Message , full = false ) {
477478 try {
478- key . instanceId = this . instance . id ;
479+ // key.instanceId = this.instance.id;
479480 const message = await this . repository . message . findFirst ( {
480481 where : key as any ,
481482 } ) ;
@@ -489,6 +490,13 @@ export class WAStartupService {
489490 [ message . messageType ] : message . content ,
490491 } ,
491492 } ;
493+
494+ if ( webMessageInfo . message [ message . messageType ] ?. mediaKey ) {
495+ webMessageInfo . message [ message . messageType ] . mediaKey = toBase64 (
496+ webMessageInfo . message ?. [ message . messageType ] ?. mediaKey as any ,
497+ ) ;
498+ }
499+
492500 if ( full ) {
493501 return webMessageInfo ;
494502 }
@@ -888,7 +896,7 @@ export class WAStartupService {
888896
889897 if ( this . databaseOptions . DB_OPTIONS . NEW_MESSAGE ) {
890898 const { id } = await this . repository . message . create ( {
891- data : JSON . parse ( JSON . stringify ( messageRaw ) as any ) ,
899+ data : JSON . parse ( JSON . stringify ( messageRaw , BufferJSON . replacer ) as any ) ,
892900 } ) ;
893901 messageRaw . id = id ;
894902 }
@@ -1355,7 +1363,7 @@ export class WAStartupService {
13551363 } ) ( ) ;
13561364 if ( this . databaseOptions . DB_OPTIONS . NEW_MESSAGE ) {
13571365 const { id } = await this . repository . message . create ( {
1358- data : JSON . parse ( JSON . stringify ( messageSent ) ) as any ,
1366+ data : JSON . parse ( JSON . stringify ( messageSent , BufferJSON . replacer ) ) as any ,
13591367 } ) ;
13601368 messageSent . id = id ;
13611369 }
@@ -2195,10 +2203,6 @@ export class WAStartupService {
21952203 throw 'The message is not of the media type' ;
21962204 }
21972205
2198- if ( typeof mediaMessage [ 'mediaKey' ] === 'object' ) {
2199- msg . message = JSON . parse ( JSON . stringify ( msg . message ) ) ;
2200- }
2201-
22022206 const stream = await downloadMediaMessage (
22032207 { key : msg ?. key , message : msg ?. message } ,
22042208 'stream' ,
@@ -2244,7 +2248,8 @@ export class WAStartupService {
22442248 if ( inner ) {
22452249 return ;
22462250 }
2247- throw new BadRequestException ( error . toString ( ) ) ;
2251+ const boom = error as Boom ;
2252+ throw new BadRequestException ( error . toString ( ) , boom ?. output ) ;
22482253 }
22492254 }
22502255
0 commit comments