@@ -70,6 +70,7 @@ import { BadRequestException, InternalServerErrorException, NotFoundException }
70
70
import ffmpegPath from '@ffmpeg-installer/ffmpeg' ;
71
71
import { Boom } from '@hapi/boom' ;
72
72
import { Instance } from '@prisma/client' ;
73
+ import { deleteTempFile , getTempFile } from '@utils/getTempFile' ;
73
74
import { makeProxyAgent } from '@utils/makeProxyAgent' ;
74
75
import { getOnWhatsappCache , saveOnWhatsappCache } from '@utils/onWhatsappCache' ;
75
76
import useMultiFileAuthStatePrisma from '@utils/use-multi-file-auth-state-prisma' ;
@@ -2266,12 +2267,20 @@ export class BaileysStartupService extends ChannelStartupService {
2266
2267
throw new BadRequestException ( 'Type not found' ) ;
2267
2268
}
2268
2269
2269
- public async statusMessage ( data : SendStatusDto ) {
2270
- const status = await this . formatStatusMessage ( data ) ;
2270
+ public async statusMessage ( data : SendStatusDto , file ?: any ) {
2271
+ const mediaData : SendStatusDto = { ... data } ;
2271
2272
2272
- return await this . sendMessageWithTyping ( 'status@broadcast' , {
2273
+ if ( file ) mediaData . content = await getTempFile ( file , this . instanceId ) ;
2274
+
2275
+ const status = await this . formatStatusMessage ( mediaData ) ;
2276
+
2277
+ const statusSent = await this . sendMessageWithTyping ( 'status@broadcast' , {
2273
2278
status,
2274
2279
} ) ;
2280
+
2281
+ if ( file ) await deleteTempFile ( file , this . instanceId ) ;
2282
+
2283
+ return statusSent ;
2275
2284
}
2276
2285
2277
2286
private async prepareMediaMessage ( mediaMessage : MediaMessage ) {
@@ -2395,7 +2404,11 @@ export class BaileysStartupService extends ChannelStartupService {
2395
2404
}
2396
2405
}
2397
2406
2398
- public async mediaSticker ( data : SendStickerDto ) {
2407
+ public async mediaSticker ( data : SendStickerDto , file ?: any ) {
2408
+ const mediaData : SendStickerDto = { ...data } ;
2409
+
2410
+ if ( file ) mediaData . sticker = await getTempFile ( file , this . instanceId ) ;
2411
+
2399
2412
const convert = await this . convertToWebP ( data . sticker ) ;
2400
2413
const gifPlayback = data . sticker . includes ( '.gif' ) ;
2401
2414
const result = await this . sendMessageWithTyping (
@@ -2413,13 +2426,19 @@ export class BaileysStartupService extends ChannelStartupService {
2413
2426
} ,
2414
2427
) ;
2415
2428
2429
+ if ( file ) await deleteTempFile ( file , this . instanceId ) ;
2430
+
2416
2431
return result ;
2417
2432
}
2418
2433
2419
- public async mediaMessage ( data : SendMediaDto , isIntegration = false ) {
2420
- const generate = await this . prepareMediaMessage ( data ) ;
2434
+ public async mediaMessage ( data : SendMediaDto , file ?: any , isIntegration = false ) {
2435
+ const mediaData : SendMediaDto = { ... data } ;
2421
2436
2422
- return await this . sendMessageWithTyping (
2437
+ if ( file ) mediaData . media = await getTempFile ( file , this . instanceId ) ;
2438
+
2439
+ const generate = await this . prepareMediaMessage ( mediaData ) ;
2440
+
2441
+ const mediaSent = await this . sendMessageWithTyping (
2423
2442
data . number ,
2424
2443
{ ...generate . message } ,
2425
2444
{
@@ -2431,6 +2450,10 @@ export class BaileysStartupService extends ChannelStartupService {
2431
2450
} ,
2432
2451
isIntegration ,
2433
2452
) ;
2453
+
2454
+ if ( file ) await deleteTempFile ( file , this . instanceId ) ;
2455
+
2456
+ return mediaSent ;
2434
2457
}
2435
2458
2436
2459
public async processAudioMp4 ( audio : string ) {
@@ -2534,13 +2557,17 @@ export class BaileysStartupService extends ChannelStartupService {
2534
2557
} ) ;
2535
2558
}
2536
2559
2537
- public async audioWhatsapp ( data : SendAudioDto , isIntegration = false ) {
2560
+ public async audioWhatsapp ( data : SendAudioDto , file ?: any , isIntegration = false ) {
2561
+ const mediaData : SendAudioDto = { ...data } ;
2562
+
2563
+ if ( file ) mediaData . audio = await getTempFile ( file , this . instanceId ) ;
2564
+
2538
2565
if ( ! data ?. encoding && data ?. encoding !== false ) {
2539
2566
data . encoding = true ;
2540
2567
}
2541
2568
2542
2569
if ( data ?. encoding ) {
2543
- const convert = await this . processAudio ( data . audio ) ;
2570
+ const convert = await this . processAudio ( mediaData . audio ) ;
2544
2571
2545
2572
if ( Buffer . isBuffer ( convert ) ) {
2546
2573
const result = this . sendMessageWithTyping < AnyMessageContent > (
@@ -2554,6 +2581,8 @@ export class BaileysStartupService extends ChannelStartupService {
2554
2581
isIntegration ,
2555
2582
) ;
2556
2583
2584
+ if ( file ) await deleteTempFile ( file , this . instanceId ) ;
2585
+
2557
2586
return result ;
2558
2587
} else {
2559
2588
throw new InternalServerErrorException ( 'Failed to convert audio' ) ;
0 commit comments