mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-13 07:04:50 -06:00
Merge branch 'release/2.2.3'
This commit is contained in:
commit
427c994993
@ -1,3 +1,10 @@
|
||||
# 2.2.3 (2025-02-03 11:52)
|
||||
|
||||
### Fixed
|
||||
|
||||
* Fix cache in local file system
|
||||
* Update Baileys Version
|
||||
|
||||
# 2.2.2 (2025-01-31 06:55)
|
||||
|
||||
### Features
|
||||
|
@ -3,7 +3,7 @@ FROM node:20-alpine AS builder
|
||||
RUN apk update && \
|
||||
apk add git ffmpeg wget curl bash openssl
|
||||
|
||||
LABEL version="2.2.2" description="Api to control whatsapp features through http requests."
|
||||
LABEL version="2.2.3" description="Api to control whatsapp features through http requests."
|
||||
LABEL maintainer="Davidson Gomes" git="https://github.com/DavidsonGomes"
|
||||
LABEL contact="contato@atendai.com"
|
||||
|
||||
|
8
package-lock.json
generated
8
package-lock.json
generated
@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "evolution-api",
|
||||
"version": "2.2.2",
|
||||
"version": "2.2.3",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "evolution-api",
|
||||
"version": "2.2.2",
|
||||
"version": "2.2.3",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@adiwajshing/keyed-db": "^0.2.4",
|
||||
@ -4752,8 +4752,8 @@
|
||||
"integrity": "sha512-OnAYlL5b7LEkALw87fUVafQw5rVR9RjwGd4KUwNQ6DrrNmaVaUCgLipfVlzrPQ4tWOR9P0IXGNOx50jYCCdSJg=="
|
||||
},
|
||||
"node_modules/baileys": {
|
||||
"version": "6.7.9",
|
||||
"resolved": "git+ssh://git@github.com/EvolutionAPI/Baileys.git#2140e16a9214067bf4cd408e88c231c24636a9e9",
|
||||
"version": "6.7.12",
|
||||
"resolved": "git+ssh://git@github.com/EvolutionAPI/Baileys.git#2c69f65d4b6c4e779d6e3d2c0c32689a5425df95",
|
||||
"dependencies": {
|
||||
"@adiwajshing/keyed-db": "^0.2.4",
|
||||
"@hapi/boom": "^9.1.3",
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "evolution-api",
|
||||
"version": "2.2.2",
|
||||
"version": "2.2.3",
|
||||
"description": "Rest api for communication with WhatsApp",
|
||||
"main": "./dist/main.js",
|
||||
"type": "commonjs",
|
||||
|
@ -2163,6 +2163,7 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
const cache = this.configService.get<CacheConf>('CACHE');
|
||||
if (!cache.REDIS.ENABLED && !cache.LOCAL.ENABLED) group = await this.findGroup({ groupJid: sender }, 'inner');
|
||||
else group = await this.getGroupMetadataCache(sender);
|
||||
// group = await this.findGroup({ groupJid: sender }, 'inner');
|
||||
} catch (error) {
|
||||
throw new NotFoundException('Group not found');
|
||||
}
|
||||
@ -3551,25 +3552,31 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
const messageId = response.message?.protocolMessage?.key?.id;
|
||||
if (messageId) {
|
||||
const isLogicalDeleted = configService.get<Database>('DATABASE').DELETE_DATA.LOGICAL_MESSAGE_DELETE;
|
||||
let message = await this.prismaRepository.message.findUnique({
|
||||
where: { id: messageId },
|
||||
let message = await this.prismaRepository.message.findFirst({
|
||||
where: {
|
||||
key: {
|
||||
path: ['id'],
|
||||
equals: messageId,
|
||||
},
|
||||
},
|
||||
});
|
||||
if (isLogicalDeleted) {
|
||||
if (!message) return response;
|
||||
const existingKey = typeof message?.key === 'object' && message.key !== null ? message.key : {};
|
||||
message = await this.prismaRepository.message.update({
|
||||
where: { id: messageId },
|
||||
where: { id: message.id },
|
||||
data: {
|
||||
key: {
|
||||
...existingKey,
|
||||
deleted: true,
|
||||
},
|
||||
status: 'DELETED',
|
||||
},
|
||||
});
|
||||
} else {
|
||||
await this.prismaRepository.message.deleteMany({
|
||||
where: {
|
||||
id: messageId,
|
||||
id: message.id,
|
||||
},
|
||||
});
|
||||
}
|
||||
@ -3578,7 +3585,7 @@ export class BaileysStartupService extends ChannelStartupService {
|
||||
instanceId: message.instanceId,
|
||||
key: message.key,
|
||||
messageType: message.messageType,
|
||||
status: message.status,
|
||||
status: 'DELETED',
|
||||
source: message.source,
|
||||
messageTimestamp: message.messageTimestamp,
|
||||
pushName: message.pushName,
|
||||
|
@ -224,63 +224,43 @@ export class DifyService {
|
||||
headers: {
|
||||
Authorization: `Bearer ${dify.apiKey}`,
|
||||
},
|
||||
responseType: 'stream',
|
||||
});
|
||||
|
||||
let conversationId;
|
||||
let answer = '';
|
||||
|
||||
const stream = response.data;
|
||||
const reader = new Readable().wrap(stream);
|
||||
const data = response.data.replaceAll('data: ', '');
|
||||
|
||||
reader.on('data', (chunk) => {
|
||||
const data = chunk.toString().replace(/data:\s*/g, '');
|
||||
const events = data.split('\n').filter((line) => line.trim() !== '');
|
||||
|
||||
if (data.trim() === '' || !data.startsWith('{')) {
|
||||
return;
|
||||
}
|
||||
for (const eventString of events) {
|
||||
if (eventString.trim().startsWith('{')) {
|
||||
const event = JSON.parse(eventString);
|
||||
|
||||
try {
|
||||
const events = data.split('\n').filter((line) => line.trim() !== '');
|
||||
|
||||
for (const eventString of events) {
|
||||
if (eventString.trim().startsWith('{')) {
|
||||
const event = JSON.parse(eventString);
|
||||
|
||||
if (event?.event === 'agent_message') {
|
||||
console.log('event:', event);
|
||||
conversationId = conversationId ?? event?.conversation_id;
|
||||
answer += event?.answer;
|
||||
}
|
||||
}
|
||||
if (event?.event === 'agent_message') {
|
||||
console.log('event:', event);
|
||||
conversationId = conversationId ?? event?.conversation_id;
|
||||
answer += event?.answer;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error parsing stream data:', error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
reader.on('end', async () => {
|
||||
if (instance.integration === Integration.WHATSAPP_BAILEYS)
|
||||
await instance.client.sendPresenceUpdate('paused', remoteJid);
|
||||
if (instance.integration === Integration.WHATSAPP_BAILEYS)
|
||||
await instance.client.sendPresenceUpdate('paused', remoteJid);
|
||||
|
||||
const message = answer;
|
||||
const message = answer;
|
||||
|
||||
await this.sendMessageWhatsApp(instance, remoteJid, message, settings);
|
||||
await this.sendMessageWhatsApp(instance, remoteJid, message, settings);
|
||||
|
||||
await this.prismaRepository.integrationSession.update({
|
||||
where: {
|
||||
id: session.id,
|
||||
},
|
||||
data: {
|
||||
status: 'opened',
|
||||
awaitUser: true,
|
||||
sessionId: conversationId,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
reader.on('error', (error) => {
|
||||
console.error('Error reading stream:', error);
|
||||
await this.prismaRepository.integrationSession.update({
|
||||
where: {
|
||||
id: session.id,
|
||||
},
|
||||
data: {
|
||||
status: 'opened',
|
||||
awaitUser: true,
|
||||
sessionId: conversationId,
|
||||
},
|
||||
});
|
||||
|
||||
return;
|
||||
|
@ -5,14 +5,14 @@ import { AuthenticationState, BufferJSON, initAuthCreds, WAProto as proto } from
|
||||
import fs from 'fs/promises';
|
||||
import path from 'path';
|
||||
|
||||
// const fixFileName = (file: string): string | undefined => {
|
||||
// if (!file) {
|
||||
// return undefined;
|
||||
// }
|
||||
// const replacedSlash = file.replace(/\//g, '__');
|
||||
// const replacedColon = replacedSlash.replace(/:/g, '-');
|
||||
// return replacedColon;
|
||||
// };
|
||||
const fixFileName = (file: string): string | undefined => {
|
||||
if (!file) {
|
||||
return undefined;
|
||||
}
|
||||
const replacedSlash = file.replace(/\//g, '__');
|
||||
const replacedColon = replacedSlash.replace(/:/g, '-');
|
||||
return replacedColon;
|
||||
};
|
||||
|
||||
export async function keyExists(sessionId: string): Promise<any> {
|
||||
try {
|
||||
@ -63,14 +63,14 @@ async function deleteAuthKey(sessionId: string): Promise<any> {
|
||||
}
|
||||
}
|
||||
|
||||
// async function fileExists(file: string): Promise<any> {
|
||||
// try {
|
||||
// const stat = await fs.stat(file);
|
||||
// if (stat.isFile()) return true;
|
||||
// } catch (error) {
|
||||
// return;
|
||||
// }
|
||||
// }
|
||||
async function fileExists(file: string): Promise<any> {
|
||||
try {
|
||||
const stat = await fs.stat(file);
|
||||
if (stat.isFile()) return true;
|
||||
} catch (error) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
export default async function useMultiFileAuthStatePrisma(
|
||||
sessionId: string,
|
||||
@ -80,16 +80,19 @@ export default async function useMultiFileAuthStatePrisma(
|
||||
saveCreds: () => Promise<void>;
|
||||
}> {
|
||||
const localFolder = path.join(INSTANCE_DIR, sessionId);
|
||||
// const localFile = (key: string) => path.join(localFolder, fixFileName(key) + '.json');
|
||||
const localFile = (key: string) => path.join(localFolder, fixFileName(key) + '.json');
|
||||
await fs.mkdir(localFolder, { recursive: true });
|
||||
|
||||
async function writeData(data: any, key: string): Promise<any> {
|
||||
const dataString = JSON.stringify(data, BufferJSON.replacer);
|
||||
|
||||
if (key != 'creds') {
|
||||
return await cache.hSet(sessionId, key, data);
|
||||
// await fs.writeFile(localFile(key), dataString);
|
||||
// return;
|
||||
if (process.env.CACHE_REDIS_ENABLED === 'true') {
|
||||
return await cache.hSet(sessionId, key, data);
|
||||
} else {
|
||||
await fs.writeFile(localFile(key), dataString);
|
||||
return;
|
||||
}
|
||||
}
|
||||
await saveKey(sessionId, dataString);
|
||||
return;
|
||||
@ -100,9 +103,13 @@ export default async function useMultiFileAuthStatePrisma(
|
||||
let rawData;
|
||||
|
||||
if (key != 'creds') {
|
||||
return await cache.hGet(sessionId, key);
|
||||
// if (!(await fileExists(localFile(key)))) return null;
|
||||
// rawData = await fs.readFile(localFile(key), { encoding: 'utf-8' });
|
||||
if (process.env.CACHE_REDIS_ENABLED === 'true') {
|
||||
return await cache.hGet(sessionId, key);
|
||||
} else {
|
||||
if (!(await fileExists(localFile(key)))) return null;
|
||||
rawData = await fs.readFile(localFile(key), { encoding: 'utf-8' });
|
||||
return JSON.parse(rawData, BufferJSON.reviver);
|
||||
}
|
||||
} else {
|
||||
rawData = await getAuthKey(sessionId);
|
||||
}
|
||||
@ -117,8 +124,11 @@ export default async function useMultiFileAuthStatePrisma(
|
||||
async function removeData(key: string): Promise<any> {
|
||||
try {
|
||||
if (key != 'creds') {
|
||||
return await cache.hDelete(sessionId, key);
|
||||
// await fs.unlink(localFile(key));
|
||||
if (process.env.CACHE_REDIS_ENABLED === 'true') {
|
||||
return await cache.hDelete(sessionId, key);
|
||||
} else {
|
||||
await fs.unlink(localFile(key));
|
||||
}
|
||||
} else {
|
||||
await deleteAuthKey(sessionId);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user