Skip to content

Commit 371ec9b

Browse files
committed
Merge branch 'release/1.7.3'
2 parents 8caf3a0 + 5e288d5 commit 371ec9b

29 files changed

+382
-276
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
# 1.7.3 (2024-04-18 12:07)
2+
3+
### Fixed
4+
* Revert fix audio encoding
5+
* Recovering messages lost with redis cache
6+
* Adjusts in redis for save instances
7+
* Adjusts in proxy
8+
* Revert pull request #523
9+
* Added instance name on logs
10+
* Added support for Spanish
11+
* Fix error: invalid operator. The allowed operators for identifier are equal_to,not_equal_to in chatwoot
12+
113
# 1.7.2 (2024-04-12 17:31)
214

315
### Feature

Docker/.env.example

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ CLEAN_STORE_CHATS=true
3333

3434
# Permanent data storage
3535
DATABASE_ENABLED=false
36-
DATABASE_CONNECTION_URI=mongodb://root:root@mongodb:27017/?authSource=admin&readPreference=primary&ssl=false&directConnection=true
36+
DATABASE_CONNECTION_URI=mongodb://root:root@mongodb:27017/?authSource=admin &
37+
readPreference=primary &
38+
ssl=false &
39+
directConnection=true
3740
DATABASE_CONNECTION_DB_PREFIX_NAME=evdocker
3841

3942
# Choose the data you want to save in the application's database or store
@@ -43,10 +46,6 @@ DATABASE_SAVE_MESSAGE_UPDATE=false
4346
DATABASE_SAVE_DATA_CONTACTS=false
4447
DATABASE_SAVE_DATA_CHATS=false
4548

46-
REDIS_ENABLED=false
47-
REDIS_URI=redis://redis:6379
48-
REDIS_PREFIX_KEY=evdocker
49-
5049
RABBITMQ_ENABLED=false
5150
RABBITMQ_RABBITMQ_MODE=global
5251
RABBITMQ_EXCHANGE_NAME=evolution_exchange
@@ -73,7 +72,7 @@ WEBHOOK_GLOBAL_URL=''
7372
WEBHOOK_GLOBAL_ENABLED=false
7473
# With this option activated, you work with a url per webhook event, respecting the global url and the name of each event
7574
WEBHOOK_GLOBAL_WEBHOOK_BY_EVENTS=false
76-
## Set the events you want to hear
75+
## Set the events you want to hear
7776
WEBHOOK_EVENTS_APPLICATION_STARTUP=false
7877
WEBHOOK_EVENTS_QRCODE_UPDATED=true
7978
WEBHOOK_EVENTS_MESSAGES_SET=true
@@ -129,6 +128,14 @@ CHATWOOT_MESSAGE_READ=false # false | true
129128
CHATWOOT_IMPORT_DATABASE_CONNECTION_URI=postgres://user:password@hostname:port/dbname
130129
CHATWOOT_IMPORT_DATABASE_PLACEHOLDER_MEDIA_MESSAGE=true
131130

131+
CACHE_REDIS_ENABLED=false
132+
CACHE_REDIS_URI=redis://redis:6379
133+
CACHE_REDIS_PREFIX_KEY=evolution
134+
CACHE_REDIS_TTL=604800
135+
CACHE_REDIS_SAVE_INSTANCES=false
136+
CACHE_LOCAL_ENABLED=false
137+
CACHE_LOCAL_TTL=604800
138+
132139
# Defines an authentication type for the api
133140
# We recommend using the apikey because it will allow you to use a custom token,
134141
# if you use jwt, a random token will be generated and may be expired and you will have to generate a new token
@@ -143,4 +150,4 @@ AUTHENTICATION_EXPOSE_IN_FETCH_INSTANCES=true
143150
AUTHENTICATION_JWT_EXPIRIN_IN=0
144151
AUTHENTICATION_JWT_SECRET='L=0YWt]b2w[WF>#>:&E`'
145152

146-
LANGUAGE=en # pt-BR, en
153+
LANGUAGE=en # pt-BR, en

Docker/evolution-api-all-services/.env.example

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@ CLEAN_STORE_CHATS=true
3333

3434
# Permanent data storage
3535
DATABASE_ENABLED=true
36-
DATABASE_CONNECTION_URI=mongodb://root:root@mongodb:27017/?authSource=admin&readPreference=primary&ssl=false&directConnection=true
36+
DATABASE_CONNECTION_URI=mongodb://root:root@mongodb:27017/?authSource=admin &
37+
readPreference=primary &
38+
ssl=false &
39+
directConnection=true
3740
DATABASE_CONNECTION_DB_PREFIX_NAME=evolution
3841

