Compare commits

..
3 Commits
Author SHA1 Message Date
devlikepro 68ac209aae [core] 2024.5.13
Release / amd64 - chrome - chrome (push) Waiting to run
Release / amd64 - chromium - latest (push) Waiting to run
Release / linux/arm64 - chromium - arm (push) Waiting to run
Release / amd64 - none - noweb (push) Waiting to run
Release / linux/arm64 - none - noweb-arm (push) Waiting to run
2024-05-30 13:21:34 +07:00
devlikepro 90b961f900 [core] Disable QR in console
Fix #351
2024-05-30 13:21:33 +07:00
devlikepro 9945fe0fd8 [core] Remove unused vars 2024-05-30 13:21:33 +07:00
9 changed files with 52 additions and 35 deletions

No files matched your search

-21
View File
@@ -131,27 +131,6 @@ export class WhatsappConfigService {
return this.configService.get('WHATSAPP_API_KEY', '');
}
getDashboardEnabled(): boolean {
const value = this.configService.get('WAHA_DASHBOARD_ENABLED', 'true');
return parseBool(value);
}
getDashboardUsernamePassword(): [string, string] | null {
if (!this.getDashboardEnabled()) {
return null;
}
const user = this.configService.get('WAHA_DASHBOARD_USERNAME', 'waha');
const password = this.configService.get('WAHA_DASHBOARD_PASSWORD', 'waha');
if (!user || !password) {
console.log(
'Please set up both WAHA_DASHBOARD_USERNAME and WAHA_DASHBOARD_PASSWORD ' +
'to enable swagger authentication.',
);
return null;
}
return [user, password];
}
getHealthMediaFilesThreshold(): number {
return this.configService.get<number>(
'WHATSAPP_HEALTH_MEDIA_FILES_THRESHOLD_MB',
+23
View File
@@ -51,6 +51,9 @@ import { QR } from '../QR';
import { DataStore } from './DataStore';
import { MediaManager } from './media.abc';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const qrcode = require('qrcode-terminal');
const CHROME_PATH = '/usr/bin/google-chrome-stable';
const CHROMIUM_PATH = '/usr/bin/chromium';
@@ -76,6 +79,7 @@ export enum WAHAInternalEvent {
export interface SessionParams {
name: string;
printQR: boolean;
mediaManager: MediaManager;
log: ConsoleLogger;
sessionStore: DataStore;
@@ -97,9 +101,11 @@ export abstract class WhatsappSession {
protected engineConfig?: any;
private _status: WAHASessionStatus;
private shouldPrintQR: boolean;
public constructor({
name,
printQR,
log,
sessionStore,
proxyConfig,
@@ -115,6 +121,7 @@ export abstract class WhatsappSession {
this.mediaManager = mediaManager;
this.sessionConfig = sessionConfig;
this.engineConfig = engineConfig;
this.shouldPrintQR = printQR;
}
protected set status(value: WAHASessionStatus) {
@@ -472,4 +479,20 @@ export abstract class WhatsappSession {
_serialized: messageId,
};
}
protected printQR(qr: QR) {
if (!this.shouldPrintQR) {
return;
}
if (!qr.raw) {
this.log.error(
'QR.raw is not available, can not print it in the console',
);
return;
}
this.log.log(
"You can disable QR in console by setting 'WAHA_PRINT_QR=false' in your environment variables.",
);
qrcode.generate(qr.raw, { small: true });
}
}
+2
View File
@@ -23,6 +23,7 @@ import { WhatsappConfigService } from '../config.service';
import { SessionManager } from './abc/manager.abc';
import { WAHAHealthCheckService } from './abc/WAHAHealthCheckService';
import { DashboardConfigServiceCore } from './config/DashboardConfigServiceCore';
import { EngineConfigService } from './config/EngineConfigService';
import { SwaggerConfigServiceCore } from './config/SwaggerConfigServiceCore';
import { WAHAHealthCheckServiceCore } from './health/WAHAHealthCheckServiceCore';
import { SessionManagerCore } from './manager.core';
@@ -84,6 +85,7 @@ const PROVIDERS = [
DashboardConfigServiceCore,
SwaggerConfigServiceCore,
WhatsappConfigService,
EngineConfigService,
ConsoleLogger,
];
+14
View File
@@ -0,0 +1,14 @@
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { parseBool } from '../../helpers';
@Injectable()
export class EngineConfigService {
constructor(protected configService: ConfigService) {}
get shouldPrintQR(): boolean {
const value = this.configService.get('WAHA_PRINT_QR', true);
return parseBool(value);
}
}
+4 -4
View File
@@ -140,7 +140,7 @@ export class WhatsappSessionNoWebCore extends WhatsappSession {
/** caching makes the store faster to send/recv messages */
keys: makeCacheableSignalKeyStore(state.keys, logger),
},
printQRInTerminal: true,
printQRInTerminal: false,
browser: Browsers.ubuntu('Chrome'),
logger: logger,
mobile: false,
@@ -258,10 +258,10 @@ export class WhatsappSessionNoWebCore extends WhatsappSession {
// Save QR
if (qr) {
const url = await QRCode.toDataURL(qr);
this.qr.save(url, qr);
this.printQR(this.qr);
this.status = WAHASessionStatus.SCAN_QR_CODE;
QRCode.toDataURL(qr).then((url) => {
this.qr.save(url, qr);
});
}
});
}
+1 -3
View File
@@ -67,11 +67,9 @@ export class WhatsappSessionVenomCore extends WhatsappSession {
protected getCatchQR() {
return (base64Qrimg, asciiQR, attempts, urlCode) => {
this.qr.save(base64Qrimg, urlCode);
this.printQR(this.qr);
this.status = WAHASessionStatus.SCAN_QR_CODE;
this.log.debug('Number of attempts to read the qrcode: ', attempts);
this.log.log('Terminal qrcode:');
// Log QR image in console without this.log to make it pretty
console.log(asciiQR);
};
}
+4 -6
View File
@@ -197,14 +197,12 @@ export class WhatsappSessionWebJSCore extends WhatsappSession {
}
protected listenConnectionEvents() {
this.whatsapp.on(Events.QR_RECEIVED, (qr) => {
this.whatsapp.on(Events.QR_RECEIVED, async (qr) => {
this.log.debug('QR received');
// Convert to image and save
QRCode.toDataURL(qr).then((url) => {
this.qr.save(url, qr);
});
// Print in terminal
qrcode.generate(qr, { small: true });
const url = await QRCode.toDataURL(qr);
this.qr.save(url, qr);
this.printQR(this.qr);
this.status = WAHASessionStatus.SCAN_QR_CODE;
});
+3
View File
@@ -20,6 +20,7 @@ import {
import { WebhookConfig } from '../structures/webhooks.config.dto';
import { SessionManager } from './abc/manager.abc';
import { SessionParams, WhatsappSession } from './abc/session.abc';
import { EngineConfigService } from './config/EngineConfigService';
import { WhatsappSessionNoWebCore } from './engines/noweb/session.noweb.core';
import { WhatsappSessionVenomCore } from './engines/venom/session.venom.core';
import { WhatsappSessionWebJSCore } from './engines/webjs/session.webjs.core';
@@ -55,6 +56,7 @@ export class SessionManagerCore extends SessionManager {
constructor(
private config: WhatsappConfigService,
private log: ConsoleLogger,
private engineConfigService: EngineConfigService,
) {
super();
@@ -126,6 +128,7 @@ export class SessionManagerCore extends SessionManager {
name,
mediaManager,
log,
printQR: this.engineConfigService.shouldPrintQR,
sessionStore: this.store,
proxyConfig: proxyConfig,
sessionConfig: request.config,
+1 -1
View File
@@ -33,7 +33,7 @@ export function getEngineName(): string {
}
export const VERSION: WAHAEnvironment = {
version: '2024.5.12',
version: '2024.5.13',
engine: getEngineName(),
tier: getWAHAVersion(),
browser: getBrowserExecutablePath(),