Skip to content

Commit bd06920

Browse files
committed
Merge branch 'release/1.8.1'
2 parents 0e9d036 + c898f1e commit bd06920

File tree

15 files changed

+529
-42
lines changed

15 files changed

+529
-42
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
# 1.8.1 (2024-06-08 21:32)
2+
3+
### Feature
4+
5+
* New method of saving sessions to a file using worker, made in partnership with [codechat](https://github.com/code-chat-br/whatsapp-api)
6+
7+
### Fixed
8+
9+
* Correction of variables breaking lines in typebot
10+
111
# 1.8.0 (2024-05-27 16:10)
212

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

919
### Fixed
20+
1021
* Correction in message formatting when generated by AI as markdown in typebot
1122
* Security fix in fetch instance with client key when not connected to mongodb
1223

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

1526
### Fixed
27+
1628
* Add merge_brazil_contacts function to solve nine digit in brazilian numbers
1729
* Optimize ChatwootService method for updating contact
1830
* Fix swagger auth
@@ -24,6 +36,7 @@
2436
# 1.7.4 (2024-04-28 09:46)
2537

2638
### Fixed
39+
2740
* Adjusts in proxy on fetchAgent
2841
* Recovering messages lost with redis cache
2942
* Log when init redis cache service
@@ -34,6 +47,7 @@
3447
# 1.7.3 (2024-04-18 12:07)
3548

3649
### Fixed
50+
3751
* Revert fix audio encoding
3852
* Recovering messages lost with redis cache
3953
* Adjusts in redis for save instances

Docker/.env.example

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

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

4239
# Choose the data you want to save in the application's database or store
@@ -137,7 +134,7 @@ CONFIG_SESSION_PHONE_NAME=Chrome
137134

138135
# Set qrcode display limit
139136
QRCODE_LIMIT=30
140-
QRCODE_COLOR=#198754
137+
QRCODE_COLOR='#198754'
141138

142139
# old | latest
143140
TYPEBOT_API_VERSION=latest

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "evolution-api",
3-
"version": "1.8.0",
3+
"version": "1.8.1",
44
"description": "Rest api for communication with WhatsApp",
55
"main": "./dist/src/main.js",
66
"scripts": {
@@ -49,7 +49,7 @@
4949
"amqplib": "^0.10.3",
5050
"@aws-sdk/client-sqs": "^3.569.0",
5151
"axios": "^1.6.5",
52-
"@whiskeysockets/baileys": "^6.7.2",
52+
"@whiskeysockets/baileys": "6.7.4",
5353
"class-validator": "^0.14.1",
5454
"compression": "^1.7.4",
5555
"cors": "^2.8.5",

src/api/controllers/instance.controller.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { RabbitmqService } from '../integrations/rabbitmq/services/rabbitmq.serv
1212
import { SqsService } from '../integrations/sqs/services/sqs.service';
1313
import { TypebotService } from '../integrations/typebot/services/typebot.service';
1414
import { WebsocketService } from '../integrations/websocket/services/websocket.service';
15+
import { ProviderFiles } from '../provider/sessions';
1516
import { RepositoryBroker } from '../repository/repository.manager';
1617
import { AuthService, OldToken } from '../services/auth.service';
1718
import { CacheService } from '../services/cache.service';
@@ -42,7 +43,8 @@ export class InstanceController {
4243
private readonly proxyService: ProxyController,
4344
private readonly cache: CacheService,
4445
private readonly chatwootCache: CacheService,
45-
private readonly messagesLostCache: CacheService,
46+
private readonly baileysCache: CacheService,
47+
private readonly providerFiles: ProviderFiles,
4648
) {}
4749

4850
private readonly logger = new Logger(InstanceController.name);
@@ -110,7 +112,8 @@ export class InstanceController {
110112
this.repository,
111113
this.cache,
112114
this.chatwootCache,
113-
this.messagesLostCache,
115+
this.baileysCache,
116+
this.providerFiles,
114117
);
115118
} else {
116119
instance = new BaileysStartupService(
@@ -119,7 +122,8 @@ export class InstanceController {
119122
this.repository,
120123
this.cache,
121124
this.chatwootCache,
122-
this.messagesLostCache,
125+
this.baileysCache,
126+
this.providerFiles,
123127
);
124128
}
125129

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

751755
try {
752-
this.waMonitor.waInstances[instanceName].sendDataWebhook(Events.INSTANCE_DELETE, {
756+
this.waMonitor.waInstances[instanceName]?.sendDataWebhook(Events.INSTANCE_DELETE, {
753757
instanceName,
754758
instanceId: (await this.repository.auth.find(instanceName))?.instanceId,
755759
});

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,10 @@ export class ChatwootService {
10921092
return messageSent;
10931093
}
10941094

1095+
if (type === 'image' && parsedMedia && parsedMedia?.ext === '.gif') {
1096+
type = 'document';
1097+
}
1098+
10951099
this.logger.verbose('send media to instance: ' + waInstance.instanceName);
10961100
const data: SendMediaDto = {
10971101
number: number,

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,10 +525,14 @@ export class TypebotService {
525525
}
526526
}
527527

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

532+
if (element.type === 'inline-variable') {
533+
text = text.trim();
534+
}
535+
532536
if (element.type === 'ol') {
533537
text =
534538
'\n' +
@@ -582,6 +586,8 @@ export class TypebotService {
582586

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

589+
formattedText = formattedText.replace(/\n$/, '');
590+
585591
await instance.textMessage({
586592
number: remoteJid.split('@')[0],
587593
options: {

src/api/provider/sessions.ts

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
import axios from 'axios';
2+
import { execSync } from 'child_process';
3+
4+
import { Auth, ConfigService, ProviderSession } from '../../config/env.config';
5+
import { Logger } from '../../config/logger.config';
6+
7+
type ResponseSuccess = { status: number; data?: any };
8+
type ResponseProvider = Promise<[ResponseSuccess?, Error?]>;
9+
10+
export class ProviderFiles {
11+
constructor(private readonly configService: ConfigService) {
12+
this.baseUrl = `http://${this.config.HOST}:${this.config.PORT}/session/${this.config.PREFIX}`;
13+
this.globalApiToken = this.configService.get<Auth>('AUTHENTICATION').API_KEY.KEY;
14+
}
15+
16+
private readonly logger = new Logger(ProviderFiles.name);
17+
18+
private baseUrl: string;
19+
private globalApiToken: string;
20+
21+
private readonly config = Object.freeze(this.configService.get<ProviderSession>('PROVIDER'));
22+
23+
get isEnabled() {
24+
return !!this.config?.ENABLED;
25+
}
26+
27+
public async onModuleInit() {
28+
if (this.config.ENABLED) {
29+
const url = `http://${this.config.HOST}:${this.config.PORT}`;
30+
try {
31+
const response = await axios.options(url + '/ping');
32+
if (response?.data != 'pong') {
33+
throw new Error('Offline file provider.');
34+
}
35+
36+
await axios.post(`${url}/session`, { group: this.config.PREFIX }, { headers: { apikey: this.globalApiToken } });
37+
} catch (error) {
38+
this.logger.error(['Failed to connect to the file server', error?.message, error?.stack]);
39+
const pid = process.pid;
40+
execSync(`kill -9 ${pid}`);
41+
}
42+
}
43+
}
44+
45+
public async onModuleDestroy() {
46+
//
47+
}
48+
49+
public async create(instance: string): ResponseProvider {
50+
try {
51+
const response = await axios.post(
52+
`${this.baseUrl}`,
53+
{
54+
instance,
55+
},
56+
{ headers: { apikey: this.globalApiToken } },
57+
);
58+
return [{ status: response.status, data: response?.data }];
59+
} catch (error) {
60+
return [
61+
{
62+
status: error?.response?.status,
63+
data: error?.response?.data,
64+
},
65+
error,
66+
];
67+
}
68+
}
69+
70+
public async write(instance: string, key: string, data: any): ResponseProvider {
71+
try {
72+
const response = await axios.post(`${this.baseUrl}/${instance}/${key}`, data, {
73+
headers: { apikey: this.globalApiToken },
74+
});
75+
return [{ status: response.status, data: response?.data }];
76+
} catch (error) {
77+
return [
78+
{
79+
status: error?.response?.status,
80+
data: error?.response?.data,
81+
},
82+
error,
83+
];
84+
}
85+
}
86+
87+
public async read(instance: string, key: string): ResponseProvider {
88+
try {
89+
const response = await axios.get(`${this.baseUrl}/${instance}/${key}`, {
90+
headers: { apikey: this.globalApiToken },
91+
});
92+
return [{ status: response.status, data: response?.data }];
93+
} catch (error) {
94+
return [
95+
{
96+
status: error?.response?.status,
97+
data: error?.response?.data,
98+
},
99+
error,
100+
];
101+
}
102+
}
103+
104+
public async delete(instance: string, key: string): ResponseProvider {
105+
try {
106+
const response = await axios.delete(`${this.baseUrl}/${instance}/${key}`, {
107+
headers: { apikey: this.globalApiToken },
108+
});
109+
return [{ status: response.status, data: response?.data }];
110+
} catch (error) {
111+
return [
112+
{
113+
status: error?.response?.status,
114+
data: error?.response?.data,
115+
},
116+
error,
117+
];
118+
}
119+
}
120+
121+
public async allInstances(): ResponseProvider {
122+
try {
123+
const response = await axios.get(`${this.baseUrl}/list-instances`, { headers: { apikey: this.globalApiToken } });
124+
return [{ status: response.status, data: response?.data as string[] }];
125+
} catch (error) {
126+
return [
127+
{
128+
status: error?.response?.status,
129+
data: error?.response?.data,
130+
},
131+
error,
132+
];
133+
}
134+
}
135+
136+
public async removeSession(instance: string): ResponseProvider {
137+
try {
138+
const response = await axios.delete(`${this.baseUrl}/${instance}`, { headers: { apikey: this.globalApiToken } });
139+
return [{ status: response.status, data: response?.data }];
140+
} catch (error) {
141+
return [
142+
{
143+
status: error?.response?.status,
144+
data: error?.response?.data,
145+
},
146+
error,
147+
];
148+
}
149+
}
150+
}

src/api/server.module.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import {
4747
WebsocketModel,
4848
} from './models';
4949
import { LabelModel } from './models/label.model';
50+
import { ProviderFiles } from './provider/sessions';
5051
import { AuthRepository } from './repository/auth.repository';
5152
import { ChatRepository } from './repository/chat.repository';
5253
import { ContactRepository } from './repository/contact.repository';
@@ -108,15 +109,17 @@ export const repository = new RepositoryBroker(
108109

109110
export const cache = new CacheService(new CacheEngine(configService, 'instance').getEngine());
110111
const chatwootCache = new CacheService(new CacheEngine(configService, ChatwootService.name).getEngine());
111-
const messagesLostCache = new CacheService(new CacheEngine(configService, 'baileys').getEngine());
112+
const baileysCache = new CacheService(new CacheEngine(configService, 'baileys').getEngine());
113+
const providerFiles = new ProviderFiles(configService);
112114

113115
export const waMonitor = new WAMonitoringService(
114116
eventEmitter,
115117
configService,
116118
repository,
117119
cache,
118120
chatwootCache,
119-
messagesLostCache,
121+
baileysCache,
122+
providerFiles,
120123
);
121124

122125
const authService = new AuthService(configService, waMonitor, repository);
@@ -167,7 +170,8 @@ export const instanceController = new InstanceController(
167170
proxyController,
168171
cache,
169172
chatwootCache,
170-
messagesLostCache,
173+
baileysCache,
174+
providerFiles,
171175
);
172176
export const sendMessageController = new SendMessageController(waMonitor);
173177
export const chatController = new ChatController(waMonitor);

0 commit comments

Comments
 (0)