fix: adjusts in temp folder and return with event send_messages

This commit is contained in:
Davidson Gomes 2023-07-12 07:05:18 -03:00
parent 1b52bdf425
commit 31486e5963
8 changed files with 68 additions and 48 deletions

View File

@ -17,6 +17,7 @@ STORE_MESSAGES=true
STORE_MESSAGE_UP=true
STORE_CONTACTS=true
STORE_CHATS=true
CLEAN_STORE_CLEANING_INTERVAL=7200 # seconds === 2h
CLEAN_STORE_MESSAGES=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
# 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_NEW_MESSAGE=true
DATABASE_SAVE_MESSAGE_UPDATE=true
DATABASE_SAVE_DATA_CONTACTS=true
DATABASE_SAVE_DATA_CHATS=true
DATABASE_SAVE_DATA_NEW_MESSAGE=false
DATABASE_SAVE_MESSAGE_UPDATE=false
DATABASE_SAVE_DATA_CONTACTS=false
DATABASE_SAVE_DATA_CHATS=false
REDIS_ENABLED=false
REDIS_URI=redis://redis:6379/1
REDIS_URI=redis://redis:6379
REDIS_PREFIX_KEY=evolution
# Webhook Settings
@ -65,10 +66,10 @@ WEBHOOK_EVENTS_GROUPS_UPDATE=true
WEBHOOK_EVENTS_GROUP_PARTICIPANTS_UPDATE=true
WEBHOOK_EVENTS_CONNECTION_UPDATE=true
# 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
CONFIG_SESSION_PHONE_CLIENT=Evolution API
CONFIG_SESSION_PHONE_CLIENT='Evolution API'
CONFIG_SESSION_PHONE_NAME=chrome # chrome | firefox | edge | opera | safari
# Set qrcode display limit
@ -88,4 +89,4 @@ AUTHENTICATION_JWT_SECRET='L0YWtjb2w554WFqPG'
AUTHENTICATION_INSTANCE_MODE=server # container or server
# if you are using container mode, set the container name and the webhook url to default instance
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 LOG_LEVEL=$LOG_LEVEL
ENV LOG_COLOR=true
ENV LOG_COLOR=$LOG_COLOR
ENV DEL_INSTANCE=$DEL_INSTANCE

View File

