Skip to content

Commit

Permalink
Merge branch 'release/1.7.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidsonGomes committed Apr 18, 2024
2 parents 8caf3a0 + 5e288d5 commit 371ec9b
Show file tree
Hide file tree
Showing 29 changed files with 382 additions and 276 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
# 1.7.3 (2024-04-18 12:07)

### Fixed
* Revert fix audio encoding
* Recovering messages lost with redis cache
* Adjusts in redis for save instances
* Adjusts in proxy
* Revert pull request #523
* Added instance name on logs
* Added support for Spanish
* Fix error: invalid operator. The allowed operators for identifier are equal_to,not_equal_to in chatwoot

# 1.7.2 (2024-04-12 17:31)

### Feature
Expand Down
21 changes: 14 additions & 7 deletions Docker/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ CLEAN_STORE_CHATS=true

# Permanent data storage
DATABASE_ENABLED=false
DATABASE_CONNECTION_URI=mongodb://root:root@mongodb:27017/?authSource=admin&readPreference=primary&ssl=false&directConnection=true
DATABASE_CONNECTION_URI=mongodb://root:root@mongodb:27017/?authSource=admin &
readPreference=primary &
ssl=false &
directConnection=true
DATABASE_CONNECTION_DB_PREFIX_NAME=evdocker

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

REDIS_ENABLED=false
REDIS_URI=redis://redis:6379
REDIS_PREFIX_KEY=evdocker

RABBITMQ_ENABLED=false
RABBITMQ_RABBITMQ_MODE=global
RABBITMQ_EXCHANGE_NAME=evolution_exchange
Expand All @@ -73,7 +72,7 @@ WEBHOOK_GLOBAL_URL=''
WEBHOOK_GLOBAL_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_GLOBAL_WEBHOOK_BY_EVENTS=false
## Set the events you want to hear
## Set the events you want to hear
WEBHOOK_EVENTS_APPLICATION_STARTUP=false
WEBHOOK_EVENTS_QRCODE_UPDATED=true
WEBHOOK_EVENTS_MESSAGES_SET=true
Expand Down Expand Up @@ -129,6 +128,14 @@ CHATWOOT_MESSAGE_READ=false # false | true
CHATWOOT_IMPORT_DATABASE_CONNECTION_URI=postgres://user:password@hostname:port/dbname
CHATWOOT_IMPORT_DATABASE_PLACEHOLDER_MEDIA_MESSAGE=true

CACHE_REDIS_ENABLED=false
CACHE_REDIS_URI=redis://redis:6379
CACHE_REDIS_PREFIX_KEY=evolution
CACHE_REDIS_TTL=604800
CACHE_REDIS_SAVE_INSTANCES=false
CACHE_LOCAL_ENABLED=false
CACHE_LOCAL_TTL=604800

# Defines an authentication type for the api
# We recommend using the apikey because it will allow you to use a custom token,
# if you use jwt, a random token will be generated and may be expired and you will have to generate a new token
Expand All @@ -143,4 +150,4 @@ AUTHENTICATION_EXPOSE_IN_FETCH_INSTANCES=true
AUTHENTICATION_JWT_EXPIRIN_IN=0
AUTHENTICATION_JWT_SECRET='L=0YWt]b2w[WF>#>:&E`'

LANGUAGE=en # pt-BR, en
LANGUAGE=en # pt-BR, en
21 changes: 14 additions & 7 deletions Docker/evolution-api-all-services/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ CLEAN_STORE_CHATS=true

# Permanent data storage
DATABASE_ENABLED=true
DATABASE_CONNECTION_URI=mongodb://root:root@mongodb:27017/?authSource=admin&readPreference=primary&ssl=false&directConnection=true
DATABASE_CONNECTION_URI=mongodb://root:root@mongodb:27017/?authSource=admin &
readPreference=primary &
ssl=false &
directConnection=true
DATABASE_CONNECTION_DB_PREFIX_NAME=evolution

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

REDIS_ENABLED=true
REDIS_URI=redis://redis:6379
REDIS_PREFIX_KEY=evolution

# Global Webhook Settings
# Each instance's Webhook URL and events will be requested at the time it is created
## Define a global webhook that will listen for enabled events from all instances
WEBHOOK_GLOBAL_URL=''
WEBHOOK_GLOBAL_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_GLOBAL_WEBHOOK_BY_EVENTS=false
## Set the events you want to hear
## Set the events you want to hear
WEBHOOK_EVENTS_APPLICATION_STARTUP=false
WEBHOOK_EVENTS_QRCODE_UPDATED=true
WEBHOOK_EVENTS_MESSAGES_SET=true
Expand Down Expand Up @@ -87,6 +86,14 @@ CONFIG_SESSION_PHONE_NAME=chrome
# Set qrcode display limit
QRCODE_LIMIT=30

