new(WhatsApp.gblib): Warning of QRCode.

This commit is contained in:
Rodrigo Rodriguez 2024-04-13 12:24:08 -03:00
parent 9b59146034
commit cd0fffb6a0
2 changed files with 27 additions and 15 deletions

View file

@ -2684,6 +2684,8 @@ export class SystemKeywords {
const { min } = await DialogKeywords.getProcessInfo(pid); const { min } = await DialogKeywords.getProcessInfo(pid);
GBLogEx.info(min, `dirFolder: remotePath=${remotePath}, baseUrl=${baseUrl}`); GBLogEx.info(min, `dirFolder: remotePath=${remotePath}, baseUrl=${baseUrl}`);
// In case of empty files, build an zero element array.
if (!array) { if (!array) {
array = []; array = [];
} }

View file

@ -138,9 +138,9 @@ export class WhatsappDirectLine extends GBService {
case 'GeneralBots': case 'GeneralBots':
const minBoot = GBServer.globals.minBoot; const minBoot = GBServer.globals.minBoot;
// Initialize the browser using a local profile for each bot. // Initialize the browser using a local profile for each bot.
const path = DialogKeywords.getGBAIPath(this.min.botId); const gbaiPath = DialogKeywords.getGBAIPath(this.min.botId);
const webVersion = '2.2411.2'; const webVersion = '2.2411.2';
const localName = Path.join('work', path, 'profile'); const localName = Path.join('work', gbaiPath, 'profile');
const createClient = () => { const createClient = () => {
const client = (this.customClient = new Client({ const client = (this.customClient = new Client({
puppeteer: GBSSR.preparePuppeteer(localName) puppeteer: GBSSR.preparePuppeteer(localName)
@ -158,23 +158,33 @@ export class WhatsappDirectLine extends GBService {
(async qr => { (async qr => {
const adminNumber = this.min.core.getParam(this.min.instance, 'Bot Admin Number', null); const adminNumber = this.min.core.getParam(this.min.instance, 'Bot Admin Number', null);
const adminEmail = this.min.core.getParam(this.min.instance, 'Bot Admin E-mail', null); const adminEmail = this.min.core.getParam(this.min.instance, 'Bot Admin E-mail', null);
// Sends QR Code to boot bot admin. // Sends QR Code to boot bot admin.
const msg = `Please, scan QR Code with for bot ${this.botId}.`; const msg = `Please, scan QR Code with for bot ${this.botId}.`;
qrcode.generate(qr, { small: true, scale: 0.5 }); qrcode.generate(qr, { small: true, scale: 0.5 });
// TODO: While handling other bots uses boot instance of this class to send QR Codes. const s = new DialogKeywords();
// const s = new DialogKeywords(min., null, null, null); const qrBuf = await s.getQRCode(qr);
// const qrBuf = await s.getQRCode(qr); const localName = Path.join('work', gbaiPath, 'cache', `qr${GBAdminService.getRndReadableIdentifier()}.png`);
// const localName = Path.join('work', gbaiName, 'cache', `qr${GBAdminService.getRndReadableIdentifier()}.png`); Fs.writeFileSync(localName, qrBuf.data);
// fs.writeFileSync(localName, qrBuf); const url = urlJoin(
// const url = urlJoin( GBServer.globals.publicAddress,
// GBServer.globals.publicAddress, this.min.botId,
// this.min.botId, 'cache',
// 'cache', Path.basename(localName)
// Path.basename(localName) );
// );
// GBServer.globals.minBoot.whatsAppDirectLine.sendFileToDevice(adminNumber, url, Path.basename(localName), msg); if (adminNumber){
// s.sendEmail(adminEmail, `Check your WhatsApp for bot ${this.botId}`, msg); await GBServer.globals.minBoot.whatsAppDirectLine.sendFileToDevice(adminNumber, url, Path.basename(localName), msg);
}
if (adminEmail){
const pid = GBAdminService.getNumberIdentifier();
await s.sendEmail({pid, to: adminEmail, subject: `Check your WhatsApp for bot ${this.min.botId}`,
body: msg
});
}
}).bind(this) }).bind(this)
); );