Skip to content

Commit 8fe75cd

Browse files
committed
Merge branch 'release/1.5.4'
2 parents e55cb08 + 303effe commit 8fe75cd

File tree

9 files changed

+151
-20
lines changed

9 files changed

+151
-20
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
# 1.5.4 (2023-10-09 20:43)
2+
3+
### Fixed
4+
5+
* Baileys logger typing issue resolved
6+
* Solved problem with duplicate messages in chatwoot
7+
18
# 1.5.3 (2023-10-06 18:55)
29

310
### Feature

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
FROM node:20.7.0-alpine
22

3-
LABEL version="1.5.3" description="Api to control whatsapp features through http requests."
3+
LABEL version="1.5.4" description="Api to control whatsapp features through http requests."
44
LABEL maintainer="Davidson Gomes" git="https://github.com/DavidsonGomes"
55
LABEL contact="contato@agenciadgcode.com"
66

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.5.3",
3+
"version": "1.5.4",
44
"description": "Rest api for communication with WhatsApp",
55
"main": "./dist/src/main.js",
66
"scripts": {

src/docs/swagger.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ info:
2525
</font>
2626
2727
[![Run in Postman](https://run.pstmn.io/button.svg)](https://god.gw.postman.com/run-collection/26869335-5546d063-156b-4529-915f-909dd628c090?action=collection%2Ffork&source=rip_markdown&collection-url=entityId%3D26869335-5546d063-156b-4529-915f-909dd628c090%26entityType%3Dcollection%26workspaceId%3D339a4ee7-378b-45c9-b5b8-fd2c0a9c2442)
28-
version: 1.5.2
28+
version: 1.5.4
2929
contact:
3030
name: DavidsonGomes
3131
email: contato@agenciadgcode.com

src/whatsapp/controllers/views.controller.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,21 @@
11
import { Request, Response } from 'express';
22

3-
import { ConfigService } from '../../config/env.config';
3+
import { Auth, ConfigService, HttpServer } from '../../config/env.config';
44
import { HttpStatus } from '../routers/index.router';
55
import { WAMonitoringService } from '../services/monitor.service';
66

77
export class ViewsController {
8-
constructor(private readonly waMonit: WAMonitoringService, private readonly configService: ConfigService) {}
8+
constructor(private readonly waMonitor: WAMonitoringService, private readonly configService: ConfigService) {}
99

1010
public async manager(request: Request, response: Response) {
1111
try {
12-
return response.status(HttpStatus.OK).render('manager');
12+
const token = this.configService.get<Auth>('AUTHENTICATION').API_KEY.KEY;
13+
const port = this.configService.get<HttpServer>('SERVER').PORT;
14+
15+
const instances = await this.waMonitor.instanceInfo();
16+
17+
console.log('INSTANCES: ', instances);
18+
return response.status(HttpStatus.OK).render('manager', { token, port, instances });
1319
} catch (error) {
1420
console.log('ERROR: ', error);
1521
}

src/whatsapp/services/chatwoot.service.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,7 @@ export class ChatwootService {
914914
},
915915
};
916916

917-
await waInstance?.audioWhatsapp(data);
917+
await waInstance?.audioWhatsapp(data, true);
918918

919919
this.logger.verbose('audio sent');
920920
return;
@@ -939,7 +939,7 @@ export class ChatwootService {
939939
data.mediaMessage.caption = caption;
940940
}
941941

942-
await waInstance?.mediaMessage(data);
942+
await waInstance?.mediaMessage(data, true);
943943

944944
this.logger.verbose('media sent');
945945
return;
@@ -1074,7 +1074,7 @@ export class ChatwootService {
10741074
},
10751075
};
10761076

1077-
await waInstance?.textMessage(data);
1077+
await waInstance?.textMessage(data, true);
10781078
}
10791079
}
10801080
}

