new(basic.gblib): Web Automation CAPTCHA processing.

This commit is contained in:
Rodrigo Rodriguez 2022-06-21 17:46:46 -03:00
parent 100cf31250
commit 696e867364
4 changed files with 316 additions and 318 deletions

View file

@ -244,7 +244,7 @@ export class DialogKeywords {
public async type(step, page, idOrName, text) {
const e = await this.getBySelector(page, idOrName);
await e.type(text);
}
}
/**
* Returns the today data filled in dd/mm/yyyy or mm/dd/yyyy.
@ -261,7 +261,7 @@ export class DialogKeywords {
}
return await tesseract.recognize(localFile, config);
}
}
/**
* Returns the today data filled in dd/mm/yyyy or mm/dd/yyyy.
@ -293,7 +293,7 @@ export class DialogKeywords {
default:
return [year, month, day].join('/');
}
}
}
/**
* Quits the dialog, currently required to get out of VM context.
@ -305,7 +305,7 @@ export class DialogKeywords {
await this.browser.close();
}
await step.endDialog();
}
}
/**
* Get active tasks.
@ -315,7 +315,7 @@ export class DialogKeywords {
public async getActiveTasks() {
let s = new HubSpotServices(null, null, process.env.HUBSPOT_KEY);
return await s.getActiveTasks();
}
}
/**
* Creates a new deal.
@ -326,7 +326,7 @@ export class DialogKeywords {
let s = new HubSpotServices(null, null, process.env.HUBSPOT_KEY);
let deal = await s.createDeal(dealName, contact, company, amount);
return deal;
}
}
/**
* Finds contacts in XRM.
@ -336,7 +336,7 @@ export class DialogKeywords {
public async fndContact(name) {
let s = new HubSpotServices(null, null, process.env.HUBSPOT_KEY);
return await s.searchContact(name);
}
}
public getContentLocaleWithCulture(contentLocale) {
@ -351,7 +351,7 @@ export class DialogKeywords {
return 'en-us';
}
}
}
/**
* Returns specified date week day in format 'Mon'.
@ -380,7 +380,7 @@ export class DialogKeywords {
return week.substr(0, 3);
}
return 'NULL';
}
}
/**
* Returns an object ready to get information about difference in several ways
@ -407,7 +407,7 @@ export class DialogKeywords {
case 'hour': return diff.hours();
case 'minute': return diff.minutes();
}
}
}
/**
* Returns specified date week day in format 'Mon'.
@ -435,7 +435,7 @@ export class DialogKeywords {
default: ret = undefined; break;
}
return ret;
}
}
@ -458,7 +458,7 @@ export class DialogKeywords {
array = array.join(", ");
return array;
}
}
/**
* Returns the specified time in format hh:dd.
@ -489,7 +489,7 @@ export class DialogKeywords {
return addZero(dt.getHours()) + ':' + addZero(dt.getMinutes());
}
return 'NULL';
}
}
/**
* Returns current time in format hh:dd.
@ -513,7 +513,7 @@ export class DialogKeywords {
{ timeZone: process.env.DEFAULT_TIMEZONE });
return /\b([0-9]|0[0-9]|1?[0-9]|2[0-3]):[0-5]?[0-9]/.exec(nowText)[0];
}
}
/**
* Sends a file to a given mobile.
@ -524,7 +524,7 @@ export class DialogKeywords {
public async sendFileTo(step, mobile, filename, caption) {
GBLog.info(`BASIC: SEND FILE TO '${mobile}', filename '${filename}'.`);
return await this.internalSendFile(null, mobile, filename, caption);
}
}
/**
* Sends a file to the current user.
@ -536,7 +536,7 @@ export class DialogKeywords {
const mobile = await this.userMobile(step);
GBLog.info(`BASIC: SEND FILE (current: ${mobile}, filename '${filename}'.`);
return await this.internalSendFile(step, mobile, filename, caption);
}
}
/**
* Defines the current language of the bot conversation.
@ -552,7 +552,7 @@ export class DialogKeywords {
await this.min.userProfile.set(step.context, user);
this.user = user;
}
}
/**
* Defines the maximum lines to scan in spreedsheets.
@ -565,7 +565,7 @@ export class DialogKeywords {
user.basicOptions.maxLines = count;
await this.min.userProfile.set(step.context, user);
this.user = user;
}
}
/**
* Defines the FIND behaviour to consider whole words while searching.
@ -578,7 +578,7 @@ export class DialogKeywords {
user.basicOptions.wholeWord = (on.trim() === "on");
await this.min.userProfile.set(step.context, user);
this.user = user;
}
}
/**
* Defines the theme for assets generation.
@ -591,7 +591,7 @@ export class DialogKeywords {
user.basicOptions.theme = theme.trim();
await this.min.userProfile.set(step.context, user);
this.user = user;
}
}
/**
* Defines translator behaviour.
@ -604,7 +604,7 @@ export class DialogKeywords {
user.basicOptions.translatorOn = (on.trim() === "on");
await this.min.userProfile.set(step.context, user);
this.user = user;
}
}
/**
@ -612,14 +612,14 @@ export class DialogKeywords {
*/
public async userName(step) {
return step ? WhatsappDirectLine.usernames[await this.userMobile(step)] : 'N/A';
}
}
/**
* OBSOLETE.
*/
public async getFrom(step) {
return step ? await this.userMobile(step) : 'N/A';
}
}
/**
@ -630,7 +630,7 @@ export class DialogKeywords {
*/
public async userMobile(step) {
return GBMinService.userMobile(step);
}
}
/**
* Shows the subject menu to the user
@ -640,7 +640,7 @@ export class DialogKeywords {
*/
public async showMenu(step) {
return await step.beginDialog('/menu');
}
}
/**
* Performs the transfer of the conversation to a human agent.
@ -650,7 +650,7 @@ export class DialogKeywords {
*/
public async transferTo(step, to: string = null) {
return await step.beginDialog('/t', { to: to });
}
}
/**
* Hears something from user and put it in a variable
@ -670,27 +670,12 @@ export class DialogKeywords {
if (this.hrOn) {
let sleep = ms => {
return new Promise(resolve => {
setTimeout(resolve, ms);
});
};
// Waits for next message in HEAR delegated context.
const mobile = await this.userMobile(step);
while (true) {
if (WhatsappDirectLine.state[mobile] === 3) {
break;
}
sleep(5000);
}
const result = WhatsappDirectLine.lastMessage[this.min.instance.botId + mobile];
opts = await promise(step, result);
if (previousResolve !== undefined) {
previousResolve(opts);
}
const botId = this.min.botId;
WhatsappDirectLine.state[botId + this.hrOn] = {
promise: promise, previousResolve: previousResolve
};
}
else {
@ -700,7 +685,7 @@ export class DialogKeywords {
await step.beginDialog('/hear', opts);
}
}
}
}
/**
* Prepares the next dialog to be shown to the specified user.
@ -722,16 +707,17 @@ export class DialogKeywords {
else {
await step.beginDialog(fromOrDialogName);
}
}
}
/**
* Talks to the user by using the specified text.
*/
public async talk(step, text: string) {
const translate = this.user ? this.user.basicOptions.translatorOn : false;
await this.min.conversationalService['sendTextWithOptions'](this.min, step, text,
this.user.basicOptions.translatorOn, null);
}
translate, null);
}
private static getChannel(step): string {
if (!step) return 'whatsapp';
@ -743,7 +729,7 @@ export class DialogKeywords {
}
return 'webchat';
}
}
}
/**
@ -795,5 +781,5 @@ export class DialogKeywords {
await this.min.conversationalService.sendFile(this.min, step, mobile, url, caption);
}
}
}
}

View file

@ -175,8 +175,8 @@ export class GBVMService extends GBService {
code = `<%\n
id = sys().getRandomId()
username = this.userName(step);
mobile = this.userMobile(step);
username = step ? this.userName(step) : sys().getRandomId();
mobile = step ? this.userMobile(step) : sys().getRandomId();
from = mobile;
ubound = function(array){return array.length};
isarray = function(array){return Array.isArray(array) };
@ -728,7 +728,7 @@ export class GBVMService extends GBService {
GBConfigService.get('DEFAULT_CONTENT_LANGUAGE')
);
if (step.context.activity['originalText']) {
if (step && step.context.activity['originalText']) {
const entities = await min["nerEngine"].findEntities(
step.context.activity['originalText'],
contentLocale);

View file

@ -188,8 +188,6 @@ export class GBMinService {
});
GBLog.info(`Package deployment done.`);
}
@ -524,7 +522,7 @@ export class GBMinService {
}
} catch (error) {
GBLog.error(`Error on Whatsapp callback: ${error.data ? error.data : error}`);
GBLog.error(`Error on Whatsapp callback: ${error.data ? error.data : error} ${error.stack}`);
}
}
@ -1249,6 +1247,8 @@ export class GBMinService {
} else if (cmdOrDialogName === '/call') {
await GBVMService.callVM(args, min, step, this.deployer);
} else if (cmdOrDialogName === '/callsch') {
await GBVMService.callVM(args, min, null, null);
} else {
await step.beginDialog(cmdOrDialogName, { args: args });
}

View file

@ -278,6 +278,18 @@ export class WhatsappDirectLine extends GBService {
}
}
const botId = this.min.instance.botId;
const state = WhatsappDirectLine.state[botId + from];
if ( state) {
WhatsappDirectLine.state[botId + from] = null;
await state.promise(null, message.text);
return; // Exit here.
};
// Processes .gbapp message interception.
await CollectionUtil.asyncForEach(this.min.appPackages, async (e: IGBPackage) => {
await e.onExchangeData(this.min, 'whatsappMessage', message);
@ -291,7 +303,9 @@ export class WhatsappDirectLine extends GBService {
if (answerText) {
await this.sendToDeviceEx(user.userSystemId, answerText, locale, null);
return; // Exit here.
}
if (message.type === 'ptt') {
@ -315,14 +329,12 @@ export class WhatsappDirectLine extends GBService {
`No momento estou apenas conseguindo ler mensagens de texto.`, null);
}
}
const botId = this.min.instance.botId;
const conversationId = WhatsappDirectLine.conversationIds[botId + from + group];
const client = await this.directLineClient;
WhatsappDirectLine.lastMessage[botId + from] = message;
// Check if this message is from a Human Agent itself.
if (user.agentMode === 'self') {