[core] WEBJS - add webjs.tagsEventsOn config
This commit is contained in:
1 parent
94c1c16de8
commit
8f94cf06de
4 files changed
+62
-4
No files matched your search
@@ -30,7 +30,10 @@ export class WebjsClientCore extends Client {
|
||||
public events = new EventEmitter();
|
||||
private wpage: WPage = null;
|
||||
|
||||
constructor(options) {
|
||||
constructor(
|
||||
options,
|
||||
protected tags: boolean,
|
||||
) {
|
||||
super(options);
|
||||
// Wait until it's READY and inject more utils
|
||||
this.on(Events.READY, async () => {
|
||||
@@ -86,6 +89,32 @@ export class WebjsClientCore extends Client {
|
||||
return;
|
||||
},
|
||||
);
|
||||
if (this.tags) {
|
||||
await this.attachTagsEvents();
|
||||
}
|
||||
}
|
||||
|
||||
async attachTagsEvents() {
|
||||
await this.pupPage.evaluate(() => {
|
||||
// @ts-ignore
|
||||
if (window.decodeStanzaBack) {
|
||||
return;
|
||||
}
|
||||
|
||||
const tags = ['receipt', 'presence', 'chatstate'];
|
||||
// @ts-ignore
|
||||
window.decodeStanzaBack = window.Store.SocketWap.decodeStanza;
|
||||
// @ts-ignore
|
||||
window.Store.SocketWap.decodeStanza = async (...args) => {
|
||||
// @ts-ignore
|
||||
const result = await window.decodeStanzaBack(...args);
|
||||
if (tags.includes(result?.tag)) {
|
||||
// @ts-ignore
|
||||
setTimeout(() => window.onTag(result), 0);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
async destroy() {
|
||||
|
||||
@@ -236,7 +236,14 @@ export class WhatsappSessionWebJSCore extends WhatsappSession {
|
||||
rmMaxRetries: undefined,
|
||||
});
|
||||
this.addProxyConfig(clientOptions);
|
||||
return new WebjsClientCore(clientOptions);
|
||||
return new WebjsClientCore(clientOptions, this.getWebjsTagsFlag());
|
||||
}
|
||||
|
||||
protected getWebjsTagsFlag() {
|
||||
// Emit 'tag:*' events only when explicitly enabled in session config.
|
||||
// This flag is required for presence.update and message.ack events.
|
||||
// Disabled by default for performance and stability reasons.
|
||||
return !!this.sessionConfig?.webjs?.tagsEventsOn;
|
||||
}
|
||||
|
||||
private restartClient() {
|
||||
|
||||
@@ -89,6 +89,19 @@ export class NowebConfig {
|
||||
markOnline: boolean = true;
|
||||
}
|
||||
|
||||
export class WebjsConfig {
|
||||
@ApiProperty({
|
||||
description:
|
||||
"Enable emission of special 'tag:*' engine events required for presence.update and message.ack.\n" +
|
||||
'WARNING: Enabling this may have performance and stability impact. Disabled by default.',
|
||||
required: false,
|
||||
default: false,
|
||||
})
|
||||
@IsBoolean()
|
||||
@IsOptional()
|
||||
tagsEventsOn?: boolean = false;
|
||||
}
|
||||
|
||||
export class IgnoreConfig {
|
||||
@ApiProperty({
|
||||
description: 'Ignore a status@broadcast (stories) events',
|
||||
@@ -173,6 +186,15 @@ export class SessionConfig {
|
||||
@Type(() => NowebConfig)
|
||||
@IsOptional()
|
||||
noweb?: NowebConfig;
|
||||
|
||||
@ApiProperty({
|
||||
description: 'WebJS-specific settings.',
|
||||
required: false,
|
||||
})
|
||||
@ValidateNested()
|
||||
@Type(() => WebjsConfig)
|
||||
@IsOptional()
|
||||
webjs?: WebjsConfig;
|
||||
}
|
||||
|
||||
export class SessionDTO {
|
||||
|
||||
@@ -12589,7 +12589,7 @@ __metadata:
|
||||
|
||||
"whatsapp-web.js@github:devlikeapro/whatsapp-web.js#fork-main-2025-06-09":
|
||||
version: 1.30.1-alpha.2
|
||||
resolution: "whatsapp-web.js@https://github.com/devlikeapro/whatsapp-web.js.git#commit=55581239a70ddb76e6fe32381d9f991557cf9df3"
|
||||
resolution: "whatsapp-web.js@https://github.com/devlikeapro/whatsapp-web.js.git#commit=30a999ffb2e37644e744f9af4920ef3c065d23c7"
|
||||
dependencies:
|
||||
"@pedroslopez/moduleraid": ^5.0.2
|
||||
archiver: ^5.3.1
|
||||
@@ -12607,7 +12607,7 @@ __metadata:
|
||||
optional: true
|
||||
unzipper:
|
||||
optional: true
|
||||
checksum: 2af8df50bf3f6225222417d3d21e63750cc520cf19636c5ffdd3e828b26c132b9f5acd36fc43a4d041a245ce1f75b3b080550f844cbf6142a322ce4ca73734c4
|
||||
checksum: af23680178cf2f9a09f28142b9dc1ba674d6a9682a0892f822990974bc4af2ce987edaed8f4dcb75f508b294cdefbeb03ba2cfa1071f1b6208b6ba2f5f82f862
|
||||
languageName: node
|
||||
linkType: hard
|
||||
|
||||
|
||||
Reference in new issue
Block a user