Skip to content

Commit ea6a7c1

Browse files
committed
Merge branch 'release/1.1.4-1'
2 parents 9b59895 + 06cde72 commit ea6a7c1

File tree

8 files changed

+63
-49
lines changed

8 files changed

+63
-49
lines changed

Docker/.env.example

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ STORE_MESSAGES=true
1717
STORE_MESSAGE_UP=true
1818
STORE_CONTACTS=true
1919
STORE_CHATS=true
20+
2021
CLEAN_STORE_CLEANING_INTERVAL=7200 # seconds === 2h
2122
CLEAN_STORE_MESSAGES=true
2223
CLEAN_STORE_MESSAGE_UP=true
@@ -29,15 +30,15 @@ DATABASE_CONNECTION_URI=mongodb://root:root@mongodb:27017/?authSource=admin&read
2930
DATABASE_CONNECTION_DB_PREFIX_NAME=evolution
3031

3132
# Choose the data you want to save in the application's database or store
32-
DATABASE_SAVE_DATA_INSTANCE=true
33+
DATABASE_SAVE_DATA_INSTANCE=false
3334
DATABASE_SAVE_DATA_OLD_MESSAGE=false
34-
DATABASE_SAVE_DATA_NEW_MESSAGE=true
35-
DATABASE_SAVE_MESSAGE_UPDATE=true
36-
DATABASE_SAVE_DATA_CONTACTS=true
37-
DATABASE_SAVE_DATA_CHATS=true
35+
DATABASE_SAVE_DATA_NEW_MESSAGE=false
36+
DATABASE_SAVE_MESSAGE_UPDATE=false
37+
DATABASE_SAVE_DATA_CONTACTS=false
38+
DATABASE_SAVE_DATA_CHATS=false
3839

3940
REDIS_ENABLED=false
40-
REDIS_URI=redis://redis:6379/1
41+
REDIS_URI=redis://redis:6379
4142
REDIS_PREFIX_KEY=evolution
4243

4344
# Webhook Settings
@@ -65,10 +66,10 @@ WEBHOOK_EVENTS_GROUPS_UPDATE=true
6566
WEBHOOK_EVENTS_GROUP_PARTICIPANTS_UPDATE=true
6667
WEBHOOK_EVENTS_CONNECTION_UPDATE=true
6768
# This event fires every time a new token is requested via the refresh route
68-
WEBHOOK_EVENTS_NEW_JWT_TOKEN=true
69+
WEBHOOK_EVENTS_NEW_JWT_TOKEN=false
6970

7071
# Name that will be displayed on smartphone connection
71-
CONFIG_SESSION_PHONE_CLIENT=Evolution API
72+
CONFIG_SESSION_PHONE_CLIENT='Evolution API'
7273
CONFIG_SESSION_PHONE_NAME=chrome # chrome | firefox | edge | opera | safari
7374

7475
# Set qrcode display limit
@@ -88,4 +89,4 @@ AUTHENTICATION_JWT_SECRET='L0YWtjb2w554WFqPG'
8889
AUTHENTICATION_INSTANCE_MODE=server # container or server
8990
# if you are using container mode, set the container name and the webhook url to default instance
9091
AUTHENTICATION_INSTANCE_NAME=evolution
91-
AUTHENTICATION_INSTANCE_WEBHOOK_URL=<url>
92+
AUTHENTICATION_INSTANCE_WEBHOOK_URL='<url>'

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ ENV CORS_METHODS="POST,GET,PUT,DELETE"
2121
ENV CORS_CREDENTIALS=true
2222

2323
ENV LOG_LEVEL=$LOG_LEVEL
24-
ENV LOG_COLOR=true
24+
ENV LOG_COLOR=$LOG_COLOR
2525

2626
ENV DEL_INSTANCE=$DEL_INSTANCE
2727

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
<div align="center">
44

