Skip to content

Commit

Permalink
Merge branch 'release/1.8.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidsonGomes committed Jun 9, 2024
2 parents 0e9d036 + c898f1e commit bd06920
Show file tree
Hide file tree
Showing 15 changed files with 529 additions and 42 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# 1.8.1 (2024-06-08 21:32)

### Feature

* New method of saving sessions to a file using worker, made in partnership with [codechat](https://github.com/code-chat-br/whatsapp-api)

### Fixed

* Correction of variables breaking lines in typebot

# 1.8.0 (2024-05-27 16:10)

### Feature
Expand All @@ -7,12 +17,14 @@
* Build in docker for linux/amd64, linux/arm64 platforms

### Fixed

* Correction in message formatting when generated by AI as markdown in typebot
* Security fix in fetch instance with client key when not connected to mongodb

# 1.7.5 (2024-05-21 08:50)

### Fixed

* Add merge_brazil_contacts function to solve nine digit in brazilian numbers
* Optimize ChatwootService method for updating contact
* Fix swagger auth
Expand All @@ -24,6 +36,7 @@
# 1.7.4 (2024-04-28 09:46)

### Fixed

* Adjusts in proxy on fetchAgent
* Recovering messages lost with redis cache
* Log when init redis cache service
Expand All @@ -34,6 +47,7 @@
# 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
Expand Down
7 changes: 2 additions & 5 deletions Docker/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,7 @@ 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 Down Expand Up @@ -137,7 +134,7 @@ CONFIG_SESSION_PHONE_NAME=Chrome

# Set qrcode display limit
QRCODE_LIMIT=30
QRCODE_COLOR=#198754
QRCODE_COLOR='#198754'

# old | latest
TYPEBOT_API_VERSION=latest
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "evolution-api",
"version": "1.8.0",
"version": "1.8.1",
"description": "Rest api for communication with WhatsApp",
"main": "./dist/src/main.js",
"scripts": {
Expand Down Expand Up @@ -49,7 +49,7 @@
"amqplib": "^0.10.3",
"@aws-sdk/client-sqs": "^3.569.0",
"axios": "^1.6.5",
"@whiskeysockets/baileys": "^6.7.2",
"@whiskeysockets/baileys": "6.7.4",
"class-validator": "^0.14.1",
"compression": "^1.7.4",
"cors": "^2.8.5",
Expand Down
12 changes: 8 additions & 4 deletions src/api/controllers/instance.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { RabbitmqService } from '../integrations/rabbitmq/services/rabbitmq.serv
import { SqsService } from '../integrations/sqs/services/sqs.service';
import { TypebotService } from '../integrations/typebot/services/typebot.service';
import { WebsocketService } from '../integrations/websocket/services/websocket.service';
import { ProviderFiles } from '../provider/sessions';
import { RepositoryBroker } from '../repository/repository.manager';
import { AuthService, OldToken } from '../services/auth.service';
import { CacheService } from '../services/cache.service';
Expand Down Expand Up @@ -42,7 +43,8 @@ export class InstanceController {
private readonly proxyService: ProxyController,
private readonly cache: CacheService,
private readonly chatwootCache: CacheService,
private readonly messagesLostCache: CacheService,
private readonly baileysCache: CacheService,
private readonly providerFiles: ProviderFiles,
) {}

private readonly logger = new Logger(InstanceController.name);
Expand Down Expand Up @@ -110,7 +112,8 @@ export class InstanceController {
this.repository,
this.cache,
this.chatwootCache,
this.messagesLostCache,
this.baileysCache,
this.providerFiles,
);
} else {
instance = new BaileysStartupService(
Expand All @@ -119,7 +122,8 @@ export class InstanceController {
this.repository,
this.cache,
this.chatwootCache,
this.messagesLostCache,
this.baileysCache,
this.providerFiles,
);
}

Expand Down Expand Up @@ -749,7 +753,7 @@ export class InstanceController {
this.logger.verbose('deleting instance: ' + instanceName);

try {
this.waMonitor.waInstances[instanceName].sendDataWebhook(Events.INSTANCE_DELETE, {
this.waMonitor.waInstances[instanceName]?.sendDataWebhook(Events.INSTANCE_DELETE, {
instanceName,
instanceId: (await this.repository.auth.find(instanceName))?.instanceId,
});
Expand Down
4 changes: 4 additions & 0 deletions src/api/integrations/chatwoot/services/chatwoot.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,10 @@ export class ChatwootService {
return messageSent;
}

if (type === 'image' && parsedMedia && parsedMedia?.ext === '.gif') {
type = 'document';
}

this.logger.verbose('send media to instance: ' + waInstance.instanceName);
const data: SendMediaDto = {
number: number,
Expand Down
8 changes: 7 additions & 1 deletion src/api/integrations/typebot/services/typebot.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,14 @@ export class TypebotService {
}
}

if (element.type === 'p') {
if (element.type === 'p' && element.type !== 'inline-variable') {
text = text.trim() + '\n';
}

if (element.type === 'inline-variable') {
text = text.trim();
}

if (element.type === 'ol') {
text =
'\n' +
Expand Down Expand Up @@ -582,6 +586,8 @@ export class TypebotService {

formattedText = formattedText.replace(/\*\*/g, '').replace(/__/, '').replace(/~~/, '').replace(/\n$/, '');

formattedText = formattedText.replace(/\n$/, '');

await instance.textMessage({
number: remoteJid.split('@')[0],
options: {
Expand Down
150 changes: 150 additions & 0 deletions src/api/provider/sessions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
import axios from 'axios';
import { execSync } from 'child_process';

import { Auth, ConfigService, ProviderSession } from '../../config/env.config';
import { Logger } from '../../config/logger.config';

type ResponseSuccess = { status: number; data?: any };
type ResponseProvider = Promise<[ResponseSuccess?, Error?]>;

export class ProviderFiles {
constructor(private readonly configService: ConfigService) {
this.baseUrl = `http://${this.config.HOST}:${this.config.PORT}/session/${this.config.PREFIX}`;
this.globalApiToken = this.configService.get<Auth>('AUTHENTICATION').API_KEY.KEY;
}

private readonly logger = new Logger(ProviderFiles.name);

private baseUrl: string;
private globalApiToken: string;

private readonly config = Object.freeze(this.configService.get<ProviderSession>('PROVIDER'));

get isEnabled() {
return !!this.config?.ENABLED;
}

public async onModuleInit() {
if (this.config.ENABLED) {
const url = `http://${this.config.HOST}:${this.config.PORT}`;
try {
const response = await axios.options(url + '/ping');
if (response?.data != 'pong') {
throw new Error('Offline file provider.');
}

await axios.post(`${url}/session`, { group: this.config.PREFIX }, { headers: { apikey: this.globalApiToken } });
} catch (error) {
this.logger.error(['Failed to connect to the file server', error?.message, error?.stack]);
const pid = process.pid;
execSync(`kill -9 ${pid}`);
}
}
}

public async onModuleDestroy() {
//
}

public async create(instance: string): ResponseProvider {
try {
const response = await axios.post(
`${this.baseUrl}`,
{
instance,
},
{ headers: { apikey: this.globalApiToken } },
);
return [{ status: response.status, data: response?.data }];
} catch (error) {
return [
{
status: error?.response?.status,
data: error?.response?.data,
},
error,
];
}
}

public async write(instance: string, key: string, data: any): ResponseProvider {
try {
const response = await axios.post(`${this.baseUrl}/${instance}/${key}`, data, {
headers: { apikey: this.globalApiToken },
});
return [{ status: response.status, data: response?.data }];
} catch (error) {
return [
{
status: error?.response?.status,
data: error?.response?.data,
},
error,
];
}
}

public async read(instance: string, key: string): ResponseProvider {
try {
const response = await axios.get(`${this.baseUrl}/${instance}/${key}`, {
headers: { apikey: this.globalApiToken },
});
return [{ status: response.status, data: response?.data }];
} catch (error) {
return [
{
status: error?.response?.status,
data: error?.response?.data,
},
error,
];
}
}

public async delete(instance: string, key: string): ResponseProvider {
try {
const response = await axios.delete(`${this.baseUrl}/${instance}/${key}`, {
headers: { apikey: this.globalApiToken },
});
return [{ status: response.status, data: response?.data }];
} catch (error) {
return [
{
status: error?.response?.status,
data: error?.response?.data,
},
error,
];
}
}

public async allInstances(): ResponseProvider {
try {
const response = await axios.get(`${this.baseUrl}/list-instances`, { headers: { apikey: this.globalApiToken } });
return [{ status: response.status, data: response?.data as string[] }];
} catch (error) {
return [
{
status: error?.response?.status,
data: error?.response?.data,
},
error,
];
}
}

public async removeSession(instance: string): ResponseProvider {
try {
const response = await axios.delete(`${this.baseUrl}/${instance}`, { headers: { apikey: this.globalApiToken } });
return [{ status: response.status, data: response?.data }];
} catch (error) {
return [
{
status: error?.response?.status,
data: error?.response?.data,
},
error,
];
}
}
}
10 changes: 7 additions & 3 deletions src/api/server.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
WebsocketModel,
} from './models';
import { LabelModel } from './models/label.model';
import { ProviderFiles } from './provider/sessions';
import { AuthRepository } from './repository/auth.repository';
import { ChatRepository } from './repository/chat.repository';
import { ContactRepository } from './repository/contact.repository';
Expand Down Expand Up @@ -108,15 +109,17 @@ export const repository = new RepositoryBroker(

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());
const baileysCache = new CacheService(new CacheEngine(configService, 'baileys').getEngine());
const providerFiles = new ProviderFiles(configService);

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

const authService = new AuthService(configService, waMonitor, repository);
Expand Down Expand Up @@ -167,7 +170,8 @@ export const instanceController = new InstanceController(
proxyController,
cache,
chatwootCache,
messagesLostCache,
baileysCache,
providerFiles,
);
export const sendMessageController = new SendMessageController(waMonitor);
export const chatController = new ChatController(waMonitor);
Expand Down
Loading

0 comments on commit bd06920

Please sign in to comment.