Skip to content

Commit db95de6

Browse files
committed
log verbose in file redis
1 parent bc2191e commit db95de6

1 file changed

Lines changed: 16 additions & 15 deletions

File tree

src/whatsapp/services/whatsapp.service.ts

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,24 +1230,24 @@ export class WAStartupService {
12301230
}
12311231
}
12321232

1233-
private async convertToWebP(image: string) {
1233+
private async convertToWebP(image: string, number: string) {
12341234
try {
12351235
let imagePath: string;
1236-
const timestamp = new Date().getTime();
1237-
const outputPath = `${join(process.cwd(), 'temp', `${timestamp}.webp`)}`;
1236+
const hash = `${number}-${new Date().getTime()}`;
1237+
const outputPath = `${join(process.cwd(), 'temp', `${hash}.webp`)}`;
12381238

12391239
if (isBase64(image)) {
12401240
const base64Data = image.replace(/^data:image\/(jpeg|png|gif);base64,/, '');
12411241
const imageBuffer = Buffer.from(base64Data, 'base64');
1242-
imagePath = `${join(process.cwd(), 'temp', `temp-${timestamp}.png`)}`;
1242+
imagePath = `${join(process.cwd(), 'temp', `temp-${hash}.png`)}`;
12431243
await sharp(imageBuffer).toFile(imagePath);
12441244
} else {
12451245
const timestamp = new Date().getTime();
12461246
const url = `${image}?timestamp=${timestamp}`;
12471247

12481248
const response = await axios.get(url, { responseType: 'arraybuffer' });
12491249
const imageBuffer = Buffer.from(response.data, 'binary');
1250-
imagePath = `${join(process.cwd(), 'temp', `temp-${timestamp}.png`)}`;
1250+
imagePath = `${join(process.cwd(), 'temp', `temp-${hash}.png`)}`;
12511251
await sharp(imageBuffer).toFile(imagePath);
12521252
}
12531253

@@ -1262,7 +1262,7 @@ export class WAStartupService {
12621262
}
12631263

12641264
public async mediaSticker(data: SendStickerDto) {
1265-
const convert = await this.convertToWebP(data.stickerMessage.image);
1265+
const convert = await this.convertToWebP(data.stickerMessage.image, data.number);
12661266
const result = await this.sendMessageWithTyping(
12671267
data.number,
12681268
{
@@ -1286,23 +1286,23 @@ export class WAStartupService {
12861286
);
12871287
}
12881288

1289-
private async processAudio(audio: string) {
1289+
private async processAudio(audio: string, number: string) {
12901290
let tempAudioPath: string;
12911291
let outputAudio: string;
1292+
const hash = `${number}-${new Date().getTime()}`;
12921293

12931294
if (isURL(audio)) {
1294-
const timestamp = new Date().getTime();
1295-
outputAudio = `${join(process.cwd(), 'temp', `${timestamp}.mp4`)}`;
1296-
tempAudioPath = `${join(process.cwd(), 'temp', `temp-${timestamp}.mp3`)}`;
1295+
outputAudio = `${join(process.cwd(), 'temp', `${hash}.mp4`)}`;
1296+
tempAudioPath = `${join(process.cwd(), 'temp', `temp-${hash}.mp3`)}`;
12971297

1298+
const timestamp = new Date().getTime();
12981299
const url = `${audio}?timestamp=${timestamp}`;
12991300

13001301
const response = await axios.get(url, { responseType: 'arraybuffer' });
13011302
fs.writeFileSync(tempAudioPath, response.data);
13021303
} else {
1303-
const timestamp = new Date().getTime();
1304-
outputAudio = `${join(process.cwd(), 'temp', `${timestamp}.mp4`)}`;
1305-
tempAudioPath = `${join(process.cwd(), 'temp', `temp-${timestamp}.mp3`)}`;
1304+
outputAudio = `${join(process.cwd(), 'temp', `${hash}.mp4`)}`;
1305+
tempAudioPath = `${join(process.cwd(), 'temp', `temp-${hash}.mp3`)}`;
13061306

13071307
const audioBuffer = Buffer.from(audio, 'base64');
13081308
fs.writeFileSync(tempAudioPath, audioBuffer);
@@ -1321,7 +1321,7 @@ export class WAStartupService {
13211321
}
13221322

13231323
public async audioWhatsapp(data: SendAudioDto) {
1324-
const convert = await this.processAudio(data.audioMessage.audio);
1324+
const convert = await this.processAudio(data.audioMessage.audio, data.number);
13251325
if (typeof convert === 'string') {
13261326
const audio = fs.readFileSync(convert).toString('base64');
13271327
const result = this.sendMessageWithTyping<AnyMessageContent>(
@@ -1600,7 +1600,8 @@ export class WAStartupService {
16001600

16011601
// if for audioMessage converte para mp3
16021602
if (convertToMp4 && typeMessage === 'audioMessage') {
1603-
const convert = await this.processAudio(buffer.toString('base64'));
1603+
const number = msg.key.remoteJid.split('@')[0];
1604+
const convert = await this.processAudio(buffer.toString('base64'), number);
16041605

16051606
if (typeof convert === 'string') {
16061607
const audio = fs.readFileSync(convert).toString('base64');

0 commit comments

Comments
 (0)