src/whatsapp/services/whatsapp.service.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,7 +1193,7 @@ export class WAStartupService {
11931193
...options,
11941194
auth: {
11951195
creds: this.instance.authState.state.creds,
1196-
keys: makeCacheableSignalKeyStore(this.instance.authState.state.keys, P({ level: 'error' })),
1196+
keys: makeCacheableSignalKeyStore(this.instance.authState.state.keys, P({ level: 'error' }) as any),
11971197
},
11981198
logger: P({ level: this.logBaileys }),
11991199
printQRInTerminal: false,
@@ -1273,7 +1273,7 @@ export class WAStartupService {
12731273
...options,
12741274
auth: {
12751275
creds: this.instance.authState.state.creds,
1276-
keys: makeCacheableSignalKeyStore(this.instance.authState.state.keys, P({ level: 'error' })),
1276+
keys: makeCacheableSignalKeyStore(this.instance.authState.state.keys, P({ level: 'error' }) as any),
12771277
},
12781278
logger: P({ level: this.logBaileys }),
12791279
printQRInTerminal: false,
@@ -1542,7 +1542,7 @@ export class WAStartupService {
15421542
'buffer',
15431543
{},
15441544
{
1545-
logger: P({ level: 'error' }),
1545+
logger: P({ level: 'error' }) as any,
15461546
reuploadRequest: this.client.updateMediaMessage,
15471547
},
15481548
);
@@ -2061,7 +2061,12 @@ export class WAStartupService {
20612061
}
20622062
}
20632063

2064-
private async sendMessageWithTyping<T = proto.IMessage>(number: string, message: T, options?: Options) {
2064+
private async sendMessageWithTyping<T = proto.IMessage>(
2065+
number: string,
2066+
message: T,
2067+
options?: Options,
2068+
isChatwoot = false,
2069+
) {
20652070
this.logger.verbose('Sending message with typing');
20662071

20672072
this.logger.verbose(`Check if number "${number}" is WhatsApp`);
@@ -2219,7 +2224,7 @@ export class WAStartupService {
22192224
this.logger.verbose('Sending data to webhook in event SEND_MESSAGE');
22202225
await this.sendDataWebhook(Events.SEND_MESSAGE, messageRaw);
22212226

2222-
if (this.localChatwoot.enabled) {
2227+
if (this.localChatwoot.enabled && !isChatwoot) {
22232228
this.chatwootService.eventWhatsapp(Events.SEND_MESSAGE, { instanceName: this.instance.name }, messageRaw);
22242229
}
22252230

@@ -2244,14 +2249,15 @@ export class WAStartupService {
22442249
}
22452250

22462251
// Send Message Controller
2247-
public async textMessage(data: SendTextDto) {
2252+
public async textMessage(data: SendTextDto, isChatwoot = false) {
22482253
this.logger.verbose('Sending text message');
22492254
return await this.sendMessageWithTyping(
22502255
data.number,
22512256
{
22522257
conversation: data.textMessage.text,
22532258
},
22542259
data?.options,
2260+
isChatwoot,
22552261
);
22562262
}
22572263

@@ -2528,11 +2534,11 @@ export class WAStartupService {
25282534
return result;
25292535
}
25302536

2531-
public async mediaMessage(data: SendMediaDto) {
2537+
public async mediaMessage(data: SendMediaDto, isChatwoot = false) {
25322538
this.logger.verbose('Sending media message');
25332539
const generate = await this.prepareMediaMessage(data.mediaMessage);
25342540

2535-
return await this.sendMessageWithTyping(data.number, { ...generate.message }, data?.options);
2541+
return await this.sendMessageWithTyping(data.number, { ...generate.message }, data?.options, isChatwoot);
25362542
}
25372543

25382544
public async processAudio(audio: string, number: string) {
@@ -2589,7 +2595,7 @@ export class WAStartupService {
25892595
});
25902596
}
25912597

2592-
public async audioWhatsapp(data: SendAudioDto) {
2598+
public async audioWhatsapp(data: SendAudioDto, isChatwoot = false) {
25932599
this.logger.verbose('Sending audio whatsapp');
25942600

25952601
if (!data.options?.encoding && data.options?.encoding !== false) {
@@ -2608,6 +2614,7 @@ export class WAStartupService {
26082614
mimetype: 'audio/mp4',
26092615
},
26102616
{ presence: 'recording', delay: data?.options?.delay },
2617+
isChatwoot,
26112618
);
26122619

26132620
fs.unlinkSync(convert);
@@ -2629,6 +2636,7 @@ export class WAStartupService {
26292636
mimetype: 'audio/ogg; codecs=opus',
26302637
},
26312638
{ presence: 'recording', delay: data?.options?.delay },
2639+
isChatwoot,
26322640
);
26332641
}
26342642

@@ -2939,7 +2947,7 @@ export class WAStartupService {
29392947
'buffer',
29402948
{},
29412949
{
2942-
logger: P({ level: 'error' }),
2950+
logger: P({ level: 'error' }) as any,
29432951
reuploadRequest: this.client.updateMediaMessage,
29442952
},
29452953
);

views/manager-wip.hbs

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<!DOCTYPE html>
2+
<html lang="pt-br">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8+
<link rel="shortcut icon" href="https://evolution-api.com/files/evolution-api-favicon.png" type="image/x-icon">
9+
10+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/css/bootstrap.min.css"
11+
integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
12+
<title>Instance Manager</title>
13+
</head>
14+
15+
<body>
16+
<div class="container mt-4">
17+
<!-- Botão para abrir o modal de adicionar nova instância -->
18+
<button class="btn btn-primary mb-3" data-toggle="modal" data-target="#actionModal" data-action="add">Nova
19+
Instância</button>
20+
21+
<!-- Tabela de instâncias -->
22+
<table class="table table-bordered">
23+
<thead>
24+
<tr>
25+
<th>Nome da Instância</th>
26+
<th>Status</th>
27+
<th>API Key</th>
28+
<th>Ações</th>
29+
</tr>
30+
</thead>
31+
<tbody>
32+
<!-- Iterando sobre as instâncias e preenchendo a tabela -->
33+
{{#each instances}}
34+
<tr>
35+
<td>{{this.instance.instanceName}}</td>
36+
<td>{{this.instance.status}}</td>
37+
<td>{{this.instance.apikey}}</td>
38+
<td>
39+
<!-- Dropdown de ações para cada instância -->
40+
<div class="dropdown">
41+
<button class="btn btn-secondary dropdown-toggle" type="button" id="actionDropdown"
42+
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
43+
Ações
44+
</button>
45+
<div class="dropdown-menu" aria-labelledby="actionDropdown">
46+
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#actionModal"
47+
data-action="connect">Connect</a>
48+
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#actionModal"
49+
data-action="restart">Restart</a>
50+
<!-- Adicione mais itens de ação aqui -->
51+
<!-- ... -->
52+
</div>
53+
</div>
54+
</td>
55+
</tr>
56+
{{/each}}
57+
</tbody>
58+
</table>
59+
</div>
60+
61+
<!-- Modal de ações -->
62+
<div class="modal fade" id="actionModal" tabindex="-1" role="dialog" aria-labelledby="actionModalLabel"
63+
aria-hidden="true">
64+
<div class="modal-dialog" role="document">
65+
<div class="modal-content">
66+
<div class="modal-header">
67+
<h5 class="modal-title" id="actionModalLabel">Ação</h5>
68+
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
69+
<span aria-hidden="true">&times;</span>
70+
</button>
71+
</div>
72+
<div class="modal-body">
73+
</div>
74+
<div class="modal-footer">
75+
<button type="button" class="btn btn-secondary" data-dismiss="modal">Fechar</button>
76+
<button type="button" class="btn btn-primary">Salvar</button>
77+
</div>
78+
</div>
79+
</div>
80+
</div>
81+
82+
<script src="https://cdn.jsdelivr.net/npm/jquery@3.5.1/dist/jquery.slim.min.js"
83+
integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
84+
crossorigin="anonymous"></script>
85+
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"
86+
integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN"
87+
crossorigin="anonymous"></script>
88+
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/dist/js/bootstrap.min.js"
89+
integrity="sha384-+sLIOodYLS7CIrQpBjl+C7nPvqq+FbNUBDunl/OZv93DB7Ln/533i8e/mZXLi/P+"
90+
crossorigin="anonymous"></script>
91+
92+
<script>
93+
$(document).ready(function(){
94+
$('#actionModal').on('show.bs.modal', function(event) {
95+
var button = $(event.relatedTarget);
96+
var action = button.data('action');
97+
98+
console.log(action);
99+
100+
if (action === 'connect') {
101+
102+
} else if (action === 'restart') {
103+
104+
}
105+
});
106+
})
107+
</script>
108+
</body>
109+
110+
</html>

views/manager.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<body>
1313

14-
<iframe src="https://app.smith.dgcode.com.br/app/evolutionapi-public/home-64ca60783615e270291978b4?embed=true" frameborder="0" style="width: 100%; height: 100vh;"></iframe>
14+
<iframe src="https://manager.evolution-api.com" frameborder="0" style="width: 100%; height: 100vh;"></iframe>
1515

1616
</body>
1717

0 commit comments

Comments
 (0)