Skip to content

Commit

Permalink
Merge branch 'release/1.5.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidsonGomes committed Oct 9, 2023
2 parents e55cb08 + 303effe commit 8fe75cd
Show file tree
Hide file tree
Showing 9 changed files with 151 additions and 20 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# 1.5.4 (2023-10-09 20:43)

### Fixed

* Baileys logger typing issue resolved
* Solved problem with duplicate messages in chatwoot

# 1.5.3 (2023-10-06 18:55)

### Feature
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM node:20.7.0-alpine

LABEL version="1.5.3" description="Api to control whatsapp features through http requests."
LABEL version="1.5.4" description="Api to control whatsapp features through http requests."
LABEL maintainer="Davidson Gomes" git="https://github.com/DavidsonGomes"
LABEL contact="[email protected]"

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.5.3",
"version": "1.5.4",
"description": "Rest api for communication with WhatsApp",
"main": "./dist/src/main.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion src/docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ info:
</font>
[![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)
version: 1.5.2
version: 1.5.4
contact:
name: DavidsonGomes
email: [email protected]
Expand Down
12 changes: 9 additions & 3 deletions src/whatsapp/controllers/views.controller.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import { Request, Response } from 'express';

import { ConfigService } from '../../config/env.config';
import { Auth, ConfigService, HttpServer } from '../../config/env.config';
import { HttpStatus } from '../routers/index.router';
import { WAMonitoringService } from '../services/monitor.service';

export class ViewsController {
constructor(private readonly waMonit: WAMonitoringService, private readonly configService: ConfigService) {}
constructor(private readonly waMonitor: WAMonitoringService, private readonly configService: ConfigService) {}

public async manager(request: Request, response: Response) {
try {
return response.status(HttpStatus.OK).render('manager');
const token = this.configService.get<Auth>('AUTHENTICATION').API_KEY.KEY;
const port = this.configService.get<HttpServer>('SERVER').PORT;

const instances = await this.waMonitor.instanceInfo();

console.log('INSTANCES: ', instances);
return response.status(HttpStatus.OK).render('manager', { token, port, instances });
} catch (error) {
console.log('ERROR: ', error);
}
Expand Down
6 changes: 3 additions & 3 deletions src/whatsapp/services/chatwoot.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ export class ChatwootService {
},
};

await waInstance?.audioWhatsapp(data);
await waInstance?.audioWhatsapp(data, true);

this.logger.verbose('audio sent');
return;
Expand All @@ -939,7 +939,7 @@ export class ChatwootService {
data.mediaMessage.caption = caption;
}

await waInstance?.mediaMessage(data);
await waInstance?.mediaMessage(data, true);

this.logger.verbose('media sent');
return;
Expand Down Expand Up @@ -1074,7 +1074,7 @@ export class ChatwootService {
},
};

await waInstance?.textMessage(data);
await waInstance?.textMessage(data, true);
}
}
}
Expand Down
28 changes: 18 additions & 10 deletions src/whatsapp/services/whatsapp.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,7 @@ export class WAStartupService {
...options,
auth: {
creds: this.instance.authState.state.creds,
keys: makeCacheableSignalKeyStore(this.instance.authState.state.keys, P({ level: 'error' })),
keys: makeCacheableSignalKeyStore(this.instance.authState.state.keys, P({ level: 'error' }) as any),
},
logger: P({ level: this.logBaileys }),
printQRInTerminal: false,
Expand Down Expand Up @@ -1273,7 +1273,7 @@ export class WAStartupService {
...options,
auth: {
creds: this.instance.authState.state.creds,
keys: makeCacheableSignalKeyStore(this.instance.authState.state.keys, P({ level: 'error' })),
keys: makeCacheableSignalKeyStore(this.instance.authState.state.keys, P({ level: 'error' }) as any),
},
logger: P({ level: this.logBaileys }),
printQRInTerminal: false,
Expand Down Expand Up @@ -1542,7 +1542,7 @@ export class WAStartupService {
'buffer',
{},
{
logger: P({ level: 'error' }),
logger: P({ level: 'error' }) as any,
reuploadRequest: this.client.updateMediaMessage,
},
);
Expand Down Expand Up @@ -2061,7 +2061,12 @@ export class WAStartupService {
}
}

private async sendMessageWithTyping<T = proto.IMessage>(number: string, message: T, options?: Options) {
private async sendMessageWithTyping<T = proto.IMessage>(
number: string,
message: T,
options?: Options,
isChatwoot = false,
) {
this.logger.verbose('Sending message with typing');

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

if (this.localChatwoot.enabled) {
if (this.localChatwoot.enabled && !isChatwoot) {
this.chatwootService.eventWhatsapp(Events.SEND_MESSAGE, { instanceName: this.instance.name }, messageRaw);
}

Expand All @@ -2244,14 +2249,15 @@ export class WAStartupService {
}

// Send Message Controller
public async textMessage(data: SendTextDto) {
public async textMessage(data: SendTextDto, isChatwoot = false) {
this.logger.verbose('Sending text message');
return await this.sendMessageWithTyping(
data.number,
{
conversation: data.textMessage.text,
},
data?.options,
isChatwoot,
);
}

Expand Down Expand Up @@ -2528,11 +2534,11 @@ export class WAStartupService {
return result;
}

public async mediaMessage(data: SendMediaDto) {
public async mediaMessage(data: SendMediaDto, isChatwoot = false) {
this.logger.verbose('Sending media message');
const generate = await this.prepareMediaMessage(data.mediaMessage);

return await this.sendMessageWithTyping(data.number, { ...generate.message }, data?.options);
return await this.sendMessageWithTyping(data.number, { ...generate.message }, data?.options, isChatwoot);
}

public async processAudio(audio: string, number: string) {
Expand Down Expand Up @@ -2589,7 +2595,7 @@ export class WAStartupService {
});
}

public async audioWhatsapp(data: SendAudioDto) {
public async audioWhatsapp(data: SendAudioDto, isChatwoot = false) {
this.logger.verbose('Sending audio whatsapp');

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

fs.unlinkSync(convert);
Expand All @@ -2629,6 +2636,7 @@ export class WAStartupService {
mimetype: 'audio/ogg; codecs=opus',
},
{ presence: 'recording', delay: data?.options?.delay },
isChatwoot,
);
}

Expand Down Expand Up @@ -2939,7 +2947,7 @@ export class WAStartupService {
'buffer',
{},
{
logger: P({ level: 'error' }),
logger: P({ level: 'error' }) as any,
reuploadRequest: this.client.updateMediaMessage,
},
);
Expand Down
110 changes: 110 additions & 0 deletions views/manager-wip.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<!DOCTYPE html>
<html lang="pt-br">

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="https://evolution-api.com/files/evolution-api-favicon.png" type="image/x-icon">

<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css"
integrity="sha384-xOolHFLEh07PJGoPkLv1IbcEPTNtaed2xpHsD9ESMhqIYd0nLMwNLD69Npy4HI+N" crossorigin="anonymous">
<title>Instance Manager</title>
</head>

<body>
<div class="container mt-4">
<!-- Botão para abrir o modal de adicionar nova instância -->
<button class="btn btn-primary mb-3" data-toggle="modal" data-target="#actionModal" data-action="add">Nova
Instância</button>

<!-- Tabela de instâncias -->
<table class="table table-bordered">
<thead>
<tr>
<th>Nome da Instância</th>
<th>Status</th>
<th>API Key</th>
<th>Ações</th>
</tr>
</thead>
<tbody>
<!-- Iterando sobre as instâncias e preenchendo a tabela -->
{{#each instances}}
<tr>
<td>{{this.instance.instanceName}}</td>
<td>{{this.instance.status}}</td>
<td>{{this.instance.apikey}}</td>
<td>
<!-- Dropdown de ações para cada instância -->
<div class="dropdown">
<button class="btn btn-secondary dropdown-toggle" type="button" id="actionDropdown"
data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Ações
</button>
<div class="dropdown-menu" aria-labelledby="actionDropdown">
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#actionModal"
data-action="connect">Connect</a>
<a class="dropdown-item" href="#" data-toggle="modal" data-target="#actionModal"
data-action="restart">Restart</a>
<!-- Adicione mais itens de ação aqui -->
<!-- ... -->
</div>
</div>
</td>
</tr>
{{/each}}
</tbody>
</table>
</div>

<!-- Modal de ações -->
<div class="modal fade" id="actionModal" tabindex="-1" role="dialog" aria-labelledby="actionModalLabel"
aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="actionModalLabel">Ação</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Fechar</button>
<button type="button" class="btn btn-primary">Salvar</button>
</div>
</div>
</div>
</div>

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.slim.min.js"
integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js"
integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN"
crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js"
integrity="sha384-+sLIOodYLS7CIrQpBjl+C7nPvqq+FbNUBDunl/OZv93DB7Ln/533i8e/mZXLi/P+"
crossorigin="anonymous"></script>

<script>
$(document).ready(function(){
$('#actionModal').on('show.bs.modal', function(event) {
var button = $(event.relatedTarget);
var action = button.data('action');
console.log(action);
if (action === 'connect') {
} else if (action === 'restart') {
}
});
})
</script>
</body>

</html>
2 changes: 1 addition & 1 deletion views/manager.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<body>

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

</body>

Expand Down

0 comments on commit 8fe75cd

Please sign in to comment.