5-
[![Whatsapp Group](https://img.shields.io/badge/Group-WhatsApp-%2322BC18)](https://evolution-api.com/whatsapp)
6-
[![Postman Collection](https://img.shields.io/badge/Postman-Collection-orange)](https://evolution-api.com/docs/evolution-documentation/getting-started/postman-collection/)
7-
[![Documentation](https://img.shields.io/badge/Documentation-Official-green)](https://evolution-api.com)
5+
[![Whatsapp Group](https://img.shields.io/badge/Group-WhatsApp-%2322BC18)](https://evolution-api.com/whatsapp)
6+
[![Discord Community](https://img.shields.io/badge/Discord-Community-blue)](https://evolution-api.com/discord)
7+
[![Postman Collection](https://img.shields.io/badge/Postman-Collection-orange)](https://evolution-api.com/postman)
8+
[![Documentation](https://img.shields.io/badge/Documentation-Official-green)](https://doc.evolution-api.com)
89
[![License](https://img.shields.io/badge/license-GPL--3.0-orange)](./LICENSE)
910
[![Support](https://img.shields.io/badge/Buy%20me-coffe-orange)](https://app.picpay.com/user/davidsongomes1998)
1011

docker.sh

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ then
88
docker network create -d bridge ${NET}
99
fi
1010

11-
# sudo mkdir -p ./docker-data/instances
12-
# sudo mkdir -p ./docker-data/mongodb
13-
# sudo mkdir -p ./docker-data/mongodb/data
14-
# sudo mkdir -p ./docker-data/mongodb/configdb
15-
# sudo mkdir -p ./docker-data/redis
16-
# sudo mkdir -p ./docker-data/redis/data
17-
1811
docker build -t ${IMAGE} .
1912

2013
docker compose up -d

src/dev-env.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,36 +61,36 @@ CLEAN_STORE:
6161

6262
# Permanent data storage
6363
DATABASE:
64-
ENABLED: true
64+
ENABLED: false
6565
CONNECTION:
6666
URI: 'mongodb://root:root@localhost:27017/?authSource=admin&readPreference=primary&ssl=false&directConnection=true'
6767
DB_PREFIX_NAME: evolution
6868
# Choose the data you want to save in the application's database or store
6969
SAVE_DATA:
7070
INSTANCE: false
7171
OLD_MESSAGE: false
72-
NEW_MESSAGE: true
73-
MESSAGE_UPDATE: true
74-
CONTACTS: true
75-
CHATS: true
72+
NEW_MESSAGE: false
73+
MESSAGE_UPDATE: false
74+
CONTACTS: false
75+
CHATS: false
7676

7777
REDIS:
78-
ENABLED: true
79-
URI: 'redis://localhost:6379/1'
78+
ENABLED: false
79+
URI: 'redis://localhost:6379'
8080
PREFIX_KEY: 'evolution'
8181

8282
# Webhook Settings
8383
WEBHOOK:
8484
# Define a global webhook that will listen for enabled events from all instances
8585
GLOBAL:
8686
URL: <url>
87-
ENABLED: true
87+
ENABLED: false
8888
# With this option activated, you work with a url per webhook event, respecting the global url and the name of each event
8989
WEBHOOK_BY_EVENTS: false
9090
# Automatically maps webhook paths
9191
# Set the events you want to hear
9292
EVENTS:
93-
APPLICATION_STARTUP: true
93+
APPLICATION_STARTUP: false
9494
QRCODE_UPDATED: true
9595
MESSAGES_SET: true
9696
MESSAGES_UPSERT: true
@@ -108,7 +108,7 @@ WEBHOOK:
108108
GROUP_PARTICIPANTS_UPDATE: true
109109
CONNECTION_UPDATE: true
110110
# This event fires every time a new token is requested via the refresh route
111-
NEW_JWT_TOKEN: true
111+
NEW_JWT_TOKEN: false
112112

113113
CONFIG_SESSION_PHONE:
114114
# Name that will be displayed on smartphone connection

src/whatsapp/repository/repository.manager.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ export class RepositoryBroker {
6363

6464
this.logger.verbose('creating webhook path: ' + join(storePath, 'webhook'));
6565
execSync(`mkdir -p ${join(storePath, 'webhook')}`);
66+
67+
this.logger.verbose('creating temp path: ' + join(storePath, 'temp'));
68+
execSync(`mkdir -p ${join(storePath, 'temp')}`);
6669
}
6770
}
6871
}

src/whatsapp/services/whatsapp.service.ts

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -984,12 +984,20 @@ export class WAStartupService {
984984
if (
985985
key.remoteJid !== 'status@broadcast' &&
986986
!key?.remoteJid?.match(/(:\d+)/) &&
987-
!key.fromMe
987+
key.fromMe
988988
) {
989+
this.logger.verbose('Message update is valid');
990+
989991
let pollUpdates: any;
990992
if (update.pollUpdates) {
993+
this.logger.verbose('Poll update found');
994+
995+
this.logger.verbose('Getting poll message');
991996
const pollCreation = await this.getMessage(key);
997+
this.logger.verbose(pollCreation);
998+
992999
if (pollCreation) {
1000+
this.logger.verbose('Getting aggregate votes in poll message');
9931001
pollUpdates = getAggregateVotesInPollMessage({
9941002
message: pollCreation as proto.IMessage,
9951003
pollUpdates: update.pollUpdates,
@@ -1005,6 +1013,8 @@ export class WAStartupService {
10051013
pollUpdates,
10061014
};
10071015

1016+
this.logger.verbose(message);
1017+
10081018
this.logger.verbose('Sending data to webhook in event MESSAGES_UPDATE');
10091019
await this.sendDataWebhook(Events.MESSAGES_UPDATE, message);
10101020

@@ -1367,21 +1377,27 @@ export class WAStartupService {
13671377
);
13681378
})();
13691379

1370-
const messageRaw: proto.IWebMessageInfo = {
1380+
const messageRaw: MessageRaw = {
13711381
key: messageSent.key,
1372-
messageTimestamp: Long.isLong(messageSent.messageTimestamp)
1373-
? messageSent.messageTimestamp?.toNumber()
1374-
: messageSent.messageTimestamp,
13751382
pushName: messageSent.pushName,
1376-
broadcast: messageSent.broadcast,
1377-
status: 2,
13781383
message: { ...messageSent.message },
1384+
messageType: getContentType(messageSent.message),
1385+
messageTimestamp: messageSent.messageTimestamp as number,
1386+
owner: this.instance.name,
1387+
source: getDevice(messageSent.key.id),
13791388
};
13801389

1381-
this.client.ev.emit('messages.upsert', {
1382-
messages: [messageRaw],
1383-
type: 'notify',
1384-
});
1390+
this.logger.log(messageRaw);
1391+
1392+
this.logger.verbose('Sending data to webhook in event SEND_MESSAGE');
1393+
await this.sendDataWebhook(Events.SEND_MESSAGE, messageRaw);
1394+
1395+
this.logger.verbose('Inserting message in database');
1396+
await this.repository.message.insert(
1397+
[messageRaw],
1398+
this.instance.name,
1399+
this.configService.get<Database>('DATABASE').SAVE_DATA.NEW_MESSAGE,
1400+
);
13851401

13861402
return messageSent;
13871403
} catch (error) {
@@ -1628,15 +1644,15 @@ export class WAStartupService {
16281644
const hash = `${number}-${new Date().getTime()}`;
16291645
this.logger.verbose('Hash to image name: ' + hash);
16301646

1631-
const outputPath = `${join(process.cwd(), 'temp', `${hash}.webp`)}`;
1647+
const outputPath = `${join(this.storePath, 'temp', `${hash}.webp`)}`;
16321648
this.logger.verbose('Output path: ' + outputPath);
16331649

16341650
if (isBase64(image)) {
16351651
this.logger.verbose('Image is base64');
16361652

16371653
const base64Data = image.replace(/^data:image\/(jpeg|png|gif);base64,/, '');
16381654
const imageBuffer = Buffer.from(base64Data, 'base64');
1639-
imagePath = `${join(process.cwd(), 'temp', `temp-${hash}.png`)}`;
1655+
imagePath = `${join(this.storePath, 'temp', `temp-${hash}.png`)}`;
16401656
this.logger.verbose('Image path: ' + imagePath);
16411657

16421658
await sharp(imageBuffer).toFile(imagePath);
@@ -1652,7 +1668,7 @@ export class WAStartupService {
16521668
this.logger.verbose('Getting image from url');
16531669

16541670
const imageBuffer = Buffer.from(response.data, 'binary');
1655-
imagePath = `${join(process.cwd(), 'temp', `temp-${hash}.png`)}`;
1671+
imagePath = `${join(this.storePath, 'temp', `temp-${hash}.png`)}`;
16561672
this.logger.verbose('Image path: ' + imagePath);
16571673

16581674
await sharp(imageBuffer).toFile(imagePath);
@@ -1710,8 +1726,8 @@ export class WAStartupService {
17101726
if (isURL(audio)) {
17111727
this.logger.verbose('Audio is url');
17121728

1713-
outputAudio = `${join(process.cwd(), 'temp', `${hash}.mp4`)}`;
1714-
tempAudioPath = `${join(process.cwd(), 'temp', `temp-${hash}.mp3`)}`;
1729+
outputAudio = `${join(this.storePath, 'temp', `${hash}.mp4`)}`;
1730+
tempAudioPath = `${join(this.storePath, 'temp', `temp-${hash}.mp3`)}`;
17151731

17161732
this.logger.verbose('Output audio path: ' + outputAudio);
17171733
this.logger.verbose('Temp audio path: ' + tempAudioPath);
@@ -1725,12 +1741,11 @@ export class WAStartupService {
17251741
this.logger.verbose('Getting audio from url');
17261742

17271743
fs.writeFileSync(tempAudioPath, response.data);
1728-
this.logger.verbose('Temp audio created');
17291744
} else {
17301745
this.logger.verbose('Audio is base64');
17311746

1732-
outputAudio = `${join(process.cwd(), 'temp', `${hash}.mp4`)}`;
1733-
tempAudioPath = `${join(process.cwd(), 'temp', `temp-${hash}.mp3`)}`;
1747+
outputAudio = `${join(this.storePath, 'temp', `${hash}.mp4`)}`;
1748+
tempAudioPath = `${join(this.storePath, 'temp', `temp-${hash}.mp3`)}`;
17341749

17351750
this.logger.verbose('Output audio path: ' + outputAudio);
17361751
this.logger.verbose('Temp audio path: ' + tempAudioPath);

src/whatsapp/types/wa.types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ export enum Events {
66
QRCODE_UPDATED = 'qrcode.updated',
77
CONNECTION_UPDATE = 'connection.update',
88
STATUS_INSTANCE = 'status.instance',
9+
SEND_MESSAGE = 'send.message',
910
MESSAGES_SET = 'messages.set',
1011
MESSAGES_UPSERT = 'messages.upsert',
1112
MESSAGES_UPDATE = 'messages.update',

0 commit comments

Comments
 (0)