@ -2,9 +2,10 @@
<div align="center">
[![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/)
[![Documentation](https://img.shields.io/badge/Documentation-Official-green)](https://evolution-api.com)
[![Whatsapp Group](https://img.shields.io/badge/Group-WhatsApp-%2322BC18)](https://evolution-api.com/whatsapp)
[![Discord Community](https://img.shields.io/badge/Discord-Community-blue)](https://evolution-api.com/discord)
[![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)
[![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}
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 compose up -d

View File

@ -61,7 +61,7 @@ CLEAN_STORE:
# Permanent data storage
DATABASE:
ENABLED: true
ENABLED: false
CONNECTION:
URI: 'mongodb://root:root@localhost:27017/?authSource=admin&readPreference=primary&ssl=false&directConnection=true'
DB_PREFIX_NAME: evolution
@ -69,14 +69,14 @@ DATABASE:
SAVE_DATA:
INSTANCE: false
OLD_MESSAGE: false
NEW_MESSAGE: true
MESSAGE_UPDATE: true
CONTACTS: true
CHATS: true
NEW_MESSAGE: false
MESSAGE_UPDATE: false
CONTACTS: false
CHATS: false
REDIS:
ENABLED: true
URI: 'redis://localhost:6379/1'
ENABLED: false
URI: 'redis://localhost:6379'
PREFIX_KEY: 'evolution'
# Webhook Settings
@ -84,13 +84,13 @@ WEBHOOK:
# Define a global webhook that will listen for enabled events from all instances
GLOBAL:
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
WEBHOOK_BY_EVENTS: false
# Automatically maps webhook paths
# Set the events you want to hear
EVENTS:
APPLICATION_STARTUP: true
APPLICATION_STARTUP: false
QRCODE_UPDATED: true
MESSAGES_SET: true
MESSAGES_UPSERT: true
@ -108,7 +108,7 @@ WEBHOOK:
GROUP_PARTICIPANTS_UPDATE: true
CONNECTION_UPDATE: true
# 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:
# 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'));
execSync(`mkdir -p ${join(storePath, 'webhook')}`);
this.logger.verbose('creating temp path: ' + join(storePath, 'temp'));
execSync(`mkdir -p ${join(storePath, 'temp')}`);
}
}
}

View File

@ -1367,21 +1367,43 @@ export class WAStartupService {
);
})();
const messageRaw: proto.IWebMessageInfo = {
// const messageRaw: proto.IWebMessageInfo = {
// key: messageSent.key,
// messageTimestamp: Long.isLong(messageSent.messageTimestamp)
// ? messageSent.messageTimestamp?.toNumber()
// : messageSent.messageTimestamp,
// pushName: messageSent.pushName,
// broadcast: messageSent.broadcast,
// status: 2,
// message: { ...messageSent.message },
// };
// this.client.ev.emit('messages.upsert', {
// messages: [messageRaw],
// type: 'notify',
// });
const messageRaw: MessageRaw = {
key: messageSent.key,
messageTimestamp: Long.isLong(messageSent.messageTimestamp)
? messageSent.messageTimestamp?.toNumber()
: messageSent.messageTimestamp,
pushName: messageSent.pushName,
broadcast: messageSent.broadcast,
status: 2,
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', {
messages: [messageRaw],
type: 'notify',
});
this.logger.log(messageRaw);
this.logger.verbose('Sending data to webhook in event MESSAGES_UPSERT');
await this.sendDataWebhook(Events.MESSAGES_UPSERT, 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;
} catch (error) {
@ -1628,7 +1650,7 @@ export class WAStartupService {
const hash = `${number}-${new Date().getTime()}`;
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);
if (isBase64(image)) {
@ -1636,7 +1658,7 @@ export class WAStartupService {
const base64Data = image.replace(/^data:image\/(jpeg|png|gif);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);
await sharp(imageBuffer).toFile(imagePath);
@ -1652,7 +1674,7 @@ export class WAStartupService {
this.logger.verbose('Getting image from url');
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);
await sharp(imageBuffer).toFile(imagePath);
@ -1710,8 +1732,8 @@ export class WAStartupService {
if (isURL(audio)) {
this.logger.verbose('Audio is url');
outputAudio = `${join(process.cwd(), 'temp', `${hash}.mp4`)}`;
tempAudioPath = `${join(process.cwd(), 'temp', `temp-${hash}.mp3`)}`;
outputAudio = `${join(this.storePath, 'temp', `${hash}.mp4`)}`;
tempAudioPath = `${join(this.storePath, 'temp', `temp-${hash}.mp3`)}`;
this.logger.verbose('Output audio path: ' + outputAudio);
this.logger.verbose('Temp audio path: ' + tempAudioPath);
@ -1725,12 +1747,11 @@ export class WAStartupService {
this.logger.verbose('Getting audio from url');
fs.writeFileSync(tempAudioPath, response.data);
this.logger.verbose('Temp audio created');
} else {
this.logger.verbose('Audio is base64');
outputAudio = `${join(process.cwd(), 'temp', `${hash}.mp4`)}`;
tempAudioPath = `${join(process.cwd(), 'temp', `temp-${hash}.mp3`)}`;
outputAudio = `${join(this.storePath, 'temp', `${hash}.mp4`)}`;
tempAudioPath = `${join(this.storePath, 'temp', `temp-${hash}.mp3`)}`;
this.logger.verbose('Output audio path: ' + outputAudio);
this.logger.verbose('Temp audio path: ' + tempAudioPath);

View File

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