fix(chatwoot): resolve webhook timeout on deletion with 5+ images

Problem:
- Chatwoot shows red error when deleting messages with 5+ images
- Cause: Chatwoot webhook timeout of 5 seconds
- Processing 5 images takes ~9 seconds
- Duplicate webhooks arrive during processing

Solution:
- Implemented async processing with setImmediate()
- Webhook responds immediately (< 100ms)
- Deletion processes in background without blocking
- Maintains idempotency with cache (1 hour TTL)
- Maintains lock mechanism (60 seconds TTL)

Benefits:
- Scales infinitely (10, 20, 100+ images)
- No timeout regardless of quantity
- No error messages in Chatwoot
- Reliable background processing

Tested:
- 5 images: 9s background processing
- Webhook response: < 100ms
- No red error in Chatwoot
- Deletion completes successfully

BREAKING CHANGE: Fixed assertSessions signature to accept force parameter
This commit is contained in:
Anderson Silva
2025-10-06 16:14:26 -03:00
parent a5a46dc72a
commit d4b0cfd2ba
3 changed files with 75 additions and 50 deletions

View File

@@ -4593,8 +4593,8 @@ export class BaileysStartupService extends ChannelStartupService {
return response;
}
public async baileysAssertSessions(jids: string[]) {
const response = await this.client.assertSessions(jids);
public async baileysAssertSessions(jids: string[], force?: boolean) {
const response = await this.client.assertSessions(jids, force);
return response;
}