3942
# Choose the data you want to save in the application's database or store
@@ -43,18 +46,14 @@ DATABASE_SAVE_MESSAGE_UPDATE=false
4346
DATABASE_SAVE_DATA_CONTACTS=false
4447
DATABASE_SAVE_DATA_CHATS=false
4548

46-
REDIS_ENABLED=true
47-
REDIS_URI=redis://redis:6379
48-
REDIS_PREFIX_KEY=evolution
49-
5049
# Global Webhook Settings
5150
# Each instance's Webhook URL and events will be requested at the time it is created
5251
## Define a global webhook that will listen for enabled events from all instances
5352
WEBHOOK_GLOBAL_URL=''
5453
WEBHOOK_GLOBAL_ENABLED=false
5554
# With this option activated, you work with a url per webhook event, respecting the global url and the name of each event
5655
WEBHOOK_GLOBAL_WEBHOOK_BY_EVENTS=false
57-
## Set the events you want to hear
56+
## Set the events you want to hear
5857
WEBHOOK_EVENTS_APPLICATION_STARTUP=false
5958
WEBHOOK_EVENTS_QRCODE_UPDATED=true
6059
WEBHOOK_EVENTS_MESSAGES_SET=true
@@ -87,6 +86,14 @@ CONFIG_SESSION_PHONE_NAME=chrome
8786
# Set qrcode display limit
8887
QRCODE_LIMIT=30
8988

89+
CACHE_REDIS_ENABLED=false
90+
CACHE_REDIS_URI=redis://redis:6379
91+
CACHE_REDIS_PREFIX_KEY=evolution
92+
CACHE_REDIS_TTL=604800
93+
CACHE_REDIS_SAVE_INSTANCES=false
94+
CACHE_LOCAL_ENABLED=false
95+
CACHE_LOCAL_TTL=604800
96+
9097
# Defines an authentication type for the api
9198
# We recommend using the apikey because it will allow you to use a custom token,
9299
# if you use jwt, a random token will be generated and may be expired and you will have to generate a new token
@@ -109,4 +116,4 @@ AUTHENTICATION_INSTANCE_NAME=evolution
109116
AUTHENTICATION_INSTANCE_WEBHOOK_URL=''
110117
AUTHENTICATION_INSTANCE_CHATWOOT_ACCOUNT_ID=1
111118
AUTHENTICATION_INSTANCE_CHATWOOT_TOKEN=123456
112-
AUTHENTICATION_INSTANCE_CHATWOOT_URL=''
119+
AUTHENTICATION_INSTANCE_CHATWOOT_URL=''

Dockerfile

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM node:20.7.0-alpine AS builder
22

3-
LABEL version="1.7.2" description="Api to control whatsapp features through http requests."
3+
LABEL version="1.7.3" description="Api to control whatsapp features through http requests."
44
LABEL maintainer="Davidson Gomes" git="https://github.com/DavidsonGomes"
55
LABEL contact="[email protected]"
66

@@ -58,10 +58,6 @@ ENV DATABASE_SAVE_MESSAGE_UPDATE=false
5858
ENV DATABASE_SAVE_DATA_CONTACTS=false
5959
ENV DATABASE_SAVE_DATA_CHATS=false
6060

61-
ENV REDIS_ENABLED=false
62-
ENV REDIS_URI=redis://redis:6379
63-
ENV REDIS_PREFIX_KEY=evolution
64-
6561
ENV RABBITMQ_ENABLED=false
6662
ENV RABBITMQ_MODE=global
6763
ENV RABBITMQ_EXCHANGE_NAME=evolution_exchange
@@ -129,6 +125,14 @@ ENV QRCODE_COLOR=#198754
129125

130126
ENV TYPEBOT_API_VERSION=latest
131127

128+
ENV CACHE_REDIS_ENABLED=false
129+
ENV CACHE_REDIS_URI=redis://redis:6379
130+
ENV CACHE_REDIS_PREFIX_KEY=evolution
131+
ENV CACHE_REDIS_TTL=604800
132+
ENV CACHE_REDIS_SAVE_INSTANCES=false
133+
ENV CACHE_LOCAL_ENABLED=false
134+
ENV CACHE_LOCAL_TTL=604800
135+
132136
ENV AUTHENTICATION_TYPE=apikey
133137

