Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
485 changes: 0 additions & 485 deletions manager/dist/assets/index-CO3NSIFj.js

This file was deleted.

569 changes: 569 additions & 0 deletions manager/dist/assets/index-CXcMB1JE.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion manager/dist/assets/index-DsIrum0U.css

This file was deleted.

1 change: 1 addition & 0 deletions manager/dist/assets/index-pR7_E4aM.css

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions manager/dist/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<link rel="icon" type="image/png" href="https://evolution-api.com/files/evo/favicon.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Evolution Manager</title>
<script type="module" crossorigin src="/assets/index-CO3NSIFj.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-DsIrum0U.css">
<script type="module" crossorigin src="/assets/index-CXcMB1JE.js"></script>
<link rel="stylesheet" crossorigin href="/assets/index-pR7_E4aM.css">
</head>
<body>
<div id="root"></div>
Expand Down
22 changes: 18 additions & 4 deletions src/api/integrations/channel/whatsapp/whatsapp.baileys.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ export class BaileysStartupService extends ChannelStartupService {
private endSession = false;
private logBaileys = this.configService.get<Log>('LOG').BAILEYS;
private eventProcessingQueue: Promise<void> = Promise.resolve();
private groupMetadataRateLimitUntil = 0;

// Cache TTL constants (in seconds)
private readonly MESSAGE_CACHE_TTL_SECONDS = 5 * 60; // 5 minutes - avoid duplicate message processing
Expand Down Expand Up @@ -789,8 +790,8 @@ export class BaileysStartupService extends ChannelStartupService {

for (const chat of chats) {
await this.prismaRepository.chat.updateMany({
where: { instanceId: this.instanceId, remoteJid: chat.id, name: chat.name },
data: { remoteJid: chat.id },
where: { instanceId: this.instanceId, remoteJid: chat.id },
data: { remoteJid: chat.id, name: chat.name },
});
}
},
Expand Down Expand Up @@ -1063,7 +1064,7 @@ export class BaileysStartupService extends ChannelStartupService {
) {
this.chatwootService.addHistoryMessages(
instance,
messagesRaw.filter((msg) => !chatwootImport.isIgnorePhoneNumber(msg.key?.remoteJid)),
messagesRaw.filter((msg) => !chatwootImport.isIgnoredRemoteJid(msg.key?.remoteJid)),
);
}

Expand Down Expand Up @@ -4285,6 +4286,11 @@ export class BaileysStartupService extends ChannelStartupService {

// Group
private async updateGroupMetadataCache(groupJid: string) {
if (Date.now() < this.groupMetadataRateLimitUntil) {
this.logger.warn(`Skipping group metadata refresh while WhatsApp rate limit is active: ${groupJid}`);
return null;
}

try {
const meta = await this.client.groupMetadata(groupJid);

Expand All @@ -4297,7 +4303,15 @@ export class BaileysStartupService extends ChannelStartupService {

return meta;
} catch (error) {
this.logger.error(error);
const isRateLimit =
error?.data === 429 || error?.message === 'rate-overlimit' || error?.toString?.()?.includes?.('rate-overlimit');

if (isRateLimit) {
this.groupMetadataRateLimitUntil = Date.now() + 5 * 60 * 1000;
this.logger.warn(`WhatsApp group metadata rate limit reached; pausing group metadata refresh for 5 minutes.`);
} else {
this.logger.error(error);
}
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,14 @@ export class ChatwootController {

return this.chatwootService.receiveWebhook(instance, data);
}

public async importData(instance: InstanceDto) {
if (!this.configService.get<Chatwoot>('CHATWOOT').ENABLED) throw new BadRequestException('Chatwoot is disabled');

try {
return await this.chatwootService.importData(instance);
} catch (error) {
throw new BadRequestException(error?.message || 'Error importing Chatwoot data');
}
}
}
10 changes: 10 additions & 0 deletions src/api/integrations/chatbot/chatwoot/routes/chatwoot.router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ export class ChatwootRouter extends RouterBroker {

res.status(HttpStatus.OK).json(response);
})
.post(this.routerPath('import'), ...guards, async (req, res) => {
const response = await this.dataValidate<InstanceDto>({
request: req,
schema: instanceSchema,
ClassRef: InstanceDto,
execute: (instance) => chatwootController.importData(instance),
});

res.status(HttpStatus.OK).json(response);
})
.post(this.routerPath('webhook'), async (req, res) => {
const response = await this.dataValidate<InstanceDto>({
request: req,
Expand Down
Loading