mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-14 09:51:24 -06:00
fix: Solved problem with duplicate messages in chatwoot
This commit is contained in:
parent
29fd448998
commit
62c74deac3
@ -1,3 +1,10 @@
|
|||||||
|
# 1.5.4 (develop)
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
* Baileys logger typing issue resolved
|
||||||
|
* Solved problem with duplicate messages in chatwoot
|
||||||
|
|
||||||
# 1.5.3 (2023-10-06 18:55)
|
# 1.5.3 (2023-10-06 18:55)
|
||||||
|
|
||||||
### Feature
|
### Feature
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
FROM node:20.7.0-alpine
|
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 maintainer="Davidson Gomes" git="https://github.com/DavidsonGomes"
|
||||||
LABEL contact="contato@agenciadgcode.com"
|
LABEL contact="contato@agenciadgcode.com"
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "evolution-api",
|
"name": "evolution-api",
|
||||||
"version": "1.5.3",
|
"version": "1.5.4",
|
||||||
"description": "Rest api for communication with WhatsApp",
|
"description": "Rest api for communication with WhatsApp",
|
||||||
"main": "./dist/src/main.js",
|
"main": "./dist/src/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
@ -25,7 +25,7 @@ info:
|
|||||||
</font>
|
</font>
|
||||||
|
|
||||||
[](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)
|
[](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:
|
contact:
|
||||||
name: DavidsonGomes
|
name: DavidsonGomes
|
||||||
email: contato@agenciadgcode.com
|
email: contato@agenciadgcode.com
|
||||||
|
@ -1,15 +1,21 @@
|
|||||||
import { Request, Response } from 'express';
|
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 { HttpStatus } from '../routers/index.router';
|
||||||
import { WAMonitoringService } from '../services/monitor.service';
|
import { WAMonitoringService } from '../services/monitor.service';
|
||||||
|
|
||||||
export class ViewsController {
|
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) {
|
public async manager(request: Request, response: Response) {
|
||||||
try {
|
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) {
|
} catch (error) {
|
||||||
console.log('ERROR: ', error);
|
console.log('ERROR: ', error);
|
||||||
}
|
}
|
||||||
|
@ -914,7 +914,7 @@ export class ChatwootService {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
await waInstance?.audioWhatsapp(data);
|
await waInstance?.audioWhatsapp(data, true);
|
||||||
|
|
||||||
this.logger.verbose('audio sent');
|
this.logger.verbose('audio sent');
|
||||||
return;
|
return;
|
||||||
@ -939,7 +939,7 @@ export class ChatwootService {
|
|||||||
data.mediaMessage.caption = caption;
|
data.mediaMessage.caption = caption;
|
||||||
}
|
}
|
||||||
|
|
||||||
await waInstance?.mediaMessage(data);
|
await waInstance?.mediaMessage(data, true);
|
||||||
|
|
||||||
this.logger.verbose('media sent');
|
this.logger.verbose('media sent');
|
||||||
return;
|
return;
|
||||||
@ -1074,7 +1074,7 @@ export class ChatwootService {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
await waInstance?.textMessage(data);
|
await waInstance?.textMessage(data, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,6 +33,7 @@ import makeWASocket, {
|
|||||||
WAMessageUpdate,
|
WAMessageUpdate,
|
||||||
WASocket,
|
WASocket,
|
||||||
} from '@whiskeysockets/baileys';
|
} from '@whiskeysockets/baileys';
|
||||||
|
import MAIN_LOGGER from '@whiskeysockets/baileys/lib/Utils/logger';
|
||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { exec, execSync } from 'child_process';
|
import { exec, execSync } from 'child_process';
|
||||||
import { arrayUnique, isBase64, isURL } from 'class-validator';
|
import { arrayUnique, isBase64, isURL } from 'class-validator';
|
||||||
@ -131,6 +132,8 @@ import { ChatwootService } from './chatwoot.service';
|
|||||||
//import { SocksProxyAgent } from './socks-proxy-agent';
|
//import { SocksProxyAgent } from './socks-proxy-agent';
|
||||||
import { TypebotService } from './typebot.service';
|
import { TypebotService } from './typebot.service';
|
||||||
|
|
||||||
|
const logger = MAIN_LOGGER.child({});
|
||||||
|
|
||||||
export class WAStartupService {
|
export class WAStartupService {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly configService: ConfigService,
|
private readonly configService: ConfigService,
|
||||||
@ -1542,7 +1545,7 @@ export class WAStartupService {
|
|||||||
'buffer',
|
'buffer',
|
||||||
{},
|
{},
|
||||||
{
|
{
|
||||||
logger: P({ level: 'error' }),
|
logger: logger,
|
||||||
reuploadRequest: this.client.updateMediaMessage,
|
reuploadRequest: this.client.updateMediaMessage,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -2061,7 +2064,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('Sending message with typing');
|
||||||
|
|
||||||
this.logger.verbose(`Check if number "${number}" is WhatsApp`);
|
this.logger.verbose(`Check if number "${number}" is WhatsApp`);
|
||||||
@ -2219,7 +2227,7 @@ export class WAStartupService {
|
|||||||
this.logger.verbose('Sending data to webhook in event SEND_MESSAGE');
|
this.logger.verbose('Sending data to webhook in event SEND_MESSAGE');
|
||||||
await this.sendDataWebhook(Events.SEND_MESSAGE, messageRaw);
|
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);
|
this.chatwootService.eventWhatsapp(Events.SEND_MESSAGE, { instanceName: this.instance.name }, messageRaw);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2244,7 +2252,7 @@ export class WAStartupService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Send Message Controller
|
// Send Message Controller
|
||||||
public async textMessage(data: SendTextDto) {
|
public async textMessage(data: SendTextDto, isChatwoot = false) {
|
||||||
this.logger.verbose('Sending text message');
|
this.logger.verbose('Sending text message');
|
||||||
return await this.sendMessageWithTyping(
|
return await this.sendMessageWithTyping(
|
||||||
data.number,
|
data.number,
|
||||||
@ -2252,6 +2260,7 @@ export class WAStartupService {
|
|||||||
conversation: data.textMessage.text,
|
conversation: data.textMessage.text,
|
||||||
},
|
},
|
||||||
data?.options,
|
data?.options,
|
||||||
|
isChatwoot,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2528,11 +2537,11 @@ export class WAStartupService {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async mediaMessage(data: SendMediaDto) {
|
public async mediaMessage(data: SendMediaDto, isChatwoot = false) {
|
||||||
this.logger.verbose('Sending media message');
|
this.logger.verbose('Sending media message');
|
||||||
const generate = await this.prepareMediaMessage(data.mediaMessage);
|
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) {
|
public async processAudio(audio: string, number: string) {
|
||||||
@ -2589,7 +2598,7 @@ export class WAStartupService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async audioWhatsapp(data: SendAudioDto) {
|
public async audioWhatsapp(data: SendAudioDto, isChatwoot = false) {
|
||||||
this.logger.verbose('Sending audio whatsapp');
|
this.logger.verbose('Sending audio whatsapp');
|
||||||
|
|
||||||
if (!data.options?.encoding && data.options?.encoding !== false) {
|
if (!data.options?.encoding && data.options?.encoding !== false) {
|
||||||
@ -2608,6 +2617,7 @@ export class WAStartupService {
|
|||||||
mimetype: 'audio/mp4',
|
mimetype: 'audio/mp4',
|
||||||
},
|
},
|
||||||
{ presence: 'recording', delay: data?.options?.delay },
|
{ presence: 'recording', delay: data?.options?.delay },
|
||||||
|
isChatwoot,
|
||||||
);
|
);
|
||||||
|
|
||||||
fs.unlinkSync(convert);
|
fs.unlinkSync(convert);
|
||||||
@ -2629,6 +2639,7 @@ export class WAStartupService {
|
|||||||
mimetype: 'audio/ogg; codecs=opus',
|
mimetype: 'audio/ogg; codecs=opus',
|
||||||
},
|
},
|
||||||
{ presence: 'recording', delay: data?.options?.delay },
|
{ presence: 'recording', delay: data?.options?.delay },
|
||||||
|
isChatwoot,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
110
views/manager-wip.hbs
Normal file
110
views/manager-wip.hbs
Normal file
@ -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/bootstrap@4.6.2/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">×</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/jquery@3.5.1/dist/jquery.slim.min.js"
|
||||||
|
integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj"
|
||||||
|
crossorigin="anonymous"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.1/dist/umd/popper.min.js"
|
||||||
|
integrity="sha384-9/reFTGAW83EW2RDu2S0VKaIzap3H66lZH81PoYlFhbGU+6BZp6G7niu735Sk7lN"
|
||||||
|
crossorigin="anonymous"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@4.6.2/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>
|
@ -11,7 +11,7 @@
|
|||||||
|
|
||||||
<body>
|
<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>
|
</body>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user