CACHE_REDIS_ENABLED=false
CACHE_REDIS_URI=redis://redis:6379
CACHE_REDIS_PREFIX_KEY=evolution
CACHE_REDIS_TTL=604800
CACHE_REDIS_SAVE_INSTANCES=false
CACHE_LOCAL_ENABLED=false
CACHE_LOCAL_TTL=604800

# Defines an authentication type for the api
# We recommend using the apikey because it will allow you to use a custom token,
# if you use jwt, a random token will be generated and may be expired and you will have to generate a new token
Expand All @@ -109,4 +116,4 @@ AUTHENTICATION_INSTANCE_NAME=evolution
AUTHENTICATION_INSTANCE_WEBHOOK_URL=''
AUTHENTICATION_INSTANCE_CHATWOOT_ACCOUNT_ID=1
AUTHENTICATION_INSTANCE_CHATWOOT_TOKEN=123456
AUTHENTICATION_INSTANCE_CHATWOOT_URL=''
AUTHENTICATION_INSTANCE_CHATWOOT_URL=''
14 changes: 9 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM node:20.7.0-alpine AS builder

LABEL version="1.7.2" description="Api to control whatsapp features through http requests."
LABEL version="1.7.3" description="Api to control whatsapp features through http requests."
LABEL maintainer="Davidson Gomes" git="https://github.com/DavidsonGomes"
LABEL contact="contato@agenciadgcode.com"

Expand Down Expand Up @@ -58,10 +58,6 @@ ENV DATABASE_SAVE_MESSAGE_UPDATE=false
ENV DATABASE_SAVE_DATA_CONTACTS=false
ENV DATABASE_SAVE_DATA_CHATS=false

ENV REDIS_ENABLED=false
ENV REDIS_URI=redis://redis:6379
ENV REDIS_PREFIX_KEY=evolution

ENV RABBITMQ_ENABLED=false
ENV RABBITMQ_MODE=global
ENV RABBITMQ_EXCHANGE_NAME=evolution_exchange
Expand Down Expand Up @@ -129,6 +125,14 @@ ENV QRCODE_COLOR=#198754

ENV TYPEBOT_API_VERSION=latest

ENV CACHE_REDIS_ENABLED=false
ENV CACHE_REDIS_URI=redis://redis:6379
ENV CACHE_REDIS_PREFIX_KEY=evolution
ENV CACHE_REDIS_TTL=604800
ENV CACHE_REDIS_SAVE_INSTANCES=false
ENV CACHE_LOCAL_ENABLED=false
ENV CACHE_LOCAL_TTL=604800

ENV AUTHENTICATION_TYPE=apikey

