[core] Add device and browser config - WEBJS, GOWS, NOWEB

fix #1109
This commit is contained in:
devlikepro committed 2025-12-30 17:38:13 +07:00
1 parent c0c3381a36
commit a16f3b67fe
4 files changed
+74 -2

No files matched your search

+33 -2
View File
@@ -1,4 +1,4 @@
import type { WABrowserDescription } from '@adiwajshing/baileys';
import { Browsers, WABrowserDescription } from '@adiwajshing/baileys';
import makeWASocket, {
Chat,
Contact,
@@ -205,6 +205,10 @@ import {
import { extractWALocation } from '@waha/core/engines/waproto/locaiton';
import { extractVCards } from '@waha/core/engines/waproto/vcards';
import { Activity } from '@waha/core/abc/activity';
import {
WAHA_CLIENT_BROWSER_NAME,
WAHA_CLIENT_DEVICE_NAME,
} from '@waha/core/env';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const promiseRetry = require('promise-retry');
@@ -314,8 +318,35 @@ export class WhatsappSessionNoWebCore extends WhatsappSession {
}
getSocketConfig(agents: Agents | undefined, state): Partial<SocketConfig> {
// Detect browser
let browser = ['Ubuntu', 'Chrome', '22.04.4'] as WABrowserDescription;
let deviceName =
this.sessionConfig.client?.deviceName ?? WAHA_CLIENT_DEVICE_NAME;
let browserName =
this.sessionConfig.client?.browserName ?? WAHA_CLIENT_BROWSER_NAME;
if (browserName && !deviceName) {
browser = Browsers.appropriate(browserName);
} else if (browserName && deviceName) {
switch (deviceName) {
case 'Mac OS':
case 'MacOS':
case 'macos':
browser = Browsers.macOS(browserName);
break;
case 'ubuntu':
case 'Ubuntu':
browser = Browsers.ubuntu(browserName);
break;
case 'windows':
case 'Windows':
browser = Browsers.windows(browserName);
break;
default:
browser = [deviceName, browserName, '22.04.4'];
}
}
const fullSyncEnabled = this.sessionConfig?.noweb?.store?.fullSync || false;
const browser = ['Ubuntu', 'Chrome', '20.0.04'] as WABrowserDescription;
let markOnlineOnConnect = this.sessionConfig?.noweb?.markOnline;
if (markOnlineOnConnect == undefined) {
markOnlineOnConnect = true;
@@ -181,6 +181,10 @@ import {
import { Activity } from '@waha/core/abc/activity';
import { CallData } from '@waha/structures/calls.dto';
import { Jid } from '@waha/core/engines/const';
import {
WAHA_CLIENT_BROWSER_NAME,
WAHA_CLIENT_DEVICE_NAME,
} from '@waha/core/env';
export interface WebJSConfig {
webVersion?: string;
@@ -242,6 +246,10 @@ export class WhatsappSessionWebJSCore extends WhatsappSession {
// add at the start
args.unshift(`--a-waha-timestamp=${new Date()}`);
args.unshift(`--a-waha-session=${this.name}`);
const deviceName =
this.sessionConfig.client?.deviceName ?? WAHA_CLIENT_DEVICE_NAME;
const browserName =
this.sessionConfig.client?.browserName ?? WAHA_CLIENT_BROWSER_NAME;
return {
puppeteer: {
protocolTimeout: 300_000,
@@ -252,6 +260,8 @@ export class WhatsappSessionWebJSCore extends WhatsappSession {
},
userAgent:
'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36',
deviceName: deviceName,
browserName: browserName,
webVersion: webVersion,
webVersionCache: {
type: cacheType,
+8
View File
@@ -22,3 +22,11 @@ if (KNEX_SQLITE_CLIENT != 'sqlite3' && KNEX_SQLITE_CLIENT != 'better-sqlite3') {
KNEX_SQLITE_CLIENT = 'sqlite3';
}
export { KNEX_SQLITE_CLIENT };
//
// Client config
//
export const WAHA_CLIENT_DEVICE_NAME =
process.env.WAHA_CLIENT_DEVICE_NAME || null;
export const WAHA_CLIENT_BROWSER_NAME =
process.env.WAHA_CLIENT_BROWSER_NAME || null;
+23
View File
@@ -155,6 +155,16 @@ export class IgnoreConfig {
broadcast?: boolean;
}
export class ClientSessionConfig {
@IsString()
@IsOptional()
deviceName?: string;
@IsString()
@IsOptional()
browserName?: string;
}
export class SessionConfig {
@ValidateNested({ each: true })
@Type(() => WebhookConfig)
@@ -204,6 +214,19 @@ export class SessionConfig {
@IsOptional()
ignore?: IgnoreConfig;
@ApiProperty({
description:
"How connected session renders in device - in format 'Browser (Device)' - Firefox (MacOS)",
example: {
browserName: 'Firefox',
deviceName: 'MacOS',
},
})
@ValidateNested()
@Type(() => ClientSessionConfig)
@IsOptional()
client?: ClientSessionConfig;
@ApiProperty({
example: {
store: {