Merge branch 'release/1.1.4-1'

This commit is contained in:
Davidson Gomes 2023-07-12 07:17:05 -03:00
commit ea6a7c1c87
8 changed files with 63 additions and 49 deletions

View File

@ -17,6 +17,7 @@ STORE_MESSAGES=true
STORE_MESSAGE_UP=true STORE_MESSAGE_UP=true
STORE_CONTACTS=true STORE_CONTACTS=true
STORE_CHATS=true STORE_CHATS=true
CLEAN_STORE_CLEANING_INTERVAL=7200 # seconds === 2h CLEAN_STORE_CLEANING_INTERVAL=7200 # seconds === 2h
CLEAN_STORE_MESSAGES=true CLEAN_STORE_MESSAGES=true
CLEAN_STORE_MESSAGE_UP=true CLEAN_STORE_MESSAGE_UP=true
@ -29,15 +30,15 @@ DATABASE_CONNECTION_URI=mongodb://root:root@mongodb:27017/?authSource=admin&read
DATABASE_CONNECTION_DB_PREFIX_NAME=evolution DATABASE_CONNECTION_DB_PREFIX_NAME=evolution
# Choose the data you want to save in the application's database or store # Choose the data you want to save in the application's database or store
DATABASE_SAVE_DATA_INSTANCE=true DATABASE_SAVE_DATA_INSTANCE=false
DATABASE_SAVE_DATA_OLD_MESSAGE=false DATABASE_SAVE_DATA_OLD_MESSAGE=false
DATABASE_SAVE_DATA_NEW_MESSAGE=true DATABASE_SAVE_DATA_NEW_MESSAGE=false
DATABASE_SAVE_MESSAGE_UPDATE=true DATABASE_SAVE_MESSAGE_UPDATE=false
DATABASE_SAVE_DATA_CONTACTS=true DATABASE_SAVE_DATA_CONTACTS=false
DATABASE_SAVE_DATA_CHATS=true DATABASE_SAVE_DATA_CHATS=false
REDIS_ENABLED=false REDIS_ENABLED=false
REDIS_URI=redis://redis:6379/1 REDIS_URI=redis://redis:6379
REDIS_PREFIX_KEY=evolution REDIS_PREFIX_KEY=evolution
# Webhook Settings # Webhook Settings
@ -65,10 +66,10 @@ WEBHOOK_EVENTS_GROUPS_UPDATE=true
WEBHOOK_EVENTS_GROUP_PARTICIPANTS_UPDATE=true WEBHOOK_EVENTS_GROUP_PARTICIPANTS_UPDATE=true
WEBHOOK_EVENTS_CONNECTION_UPDATE=true WEBHOOK_EVENTS_CONNECTION_UPDATE=true
# This event fires every time a new token is requested via the refresh route # This event fires every time a new token is requested via the refresh route
WEBHOOK_EVENTS_NEW_JWT_TOKEN=true WEBHOOK_EVENTS_NEW_JWT_TOKEN=false
# Name that will be displayed on smartphone connection # Name that will be displayed on smartphone connection
CONFIG_SESSION_PHONE_CLIENT=Evolution API CONFIG_SESSION_PHONE_CLIENT='Evolution API'
CONFIG_SESSION_PHONE_NAME=chrome # chrome | firefox | edge | opera | safari CONFIG_SESSION_PHONE_NAME=chrome # chrome | firefox | edge | opera | safari
# Set qrcode display limit # Set qrcode display limit
@ -88,4 +89,4 @@ AUTHENTICATION_JWT_SECRET='L0YWtjb2w554WFqPG'
AUTHENTICATION_INSTANCE_MODE=server # container or server AUTHENTICATION_INSTANCE_MODE=server # container or server
# if you are using container mode, set the container name and the webhook url to default instance # if you are using container mode, set the container name and the webhook url to default instance
AUTHENTICATION_INSTANCE_NAME=evolution AUTHENTICATION_INSTANCE_NAME=evolution
AUTHENTICATION_INSTANCE_WEBHOOK_URL=<url> AUTHENTICATION_INSTANCE_WEBHOOK_URL='<url>'

View File

@ -21,7 +21,7 @@ ENV CORS_METHODS="POST,GET,PUT,DELETE"
ENV CORS_CREDENTIALS=true ENV CORS_CREDENTIALS=true
ENV LOG_LEVEL=$LOG_LEVEL ENV LOG_LEVEL=$LOG_LEVEL
ENV LOG_COLOR=true ENV LOG_COLOR=$LOG_COLOR
ENV DEL_INSTANCE=$DEL_INSTANCE ENV DEL_INSTANCE=$DEL_INSTANCE

