Skip to content

Commit bca5ec6

Browse files
committed
fix: writing over 20s now loops until finished
1 parent e2c67d7 commit bca5ec6

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

src/whatsapp/services/whatsapp.baileys.service.ts

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import makeWASocket, {
3232
WAMediaUpload,
3333
WAMessage,
3434
WAMessageUpdate,
35+
WAPresence,
3536
WASocket,
3637
} from '@whiskeysockets/baileys';
3738
import { Label } from '@whiskeysockets/baileys/lib/Types/Label';
@@ -1622,17 +1623,37 @@ export class BaileysStartupService extends WAStartupService {
16221623
if (options?.delay) {
16231624
this.logger.verbose('Delaying message');
16241625

1625-
await this.client.presenceSubscribe(sender);
1626-
this.logger.verbose('Subscribing to presence');
1626+
if (options.delay > 20000) {
1627+
let remainingDelay = options.delay;
1628+
while (remainingDelay > 20000) {
1629+
await this.client.presenceSubscribe(sender);
16271630

1628-
await this.client.sendPresenceUpdate(options?.presence ?? 'composing', sender);
1629-
this.logger.verbose('Sending presence update: ' + options?.presence ?? 'composing');
1631+
await this.client.sendPresenceUpdate((options.presence as WAPresence) ?? 'composing', sender);
16301632

1631-
await delay(options.delay);
1632-
this.logger.verbose('Set delay: ' + options.delay);
1633+
await delay(20000);
16331634

1634-
await this.client.sendPresenceUpdate('paused', sender);
1635-
this.logger.verbose('Sending presence update: paused');
1635+
await this.client.sendPresenceUpdate('paused', sender);
1636+
1637+
remainingDelay -= 20000;
1638+
}
1639+
if (remainingDelay > 0) {
1640+
await this.client.presenceSubscribe(sender);
1641+
1642+
await this.client.sendPresenceUpdate((options.presence as WAPresence) ?? 'composing', sender);
1643+
1644+
await delay(remainingDelay);
1645+
1646+
await this.client.sendPresenceUpdate('paused', sender);
1647+
}
1648+
} else {
1649+
await this.client.presenceSubscribe(sender);
1650+
1651+
await this.client.sendPresenceUpdate((options.presence as WAPresence) ?? 'composing', sender);
1652+
1653+
await delay(options.delay);
1654+
1655+
await this.client.sendPresenceUpdate('paused', sender);
1656+
}
16361657
}
16371658

16381659
const linkPreview = options?.linkPreview != false ? undefined : false;

0 commit comments

Comments
 (0)