Skip to content

Commit

Permalink
Inclusão das variáveis para personalização das cores do QrCode no arq…
Browse files Browse the repository at this point in the history
…uivo de configuração. Caso as variáveis não sejam declaradas, serão utilizadas as cores light(#ffffff) e dark(#198754)
  • Loading branch information
vilsonei committed Jun 20, 2024
1 parent 7168182 commit 3151a92
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ CONFIG_SESSION_PHONE_NAME=Edge
# Set qrcode display limit
QRCODE_LIMIT=5
QRCODE_EXPIRATION_TIME=20 # seconds
QRCODE_LIGHT_COLOR=#ffffff
QRCODE_DARK_COLOR=#198754

# Maximun time to connect to whatsapp
CONNECTION_TIMEOUT=120 # seconds
Expand Down
4 changes: 4 additions & 0 deletions src/config/env.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ export type ProviderSession = {
export type QrCode = {
LIMIT: number;
EXPIRATION_TIME: number;
LIGHT_COLOR: string;
DARK_COLOR: string;
};

export type Jwt = { EXPIRIN_IN: number; SECRET: string };
Expand Down Expand Up @@ -203,6 +205,8 @@ export class ConfigService {
QRCODE: {
LIMIT: Number.parseInt(process.env?.QRCODE_LIMIT || '10'),
EXPIRATION_TIME: Number.parseInt(process.env?.QRCODE_EXPIRATION_TIME || '60'),
LIGHT_COLOR: process.env?.QRCODE_LIGHT_COLOR ? process.env?.QRCODE_LIGHT_COLOR : '#ffffff',
DARK_COLOR: process.env?.QRCODE_DARK_COLOR ? process.env?.QRCODE_DARK_COLOR : '#198754'
},
CONNECTION_TIMEOUT: Number.parseInt(process.env?.CONNECTION_TIMEOUT || '300'),
AUTHENTICATION: {
Expand Down
4 changes: 3 additions & 1 deletion src/whatsapp/services/whatsapp.service.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { QrCode } from './../../config/env.config';
/**
* ┌──────────────────────────────────────────────────────────────────────────────┐
* │ @author jrCleber │
Expand Down Expand Up @@ -374,11 +375,12 @@ export class WAStartupService {

this.instanceQr.count++;

const qrCodeOptions: QrCode = this.configService.get<QrCode>('QRCODE');
const optsQrcode: QRCodeToDataURLOptions = {
margin: 3,
scale: 4,
errorCorrectionLevel: 'H',
color: { light: '#ffffff', dark: '#198754' },
color: { light: qrCodeOptions.LIGHT_COLOR, dark: qrCodeOptions.DARK_COLOR },
};

qrcode.toDataURL(qr, optsQrcode, (error, base64) => {
Expand Down

0 comments on commit 3151a92

Please sign in to comment.