From 692016d7252c0f1c732d305b892baa5b2e0f384d Mon Sep 17 00:00:00 2001 From: AlanPerdomo Date: Thu, 2 Mar 2023 17:46:45 -0300 Subject: [PATCH 1/2] new(all): #171 HEAR AS qrcode. --- package.json | 4 +++- packages/basic.gblib/services/DialogKeywords.ts | 8 ++++++++ packages/basic.gblib/services/KeywordsExpressions.ts | 7 +++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 43c15e8b..044a0378 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "João Ferreira ", "Jorge Ramos ", "PH ", - "Dário Vieira " + "Dário Vieira ", + "Alan Perdomo " ], "engines": { "node": "=19.7.0" @@ -140,6 +141,7 @@ "puppeteer-extra": "3.3.4", "puppeteer-extra-plugin-stealth": "2.11.1", "qrcode": "1.5.1", + "qr-scanner": "^1.4.2", "qrcode-terminal": "0.12.0", "readline": "1.3.0", "reflect-metadata": "0.1.13", diff --git a/packages/basic.gblib/services/DialogKeywords.ts b/packages/basic.gblib/services/DialogKeywords.ts index d1e677b4..1221d230 100644 --- a/packages/basic.gblib/services/DialogKeywords.ts +++ b/packages/basic.gblib/services/DialogKeywords.ts @@ -59,6 +59,7 @@ import qrcode from 'qrcode'; import { json } from 'body-parser'; import { WebAutomationServices } from './WebAutomationServices.js'; import urljoin from 'url-join'; +import QrScanner from 'qr-scanner'; /** * Default check interval for user replay @@ -1002,6 +1003,13 @@ export class DialogKeywords { } result = phoneNumber; + } else if (kind === 'qr-scanner'){ + //https://github.com/GeneralBots/BotServer/issues/171 + GBLog.info(`BASIC (${min.botId}): Upload done for ${answer.filename}.`); + const handle = WebAutomationServices.cyrb53(this.min.botId + answer.filename); + GBServer.globals.files[handle] = answer; + QrScanner.scanImage(GBServer.globals.files[handle]).then(result => console.log(result)).catch(error => console.log(error || 'no QR code found.')); + } else if (kind === 'zipcode') { const extractEntity = (text: string) => { text = text.replace(/\-/gi, ''); diff --git a/packages/basic.gblib/services/KeywordsExpressions.ts b/packages/basic.gblib/services/KeywordsExpressions.ts index 1d4098fd..c58ca3a5 100644 --- a/packages/basic.gblib/services/KeywordsExpressions.ts +++ b/packages/basic.gblib/services/KeywordsExpressions.ts @@ -247,6 +247,13 @@ export class KeywordsExpressions { } ]; + keywords[i++] = [ + /^\s*hear (\w+) as\s*qrcode/gim, + ($0, $1) => { + return `${$1} = await dk.getHear({pid: pid, kind:"qrcode")}`; + } + ]; + keywords[i++] = [ /^\s*hear (\w+) as\s*language/gim, ($0, $1) => { From d902e14f78913626d3f8ac758a3b98776d1589b5 Mon Sep 17 00:00:00 2001 From: Rodrigo Rodriguez Date: Fri, 3 Mar 2023 19:10:31 -0300 Subject: [PATCH 2/2] fix(basic.gblib): WA page bug removal. --- .../basic.gblib/services/DialogKeywords.ts | 26 +++++++++---------- .../services/KeywordsExpressions.ts | 6 ++--- .../basic.gblib/services/SystemKeywords.ts | 11 ++++---- .../services/WebAutomationServices.ts | 2 +- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/packages/basic.gblib/services/DialogKeywords.ts b/packages/basic.gblib/services/DialogKeywords.ts index d1e677b4..83e1514c 100644 --- a/packages/basic.gblib/services/DialogKeywords.ts +++ b/packages/basic.gblib/services/DialogKeywords.ts @@ -228,7 +228,7 @@ export class DialogKeywords { * * @example x = TODAY */ - public async getToday({}) { + public async getToday({ }) { let d = new Date(), month = '' + (d.getMonth() + 1), day = '' + d.getDate(), @@ -264,28 +264,28 @@ export class DialogKeywords { * * @example EXIT */ - public async exit({}) {} + public async exit({ }) { } /** * Get active tasks. * * @example list = ACTIVE TASKS */ - public async getActiveTasks({ pid }) {} + public async getActiveTasks({ pid }) { } /** * Creates a new deal. * * @example CREATE DEAL dealname,contato,empresa,amount */ - public async createDeal({ pid, dealName, contact, company, amount }) {} + public async createDeal({ pid, dealName, contact, company, amount }) { } /** * Finds contacts in XRM. * * @example list = FIND CONTACT "Sandra" */ - public async fndContact({ pid, name }) {} + public async fndContact({ pid, name }) { } public getContentLocaleWithCulture(contentLocale) { switch (contentLocale) { @@ -488,7 +488,7 @@ export class DialogKeywords { * @example SAVE "contacts.xlsx", name, email, NOW * */ - public async getNow({}) { + public async getNow({ }) { const contentLocale = this.min.core.getParam( this.min.instance, 'Default Content Language', @@ -724,7 +724,7 @@ export class DialogKeywords { * @example MENU * */ - public async showMenu({}) { + public async showMenu({ }) { // https://github.com/GeneralBots/BotServer/issues/237 // return await beginDialog('/menu'); } @@ -828,7 +828,7 @@ export class DialogKeywords { const answer = min.cbMap[userId].promise; if (kind === 'sheet') { - + // Retrieves the .xlsx file associated with the HEAR var AS file.xlsx. let { baseUrl, client } = await GBDeployer.internalGetDriveClient(this.min); @@ -864,12 +864,11 @@ export class DialogKeywords { let list = []; for (; index < results.text.length; index++) { if (results.text[index][0] !== '') { - list.push( results.text[index][0]); + list.push(results.text[index][0]); } - else - { + else { break; - } + } } // Search the answer in one of valid list items loaded from sheeet. @@ -1121,7 +1120,7 @@ export class DialogKeywords { /** * Talks to the user by using the specified text. */ - public async getTalk({ pid, text }) { + public async getTalk({ pid, text }): Promise<{ status: number }> { GBLog.info(`BASIC: TALK '${text}'.`); const { min, user } = await DialogKeywords.getProcessInfo(pid); @@ -1130,6 +1129,7 @@ export class DialogKeywords { await min.conversationalService['sendOnConversation'](min, user, text); } + return { status: 0 }; } private static getChannel(): string { diff --git a/packages/basic.gblib/services/KeywordsExpressions.ts b/packages/basic.gblib/services/KeywordsExpressions.ts index 1d4098fd..c62aed52 100644 --- a/packages/basic.gblib/services/KeywordsExpressions.ts +++ b/packages/basic.gblib/services/KeywordsExpressions.ts @@ -139,7 +139,7 @@ export class KeywordsExpressions { /^\s*open\s*(.*)/gim, ($0, $1, $2) => { let sessionName; - let kind = ''; + let kind = null; let pos; if (pos = $1.match(/\s*AS\s*\#/)) { @@ -655,7 +655,7 @@ export class KeywordsExpressions { // page is not string. // https://github.com/GeneralBots/BotServer/issues/310 const params = this.getParams('page,' + $3, ['handle', 'frameOrSelector', 'selector']); - return `await wa.click ({pid: pid, ${params}})`; + return `await wa.getClick ({pid: pid, ${params}})`; } ]; @@ -764,7 +764,7 @@ export class KeywordsExpressions { /^\s*set\s*(.*)/gim, ($0, $1, $2) => { const params = this.getParams($1, ['file', 'address', 'value']); - return `await sys.set ({pid: pid, ${params}})`; + return `await sys.getSet ({pid: pid, handle:page, ${params}})`; } ]; keywords[i++] = [ diff --git a/packages/basic.gblib/services/SystemKeywords.ts b/packages/basic.gblib/services/SystemKeywords.ts index b7692562..3e4792ea 100644 --- a/packages/basic.gblib/services/SystemKeywords.ts +++ b/packages/basic.gblib/services/SystemKeywords.ts @@ -488,14 +488,15 @@ export class SystemKeywords { * @example SET page, "elementHTMLSelector", "text" * */ - public async set({ pid, file, address, value }): Promise { + public async getSet({ pid, page, file, address, value }): Promise { const { min, user } = await DialogKeywords.getProcessInfo(pid); // Handles calls for HTML stuff - if (file._javascriptEnabled) { - const page = file; - GBLog.info(`BASIC: Web automation setting ${page}' to '${value}' (SET). `); + if (file.indexOf("#") != -1 || + file.indexOf("[") != -1 ) { + value = address; + GBLog.info(`BASIC: Web automation setting ${file}' to '${value}' (SET). `); await this.wa.setElementText({ page, selector: address, text: value }); return; @@ -1694,7 +1695,7 @@ export class SystemKeywords { const address = `${cell}:${cell}`; if (value !== found[columnName]) { - await this.set({ pid, file, address, value }); + await this.getSet({ pid, file, page:null, address, value }); merges++; } } diff --git a/packages/basic.gblib/services/WebAutomationServices.ts b/packages/basic.gblib/services/WebAutomationServices.ts index c9aa7b66..18da7ea0 100644 --- a/packages/basic.gblib/services/WebAutomationServices.ts +++ b/packages/basic.gblib/services/WebAutomationServices.ts @@ -277,7 +277,7 @@ export class WebAutomationServices { * * @example CLICK page,"#idElement" */ - public async click({ pid, handle, frameOrSelector, selector }) { + public async getClick({ pid, handle, frameOrSelector, selector }) { const page = this.getPageByHandle(handle); GBLog.info(`BASIC: Web Automation CLICK element: ${frameOrSelector}.`); if (selector) {