View File

@ -2,9 +2,10 @@
<div align="center"> <div align="center">
[![Whatsapp Group](https://img.shields.io/badge/Group-WhatsApp-%2322BC18)](https://evolution-api.com/whatsapp) [![Whatsapp Group](https://img.shields.io/badge/Group-WhatsApp-%2322BC18)](https://evolution-api.com/whatsapp)
[![Postman Collection](https://img.shields.io/badge/Postman-Collection-orange)](https://evolution-api.com/docs/evolution-documentation/getting-started/postman-collection/) [![Discord Community](https://img.shields.io/badge/Discord-Community-blue)](https://evolution-api.com/discord)
[![Documentation](https://img.shields.io/badge/Documentation-Official-green)](https://evolution-api.com) [![Postman Collection](https://img.shields.io/badge/Postman-Collection-orange)](https://evolution-api.com/postman)
[![Documentation](https://img.shields.io/badge/Documentation-Official-green)](https://doc.evolution-api.com)
[![License](https://img.shields.io/badge/license-GPL--3.0-orange)](./LICENSE) [![License](https://img.shields.io/badge/license-GPL--3.0-orange)](./LICENSE)
[![Support](https://img.shields.io/badge/Buy%20me-coffe-orange)](https://app.picpay.com/user/davidsongomes1998) [![Support](https://img.shields.io/badge/Buy%20me-coffe-orange)](https://app.picpay.com/user/davidsongomes1998)

View File

@ -8,13 +8,6 @@ then
docker network create -d bridge ${NET} docker network create -d bridge ${NET}
fi fi
# sudo mkdir -p ./docker-data/instances
# sudo mkdir -p ./docker-data/mongodb
# sudo mkdir -p ./docker-data/mongodb/data
# sudo mkdir -p ./docker-data/mongodb/configdb
# sudo mkdir -p ./docker-data/redis
# sudo mkdir -p ./docker-data/redis/data
docker build -t ${IMAGE} . docker build -t ${IMAGE} .
docker compose up -d docker compose up -d

View File

@ -61,7 +61,7 @@ CLEAN_STORE:
# Permanent data storage # Permanent data storage
DATABASE: DATABASE:
ENABLED: true ENABLED: false
CONNECTION: CONNECTION:
URI: 'mongodb://root:root@localhost:27017/?authSource=admin&readPreference=primary&ssl=false&directConnection=true' URI: 'mongodb://root:root@localhost:27017/?authSource=admin&readPreference=primary&ssl=false&directConnection=true'
DB_PREFIX_NAME: evolution DB_PREFIX_NAME: evolution
@ -69,14 +69,14 @@ DATABASE:
SAVE_DATA: SAVE_DATA:
INSTANCE: false INSTANCE: false
OLD_MESSAGE: false OLD_MESSAGE: false
NEW_MESSAGE: true NEW_MESSAGE: false
MESSAGE_UPDATE: true MESSAGE_UPDATE: false
CONTACTS: true CONTACTS: false
CHATS: true CHATS: false
REDIS: REDIS:
ENABLED: true ENABLED: false
URI: 'redis://localhost:6379/1' URI: 'redis://localhost:6379'
PREFIX_KEY: 'evolution' PREFIX_KEY: 'evolution'
# Webhook Settings # Webhook Settings
@ -84,13 +84,13 @@ WEBHOOK:
# Define a global webhook that will listen for enabled events from all instances # Define a global webhook that will listen for enabled events from all instances
GLOBAL: GLOBAL:
URL: <url> URL: <url>
ENABLED: true ENABLED: false
# With this option activated, you work with a url per webhook event, respecting the global url and the name of each event # With this option activated, you work with a url per webhook event, respecting the global url and the name of each event
WEBHOOK_BY_EVENTS: false WEBHOOK_BY_EVENTS: false
# Automatically maps webhook paths # Automatically maps webhook paths
# Set the events you want to hear # Set the events you want to hear
EVENTS: EVENTS:
APPLICATION_STARTUP: true APPLICATION_STARTUP: false
QRCODE_UPDATED: true QRCODE_UPDATED: true
MESSAGES_SET: true MESSAGES_SET: true
MESSAGES_UPSERT: true MESSAGES_UPSERT: true
@ -108,7 +108,7 @@ WEBHOOK:
GROUP_PARTICIPANTS_UPDATE: true GROUP_PARTICIPANTS_UPDATE: true
CONNECTION_UPDATE: true CONNECTION_UPDATE: true
# This event fires every time a new token is requested via the refresh route # This event fires every time a new token is requested via the refresh route
NEW_JWT_TOKEN: true NEW_JWT_TOKEN: false
CONFIG_SESSION_PHONE: CONFIG_SESSION_PHONE:
# Name that will be displayed on smartphone connection # Name that will be displayed on smartphone connection

View File

@ -63,6 +63,9 @@ export class RepositoryBroker {
this.logger.verbose('creating webhook path: ' + join(storePath, 'webhook')); this.logger.verbose('creating webhook path: ' + join(storePath, 'webhook'));
execSync(`mkdir -p ${join(storePath, 'webhook')}`); execSync(`mkdir -p ${join(storePath, 'webhook')}`);
this.logger.verbose('creating temp path: ' + join(storePath, 'temp'));
execSync(`mkdir -p ${join(storePath, 'temp')}`);
} }
} }
} }

View File

@ -984,12 +984,20 @@ export class WAStartupService {
if ( if (
key.remoteJid !== 'status@broadcast' && key.remoteJid !== 'status@broadcast' &&
!key?.remoteJid?.match(/(:\d+)/) && !key?.remoteJid?.match(/(:\d+)/) &&
!key.fromMe key.fromMe
) { ) {
this.logger.verbose('Message update is valid');
let pollUpdates: any; let pollUpdates: any;
if (update.pollUpdates) { if (update.pollUpdates) {
this.logger.verbose('Poll update found');
this.logger.verbose('Getting poll message');
const pollCreation = await this.getMessage(key); const pollCreation = await this.getMessage(key);
this.logger.verbose(pollCreation);
if (pollCreation) { if (pollCreation) {
this.logger.verbose('Getting aggregate votes in poll message');
pollUpdates = getAggregateVotesInPollMessage({ pollUpdates = getAggregateVotesInPollMessage({
message: pollCreation as proto.IMessage, message: pollCreation as proto.IMessage,
pollUpdates: update.pollUpdates, pollUpdates: update.pollUpdates,
@ -1005,6 +1013,8 @@ export class WAStartupService {
pollUpdates, pollUpdates,
}; };
this.logger.verbose(message);
this.logger.verbose('Sending data to webhook in event MESSAGES_UPDATE'); this.logger.verbose('Sending data to webhook in event MESSAGES_UPDATE');
await this.sendDataWebhook(Events.MESSAGES_UPDATE, message); await this.sendDataWebhook(Events.MESSAGES_UPDATE, message);
@ -1367,21 +1377,27 @@ export class WAStartupService {
); );
})(); })();
const messageRaw: proto.IWebMessageInfo = { const messageRaw: MessageRaw = {
key: messageSent.key, key: messageSent.key,
messageTimestamp: Long.isLong(messageSent.messageTimestamp)
? messageSent.messageTimestamp?.toNumber()
: messageSent.messageTimestamp,
pushName: messageSent.pushName, pushName: messageSent.pushName,
broadcast: messageSent.broadcast,
status: 2,
message: { ...messageSent.message }, message: { ...messageSent.message },
messageType: getContentType(messageSent.message),
messageTimestamp: messageSent.messageTimestamp as number,
owner: this.instance.name,
source: getDevice(messageSent.key.id),
}; };
this.client.ev.emit('messages.upsert', { this.logger.log(messageRaw);
messages: [messageRaw],
type: 'notify', this.logger.verbose('Sending data to webhook in event SEND_MESSAGE');
}); await this.sendDataWebhook(Events.SEND_MESSAGE, messageRaw);
this.logger.verbose('Inserting message in database');
await this.repository.message.insert(
[messageRaw],
this.instance.name,
this.configService.get<Database>('DATABASE').SAVE_DATA.NEW_MESSAGE,
);
return messageSent; return messageSent;
} catch (error) { } catch (error) {
@ -1628,7 +1644,7 @@ export class WAStartupService {
const hash = `${number}-${new Date().getTime()}`; const hash = `${number}-${new Date().getTime()}`;
this.logger.verbose('Hash to image name: ' + hash); this.logger.verbose('Hash to image name: ' + hash);
const outputPath = `${join(process.cwd(), 'temp', `${hash}.webp`)}`; const outputPath = `${join(this.storePath, 'temp', `${hash}.webp`)}`;
this.logger.verbose('Output path: ' + outputPath); this.logger.verbose('Output path: ' + outputPath);
if (isBase64(image)) { if (isBase64(image)) {
@ -1636,7 +1652,7 @@ export class WAStartupService {
const base64Data = image.replace(/^data:image\/(jpeg|png|gif);base64,/, ''); const base64Data = image.replace(/^data:image\/(jpeg|png|gif);base64,/, '');
const imageBuffer = Buffer.from(base64Data, 'base64'); const imageBuffer = Buffer.from(base64Data, 'base64');
imagePath = `${join(process.cwd(), 'temp', `temp-${hash}.png`)}`; imagePath = `${join(this.storePath, 'temp', `temp-${hash}.png`)}`;
this.logger.verbose('Image path: ' + imagePath); this.logger.verbose('Image path: ' + imagePath);
await sharp(imageBuffer).toFile(imagePath); await sharp(imageBuffer).toFile(imagePath);
@ -1652,7 +1668,7 @@ export class WAStartupService {
this.logger.verbose('Getting image from url'); this.logger.verbose('Getting image from url');
const imageBuffer = Buffer.from(response.data, 'binary'); const imageBuffer = Buffer.from(response.data, 'binary');
imagePath = `${join(process.cwd(), 'temp', `temp-${hash}.png`)}`; imagePath = `${join(this.storePath, 'temp', `temp-${hash}.png`)}`;
this.logger.verbose('Image path: ' + imagePath); this.logger.verbose('Image path: ' + imagePath);
await sharp(imageBuffer).toFile(imagePath); await sharp(imageBuffer).toFile(imagePath);
@ -1710,8 +1726,8 @@ export class WAStartupService {
if (isURL(audio)) { if (isURL(audio)) {
this.logger.verbose('Audio is url'); this.logger.verbose('Audio is url');
outputAudio = `${join(process.cwd(), 'temp', `${hash}.mp4`)}`; outputAudio = `${join(this.storePath, 'temp', `${hash}.mp4`)}`;
tempAudioPath = `${join(process.cwd(), 'temp', `temp-${hash}.mp3`)}`; tempAudioPath = `${join(this.storePath, 'temp', `temp-${hash}.mp3`)}`;
this.logger.verbose('Output audio path: ' + outputAudio); this.logger.verbose('Output audio path: ' + outputAudio);
this.logger.verbose('Temp audio path: ' + tempAudioPath); this.logger.verbose('Temp audio path: ' + tempAudioPath);
@ -1725,12 +1741,11 @@ export class WAStartupService {
this.logger.verbose('Getting audio from url'); this.logger.verbose('Getting audio from url');
fs.writeFileSync(tempAudioPath, response.data); fs.writeFileSync(tempAudioPath, response.data);
this.logger.verbose('Temp audio created');
} else { } else {
this.logger.verbose('Audio is base64'); this.logger.verbose('Audio is base64');
outputAudio = `${join(process.cwd(), 'temp', `${hash}.mp4`)}`; outputAudio = `${join(this.storePath, 'temp', `${hash}.mp4`)}`;
tempAudioPath = `${join(process.cwd(), 'temp', `temp-${hash}.mp3`)}`; tempAudioPath = `${join(this.storePath, 'temp', `temp-${hash}.mp3`)}`;
this.logger.verbose('Output audio path: ' + outputAudio); this.logger.verbose('Output audio path: ' + outputAudio);
this.logger.verbose('Temp audio path: ' + tempAudioPath); this.logger.verbose('Temp audio path: ' + tempAudioPath);

View File

@ -6,6 +6,7 @@ export enum Events {
QRCODE_UPDATED = 'qrcode.updated', QRCODE_UPDATED = 'qrcode.updated',
CONNECTION_UPDATE = 'connection.update', CONNECTION_UPDATE = 'connection.update',
STATUS_INSTANCE = 'status.instance', STATUS_INSTANCE = 'status.instance',
SEND_MESSAGE = 'send.message',
MESSAGES_SET = 'messages.set', MESSAGES_SET = 'messages.set',
MESSAGES_UPSERT = 'messages.upsert', MESSAGES_UPSERT = 'messages.upsert',
MESSAGES_UPDATE = 'messages.update', MESSAGES_UPDATE = 'messages.update',