134138
ENV AUTHENTICATION_API_KEY=B6D711FCDE4D4FD5936544120E713976

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "evolution-api",
3-
"version": "1.7.2",
3+
"version": "1.7.3",
44
"description": "Rest api for communication with WhatsApp",
55
"main": "./dist/src/main.js",
66
"scripts": {

src/api/abstract/abstract.cache.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
export interface ICache {
22
get(key: string): Promise<any>;
33

4+
hGet(key: string, field: string): Promise<any>;
5+
46
set(key: string, value: any, ttl?: number): void;
57

8+
hSet(key: string, field: string, value: any): Promise<void>;
9+
610
has(key: string): Promise<boolean>;
711

812
keys(appendCriteria?: string): Promise<string[]>;
913

1014
delete(key: string | string[]): Promise<number>;
1115

16+
hDelete(key: string, field: string): Promise<any>;
17+
1218
deleteAll(appendCriteria?: string): Promise<number>;
1319
}

src/api/controllers/instance.controller.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { v4 } from 'uuid';
66
import { ConfigService, HttpServer, WaBusiness } from '../../config/env.config';
77
import { Logger } from '../../config/logger.config';
88
import { BadRequestException, InternalServerErrorException } from '../../exceptions';
9-
import { RedisCache } from '../../libs/redis.client';
109
import { InstanceDto, SetPresenceDto } from '../dto/instance.dto';
1110
import { ChatwootService } from '../integrations/chatwoot/services/chatwoot.service';
1211
import { RabbitmqService } from '../integrations/rabbitmq/services/rabbitmq.service';
@@ -41,8 +40,9 @@ export class InstanceController {
4140
private readonly typebotService: TypebotService,
4241
private readonly integrationService: IntegrationService,
4342
private readonly proxyService: ProxyController,
44-
private readonly cache: RedisCache,
43+
private readonly cache: CacheService,
4544
private readonly chatwootCache: CacheService,
45+
private readonly messagesLostCache: CacheService,
4646
) {}
4747

4848
private readonly logger = new Logger(InstanceController.name);
@@ -108,6 +108,7 @@ export class InstanceController {
108108
this.repository,
109109
this.cache,
110110
this.chatwootCache,
111+
this.messagesLostCache,
111112
);
112113
} else {
113114
instance = new BaileysStartupService(
@@ -116,6 +117,7 @@ export class InstanceController {
116117
this.repository,
117118
this.cache,
118119
this.chatwootCache,
120+
this.messagesLostCache,
119121
);
120122
}
121123

src/api/guards/instance.guard.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { NextFunction, Request, Response } from 'express';
22
import { existsSync } from 'fs';
33
import { join } from 'path';
44

5-
import { configService, Database, Redis } from '../../config/env.config';
5+
import { CacheConf, configService, Database } from '../../config/env.config';
66
import { INSTANCE_DIR } from '../../config/path.config';
77
import {
88
BadRequestException,
@@ -17,12 +17,13 @@ import { cache, waMonitor } from '../server.module';
1717
async function getInstance(instanceName: string) {
1818
try {
1919
const db = configService.get<Database>('DATABASE');
20-
const redisConf = configService.get<Redis>('REDIS');
20+
const cacheConf = configService.get<CacheConf>('CACHE');
2121

2222
const exists = !!waMonitor.waInstances[instanceName];
2323

24-
if (redisConf.ENABLED) {
25-
const keyExists = await cache.keyExists();
24+
if (cacheConf.REDIS.ENABLED && cacheConf.REDIS.SAVE_INSTANCES) {
25+
const keyExists = await cache.has(instanceName);
26+
2627
return exists || keyExists;
2728
}
2829

src/api/integrations/chatwoot/controllers/chatwoot.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { isURL } from 'class-validator';
22

3+
import { CacheEngine } from '../../../../cache/cacheengine';
34
import { ConfigService, HttpServer } from '../../../../config/env.config';
45
import { Logger } from '../../../../config/logger.config';
56
import { BadRequestException } from '../../../../exceptions';
67
import { InstanceDto } from '../../../dto/instance.dto';
78
import { RepositoryBroker } from '../../../repository/repository.manager';
89
import { waMonitor } from '../../../server.module';
910
import { CacheService } from '../../../services/cache.service';
10-
import { CacheEngine } from '../cache/cacheengine';
1111
import { ChatwootDto } from '../dto/chatwoot.dto';
1212
import { ChatwootService } from '../services/chatwoot.service';
1313

src/api/integrations/chatwoot/services/chatwoot.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ export class ChatwootService {
461461
const queryOperator = fieldsToSearch.length - 1 === index1 && numbers.length - 1 === index2 ? null : 'OR';
462462
filterPayload.push({
463463
attribute_key: field,
464-
filter_operator: field == 'phone_number' ? 'equal_to' : 'contains',
464+
filter_operator: ['phone_number', 'identifier'].includes(field) ? 'equal_to' : 'contains',
465465
values: [number.replace('+', '')],
466466
query_operator: queryOperator,
467467
});

src/api/integrations/typebot/services/typebot.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export class TypebotService {
5757

5858
if (session) {
5959
if (status === 'closed') {
60-
const found_session: Session[] = findData.sessions.splice(findData.sessions.indexOf(session), 1);
60+
findData.sessions.splice(findData.sessions.indexOf(session), 1);
6161

6262
const typebotData = {
6363
enabled: findData.enabled,
@@ -68,7 +68,7 @@ export class TypebotService {
6868
delay_message: findData.delay_message,
6969
unknown_message: findData.unknown_message,
7070
listening_from_me: findData.listening_from_me,
71-
sessions: found_session,
71+
sessions: findData.sessions,
7272
};
7373

7474
this.create(instance, typebotData);
@@ -106,7 +106,7 @@ export class TypebotService {
106106
delay_message: findData.delay_message,
107107
unknown_message: findData.unknown_message,
108108
listening_from_me: findData.listening_from_me,
109-
sessions: findData.sessions.splice(findData.sessions.indexOf(session), 1),
109+
sessions: findData.sessions,
110110
};
111111

112112
this.create(instance, typebotData);

src/api/server.module.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
import { CacheEngine } from '../cache/cacheengine';
12
import { configService } from '../config/env.config';
23
import { eventEmitter } from '../config/event.config';
34
import { Logger } from '../config/logger.config';
45
import { dbserver } from '../libs/db.connect';
5-
import { RedisCache } from '../libs/redis.client';
66
import { ChatController } from './controllers/chat.controller';
77
import { GroupController } from './controllers/group.controller';
88
import { InstanceController } from './controllers/instance.controller';
@@ -14,7 +14,6 @@ import { WebhookController } from './controllers/webhook.controller';
1414
import { ChamaaiController } from './integrations/chamaai/controllers/chamaai.controller';
1515
import { ChamaaiRepository } from './integrations/chamaai/repository/chamaai.repository';
1616
import { ChamaaiService } from './integrations/chamaai/services/chamaai.service';
17-
import { CacheEngine } from './integrations/chatwoot/cache/cacheengine';
1817
import { ChatwootController } from './integrations/chatwoot/controllers/chatwoot.controller';
1918
import { ChatwootRepository } from './integrations/chatwoot/repository/chatwoot.repository';
2019
import { ChatwootService } from './integrations/chatwoot/services/chatwoot.service';
@@ -107,10 +106,18 @@ export const repository = new RepositoryBroker(
107106
dbserver?.getClient(),
108107
);
109108

110-
export const cache = new RedisCache();
109+
export const cache = new CacheService(new CacheEngine(configService, 'instance').getEngine());
111110
const chatwootCache = new CacheService(new CacheEngine(configService, ChatwootService.name).getEngine());
111+
const messagesLostCache = new CacheService(new CacheEngine(configService, 'baileys').getEngine());
112112

113-
export const waMonitor = new WAMonitoringService(eventEmitter, configService, repository, cache, chatwootCache);
113+
export const waMonitor = new WAMonitoringService(
114+
eventEmitter,
115+
configService,
116+
repository,
117+
cache,
118+
chatwootCache,
119+
messagesLostCache,
120+
);
114121

115122
const authService = new AuthService(configService, waMonitor, repository);
116123

@@ -160,6 +167,7 @@ export const instanceController = new InstanceController(
160167
proxyController,
161168
cache,
162169
chatwootCache,
170+
messagesLostCache,
163171
);
164172
export const sendMessageController = new SendMessageController(waMonitor);
165173
export const chatController = new ChatController(waMonitor);

0 commit comments

Comments
 (0)