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

@ -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 {
@ -729,8 +714,9 @@ export class DialogKeywords {
* 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 {

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') {