Skip to content

Commit 8cb431a

Browse files
committed
Fixed cash when sending stickers via url
1 parent 77f98c2 commit 8cb431a

File tree

5 files changed

+13
-5
lines changed

5 files changed

+13
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Added timestamp internally in urls to avoid caching
66
* Correction in decryption of poll votes
77
* Change in the way the api sent and saved the sent messages, now it goes in the messages.upsert event
8+
* Fixed cash when sending stickers via url
89

910
# 1.1.2 (2023-06-28 13:43)
1011

docker-compose.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ services:
3939
- DATABASE_SAVE_MESSAGE_UPDATE=true
4040
- DATABASE_SAVE_DATA_CONTACTS=true
4141
- DATABASE_SAVE_DATA_CHATS=true
42-
- REDIS_ENABLED=false
42+
- REDIS_ENABLED=true
4343
- REDIS_URI=redis://redis:6379/1
4444
- REDIS_PREFIX_KEY=evolution
4545
# Webhook Settings

src/whatsapp/services/whatsapp.service.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,14 +1167,19 @@ export class WAStartupService {
11671167
imagePath = `${join(process.cwd(), 'temp', 'temp-sticker.png')}`;
11681168
await sharp(imageBuffer).toFile(imagePath);
11691169
} else {
1170-
const response = await axios.get(image, { responseType: 'arraybuffer' });
1170+
const timestamp = new Date().getTime();
1171+
const url = `${image}?timestamp=${timestamp}`;
1172+
1173+
const response = await axios.get(url, { responseType: 'arraybuffer' });
11711174
const imageBuffer = Buffer.from(response.data, 'binary');
11721175
imagePath = `${join(process.cwd(), 'temp', 'temp-sticker.png')}`;
11731176
await sharp(imageBuffer).toFile(imagePath);
11741177
}
11751178

11761179
await sharp(imagePath).webp().toFile(outputPath);
11771180

1181+
fs.unlinkSync(imagePath);
1182+
11781183
return outputPath;
11791184
} catch (error) {
11801185
console.error('Erro ao converter a imagem para WebP:', error);
@@ -1183,13 +1188,17 @@ export class WAStartupService {
11831188

11841189
public async mediaSticker(data: SendStickerDto) {
11851190
const convert = await this.convertToWebP(data.stickerMessage.image);
1186-
return await this.sendMessageWithTyping(
1191+
const result = await this.sendMessageWithTyping(
11871192
data.number,
11881193
{
11891194
sticker: { url: convert },
11901195
},
11911196
data?.options,
11921197
);
1198+
1199+
fs.unlinkSync(convert);
1200+
1201+
return result;
11931202
}
11941203

11951204
public async mediaMessage(data: SendMediaDto) {
@@ -1225,7 +1234,6 @@ export class WAStartupService {
12251234

12261235
return new Promise((resolve, reject) => {
12271236
exec(
1228-
// `${ffmpegPath.path} -i ${tempAudioPath} -c:a libopus ${outputAudio} -y`,
12291237
`${ffmpegPath.path} -i ${tempAudioPath} -vn -ab 128k -ar 44100 -f ipod ${outputAudio} -y`,
12301238
(error, _stdout, _stderr) => {
12311239
fs.unlinkSync(tempAudioPath);
@@ -1245,7 +1253,6 @@ export class WAStartupService {
12451253
{
12461254
audio: Buffer.from(audio, 'base64'),
12471255
ptt: true,
1248-
// mimetype: 'audio/ogg; codecs=opus',
12491256
mimetype: 'audio/mp4',
12501257
},
12511258
{ presence: 'recording', delay: data?.options?.delay },

temp/sticker.webp

-8.61 KB
Binary file not shown.

temp/sticker.webp_original

-8.42 KB
Binary file not shown.

0 commit comments

Comments
 (0)