ENV AUTHENTICATION_API_KEY=B6D711FCDE4D4FD5936544120E713976
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "evolution-api",
"version": "1.7.2",
"version": "1.7.3",
"description": "Rest api for communication with WhatsApp",
"main": "./dist/src/main.js",
"scripts": {
Expand Down
6 changes: 6 additions & 0 deletions src/api/abstract/abstract.cache.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
export interface ICache {
get(key: string): Promise<any>;

hGet(key: string, field: string): Promise<any>;

set(key: string, value: any, ttl?: number): void;

hSet(key: string, field: string, value: any): Promise<void>;

has(key: string): Promise<boolean>;

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

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

hDelete(key: string, field: string): Promise<any>;

deleteAll(appendCriteria?: string): Promise<number>;
}
6 changes: 4 additions & 2 deletions src/api/controllers/instance.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { v4 } from 'uuid';
import { ConfigService, HttpServer, WaBusiness } from '../../config/env.config';
import { Logger } from '../../config/logger.config';
import { BadRequestException, InternalServerErrorException } from '../../exceptions';
import { RedisCache } from '../../libs/redis.client';
import { InstanceDto, SetPresenceDto } from '../dto/instance.dto';
import { ChatwootService } from '../integrations/chatwoot/services/chatwoot.service';
import { RabbitmqService } from '../integrations/rabbitmq/services/rabbitmq.service';
Expand Down Expand Up @@ -41,8 +40,9 @@ export class InstanceController {
private readonly typebotService: TypebotService,
private readonly integrationService: IntegrationService,
private readonly proxyService: ProxyController,
private readonly cache: RedisCache,
private readonly cache: CacheService,
private readonly chatwootCache: CacheService,
private readonly messagesLostCache: CacheService,
) {}

private readonly logger = new Logger(InstanceController.name);
Expand Down Expand Up @@ -108,6 +108,7 @@ export class InstanceController {
this.repository,
this.cache,
this.chatwootCache,
this.messagesLostCache,
);
} else {
instance = new BaileysStartupService(
Expand All @@ -116,6 +117,7 @@ export class InstanceController {
this.repository,
this.cache,
this.chatwootCache,
this.messagesLostCache,
);
}

Expand Down
9 changes: 5 additions & 4 deletions src/api/guards/instance.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { NextFunction, Request, Response } from 'express';
import { existsSync } from 'fs';
import { join } from 'path';

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

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

if (redisConf.ENABLED) {
const keyExists = await cache.keyExists();
if (cacheConf.REDIS.ENABLED && cacheConf.REDIS.SAVE_INSTANCES) {
const keyExists = await cache.has(instanceName);

return exists || keyExists;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { isURL } from 'class-validator';

import { CacheEngine } from '../../../../cache/cacheengine';
import { ConfigService, HttpServer } from '../../../../config/env.config';
import { Logger } from '../../../../config/logger.config';
import { BadRequestException } from '../../../../exceptions';
import { InstanceDto } from '../../../dto/instance.dto';
import { RepositoryBroker } from '../../../repository/repository.manager';
import { waMonitor } from '../../../server.module';
import { CacheService } from '../../../services/cache.service';
import { CacheEngine } from '../cache/cacheengine';
import { ChatwootDto } from '../dto/chatwoot.dto';
import { ChatwootService } from '../services/chatwoot.service';

Expand Down
2 changes: 1 addition & 1 deletion src/api/integrations/chatwoot/services/chatwoot.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ export class ChatwootService {
const queryOperator = fieldsToSearch.length - 1 === index1 && numbers.length - 1 === index2 ? null : 'OR';
filterPayload.push({
attribute_key: field,
filter_operator: field == 'phone_number' ? 'equal_to' : 'contains',
filter_operator: ['phone_number', 'identifier'].includes(field) ? 'equal_to' : 'contains',
values: [number.replace('+', '')],
query_operator: queryOperator,
});
Expand Down
6 changes: 3 additions & 3 deletions src/api/integrations/typebot/services/typebot.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export class TypebotService {

if (session) {
if (status === 'closed') {
const found_session: Session[] = findData.sessions.splice(findData.sessions.indexOf(session), 1);
findData.sessions.splice(findData.sessions.indexOf(session), 1);

const typebotData = {
enabled: findData.enabled,
Expand All @@ -68,7 +68,7 @@ export class TypebotService {
delay_message: findData.delay_message,
unknown_message: findData.unknown_message,
listening_from_me: findData.listening_from_me,
sessions: found_session,
sessions: findData.sessions,
};

this.create(instance, typebotData);
Expand Down Expand Up @@ -106,7 +106,7 @@ export class TypebotService {
delay_message: findData.delay_message,
unknown_message: findData.unknown_message,
listening_from_me: findData.listening_from_me,
sessions: findData.sessions.splice(findData.sessions.indexOf(session), 1),
sessions: findData.sessions,
};

this.create(instance, typebotData);
Expand Down
16 changes: 12 additions & 4 deletions src/api/server.module.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { CacheEngine } from '../cache/cacheengine';
import { configService } from '../config/env.config';
import { eventEmitter } from '../config/event.config';
import { Logger } from '../config/logger.config';
import { dbserver } from '../libs/db.connect';
import { RedisCache } from '../libs/redis.client';
import { ChatController } from './controllers/chat.controller';
import { GroupController } from './controllers/group.controller';
import { InstanceController } from './controllers/instance.controller';
Expand All @@ -14,7 +14,6 @@ import { WebhookController } from './controllers/webhook.controller';
import { ChamaaiController } from './integrations/chamaai/controllers/chamaai.controller';
import { ChamaaiRepository } from './integrations/chamaai/repository/chamaai.repository';
import { ChamaaiService } from './integrations/chamaai/services/chamaai.service';
import { CacheEngine } from './integrations/chatwoot/cache/cacheengine';
import { ChatwootController } from './integrations/chatwoot/controllers/chatwoot.controller';
import { ChatwootRepository } from './integrations/chatwoot/repository/chatwoot.repository';
import { ChatwootService } from './integrations/chatwoot/services/chatwoot.service';
Expand Down Expand Up @@ -107,10 +106,18 @@ export const repository = new RepositoryBroker(
dbserver?.getClient(),
);

export const cache = new RedisCache();
export const cache = new CacheService(new CacheEngine(configService, 'instance').getEngine());
const chatwootCache = new CacheService(new CacheEngine(configService, ChatwootService.name).getEngine());
const messagesLostCache = new CacheService(new CacheEngine(configService, 'baileys').getEngine());

export const waMonitor = new WAMonitoringService(eventEmitter, configService, repository, cache, chatwootCache);
export const waMonitor = new WAMonitoringService(
eventEmitter,
configService,
repository,
cache,
chatwootCache,
messagesLostCache,
);

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

Expand Down Expand Up @@ -160,6 +167,7 @@ export const instanceController = new InstanceController(
proxyController,
cache,
chatwootCache,
messagesLostCache,
);
export const sendMessageController = new SendMessageController(waMonitor);
export const chatController = new ChatController(waMonitor);
Expand Down
Loading

0 comments on commit 371ec9b

Please sign in to comment.