fix(all): Fixing bugs of 3.0.

This commit is contained in:
rodrigorodriguez 2022-12-14 08:23:39 -03:00
parent ea6c721cb5
commit bf705c730b
18 changed files with 173 additions and 104 deletions

1
package-lock.json generated
View file

@ -64,7 +64,6 @@
"lodash": "4.17.21",
"luxon": "3.1.0",
"mammoth": "1.5.1",
"marked": "4.2.2",
"moment": "1.3.0",
"ms-rest-azure": "3.0.2",
"nexmo": "2.9.1",

View file

@ -28,7 +28,7 @@
},
"scripts": {
"clean": "shx rm -rf node_modules/ dist/ docs/reference",
"tslint": "tslint --fix ./src/*.ts ./packages/**/*.ts -t verbose -e ./packages/default.gbui/**/* -e ./packages/**/*.gbdialog/**/*",
"tslint": "tslint --fix ./src/*.ts ./packages/**/*.ts -t verbose",
"build": "npm install && npm run build-server && npm run build-gbui",
"build-server": "tsc",
"build-gbui": "cd packages/default.gbui && echo SKIP_PREFLIGHT_CHECK=true >.env && npm install && npm run build",
@ -105,12 +105,11 @@
"lodash": "4.17.21",
"luxon": "3.1.0",
"mammoth": "1.5.1",
"marked": "4.2.2",
"moment": "1.3.0",
"ms-rest-azure": "3.0.2",
"ms-rest-azure": "3.0.0",
"nexmo": "2.9.1",
"node-cron": "3.0.2",
"node-nlp": "^4.24.0",
"node-nlp": "4.24.0",
"node-tesseract-ocr": "2.2.1",
"npm": "9.1.2",
"open": "8.4.0",

View file

@ -37,7 +37,7 @@
'use strict';
import { AuthenticationContext, TokenResponse } from 'adal-node';
import { GBLog, GBMinInstance, IGBAdminService, IGBCoreService, IGBDeployer, IGBInstance } from 'botlib';
import { GBMinInstance, IGBAdminService, IGBCoreService, IGBDeployer, IGBInstance } from 'botlib';
import { FindOptions } from 'sequelize/types';
import urlJoin from 'url-join';
import { AzureDeployerService } from '../../azuredeployer.gbapp/services/AzureDeployerService.js';

View file

@ -50,7 +50,7 @@ import { GuaribasUser } from '../../security.gbapp/models/index.js';
import phoneUtil from 'google-libphonenumber';
import phone from 'phone';
import DateDiff from 'date-diff';
import { Buttons } from 'whatsapp-web.js';
import { Buttons, List } from 'whatsapp-web.js';
import tesseract from 'node-tesseract-ocr';
import Path from 'path';
import sgMail from '@sendgrid/mail';
@ -742,16 +742,33 @@ export class DialogKeywords {
// TODO: https://github.com/GeneralBots/BotServer/issues/266
if (args && args.length > 1) {
let choices = [];
let i = 0;
await CollectionUtil.asyncForEach(args, async arg => {
i++;
choices.push({ body: arg, id: `button${i}` });
await this.talk(arg);
});
const button = new wpp.Buttons(Messages[locale].choices, choices, ' ', ' ');
// TODO: await this.talk(button);
// TODO: https://github.com/pedroslopez/whatsapp-web.js/issues/1811
//
// const list = new List(
// 'Escolha um dos itens',
// 'Itens1',
// [
// {
// title: 'Itens2',
// rows: []
// }
// ],
// 'Please select a product'
// );
// let i = 0;
// await CollectionUtil.asyncForEach(args, async arg => {
// i++;
// list.sections[0].rows.push({ title: arg, id: `button${i}` });
// await this.talk(arg);
// });
// const button = new wpp.Buttons(Messages[locale].choices, choices, ' ', ' ');
// await this.talk(button);
GBLog.info(`BASIC: HEAR with [${args.toString()}] (Asking for input).`);
} else {

View file

@ -294,6 +294,7 @@ export class GBVMService extends GBService {
if (error) {
reject(error);
} else {
text = text.replace('¨', '"');
text = text.replace('“', '"');
text = text.replace('”', '"');
text = text.replace('', "'");

View file

@ -656,7 +656,7 @@ export class SystemKeywords {
public async find ({ args }): Promise<any> {
const file = args[0];
args.shift();
GBLog.info(`BASIC: FIND running on ${file} and args: ${JSON.stringify(args)}...`);
const botId = this.min.instance.botId;
const path = `/${botId}.gbai/${botId}.gbdata`;
@ -671,6 +671,7 @@ export class SystemKeywords {
} else {
maxLines = this.dk.maxLines;
}
GBLog.info(`BASIC: FIND running on ${file} (maxLines: ${maxLines}) and args: ${JSON.stringify(args)}...`);
// Choose data sources based on file type (HTML Table, data variable or sheet file)
@ -1295,8 +1296,8 @@ export class SystemKeywords {
if (streaming) { // TODO: Do it with fetch.
options['responseType'] = 'stream';
options['encoding'] = null;
}
let result = await fetch(url, options);
}fetch
const result = await fetch(url, options);
try {
return JSON.parse(await result.text());

View file

@ -117,7 +117,7 @@ export class WebAutomationKeywords {
/**
* Returns the page object.
*
* @example x = GET PAGE
* @example OPEN "https://wikipedia.org"
*/
public async getPage ({ url, username, password }) {
GBLog.info(`BASIC: Web Automation GET PAGE ${url}.`);

View file

@ -256,7 +256,9 @@ export class GBMinService {
GBServer.globals.sysPackages,
GBServer.globals.appPackages
);
min['groupCache'] = await KBService.getGroupReplies(instance.instanceId);
// TODO: min['groupCache'] = await KBService.getGroupReplies(instance.instanceId);
GBServer.globals.minInstances.push(min);
await this.deployer.deployPackage(min, 'packages/default.gbtheme');
@ -296,7 +298,7 @@ export class GBMinService {
// Loads Named Entity data for this bot.
await KBService.RefreshNER(min);
// TODO: await KBService.RefreshNER(min);
// Calls the loadBot context.activity for all packages.

View file

@ -46,7 +46,9 @@ import { GoogleChatDirectLine } from './services/GoogleChatDirectLine.js';
export class GBGoogleChatPackage implements IGBPackage {
public sysPackages: IGBPackage[];
public async loadBot (min: GBMinInstance): Promise<void> {}
public async loadBot (min: GBMinInstance): Promise<void> {
GBLog.verbose(`loadBot called.`);
}
public async getDialogs (min: GBMinInstance) {
GBLog.verbose(`getDialogs called.`);

View file

@ -45,7 +45,9 @@ import { Sequelize } from 'sequelize-typescript';
export class GBHubSpotPackage implements IGBPackage {
public sysPackages: IGBPackage[];
public async loadBot (min: GBMinInstance): Promise<void> {}
public async loadBot (min: GBMinInstance): Promise<void> {
GBLog.verbose(`loadBot called.`);
}
public async getDialogs (min: GBMinInstance) {
GBLog.verbose(`getDialogs called.`);

View file

@ -63,8 +63,9 @@ export class GuaribasUser extends Model<GuaribasUser> {
@Column(DataType.STRING(255))
displayName: string;
@Column(DataType.INTEGER)
@Column(DataType.STRING(255))
userSystemId: string;
@Column(DataType.STRING(255))
userName: string;

View file

@ -14,7 +14,8 @@ export const Messages = {
whats_mobile: 'Qual o seu celular?',
confirm_mobile: 'Por favor, digite o código enviado para seu celular.',
confirm_mobile_again:
'Esse não me parece ser um código numérico válido. Por favor, digite novamente o código enviado para seu celular.',
`Esse não me parece ser um código numérico válido. Por favor, digite novamente o
código enviado para seu celular.`,
validation_enter_valid_email: 'Por favor, digite um e-mail válido no formato nome@domínio.com.br.',
validation_enter_name: 'Por favor, digite seu nome completo',
validation_enter_valid_mobile: 'Por favor, insira um número de celular válido (ex.: +55 21 98888-7766).'

View file

@ -45,7 +45,9 @@ import { Sequelize } from 'sequelize-typescript';
export class GBTeamsPackage implements IGBPackage {
public sysPackages: IGBPackage[];
public async loadBot (min: GBMinInstance): Promise<void> {}
public async loadBot(min: GBMinInstance): Promise<void> {
GBLog.verbose(`loadBot called.`);
}
public async getDialogs(min: GBMinInstance) {
GBLog.verbose(`getDialogs called.`);

View file

@ -46,7 +46,9 @@ import { WhatsappDirectLine } from './services/WhatsappDirectLine.js';
export class GBWhatsappPackage implements IGBPackage {
public sysPackages: IGBPackage[];
public async loadBot (min: GBMinInstance): Promise<void> {}
public async loadBot (min: GBMinInstance): Promise<void> {
GBLog.verbose(`loadBot called.`);
}
public async getDialogs (min: GBMinInstance) {
GBLog.verbose(`getDialogs called.`);

View file

@ -314,6 +314,9 @@ export class WhatsappDirectLine extends GBService {
public async check() {
switch (this.provider) {
case 'GeneralBots':
// TODO: Verify if browser is OK.
return true;
default:
GBLog.verbose(`GBWhatsapp: Checking server...`);

56
src/RootData.ts Normal file
View file

@ -0,0 +1,56 @@
/*****************************************************************************\
| ( )_ _ |
| _ _ _ __ _ _ __ ___ ___ _ _ | ,_)(_) ___ ___ _ |
| ( '_`\ ( '__)/'_` ) /'_ `\/' _ ` _ `\ /'_` )| | | |/',__)/' v `\ /'_`\ |
| | (_) )| | ( (_| |( (_) || ( ) ( ) |( (_| || |_ | |\__, \| (˅) |( (_) ) |
| | ,__/'(_) `\__,_)`\__ |(_) (_) (_)`\__,_)`\__)(_)(____/(_) (_)`\___/' |
| | | ( )_) | |
| (_) \___/' |
| |
| General Bots Copyright (c) Pragmatismo.io. All rights reserved. |
| Licensed under the AGPL-3.0. |
| |
| According to our dual licensing model, this program can be used either |
| under the terms of the GNU Affero General Public License, version 3, |
| or under a proprietary license. |
| |
| The texts of the GNU Affero General Public License with an additional |
| permission and of our proprietary license can be found at and |
| in the LICENSE file you have received along with this program. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY, without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| "General Bots" is a registered trademark of Pragmatismo.io. |
| The licensing of the program under the AGPLv3 does not imply a |
| trademark license. Therefore any rights, title and interest in |
| our trademarks remain entirely with us. |
| |
\*****************************************************************************/
/**
* @fileoverview General Bots server core.
*/
'use strict';
import { GBMinInstance, IGBInstance } from 'botlib';
import { GBMinService } from '../packages/core.gbapp/services/GBMinService.js';
/**
* Global shared server data;
*/
export class RootData {
public publicAddress: string; // URI for BotServer
public server: any; // Express reference
public sysPackages: any[]; // Loaded system package list
public appPackages: any[]; // Loaded .gbapp package list
public minService: GBMinService; // Minimalist service core
public bootInstance: IGBInstance; // General Bot Interface Instance
public minInstances: any[]; // List of bot instances.
public minBoot: GBMinInstance; // Reference to boot bot.
public wwwroot: string; // .gbui or a static webapp.
public entryPointDialog: string; // To replace default welcome dialog.
public debugConversationId: any; // Used to self-message during debug.
public debuggers: any[]; // Client of attached Debugger instances by botId.
}

View file

@ -42,7 +42,7 @@ import https from 'https';
import mkdirp from 'mkdirp';
import Path from 'path';
import * as Fs from 'fs';
import { GBLog, GBMinInstance, IGBCoreService, IGBInstance, IGBPackage } from 'botlib';
import { GBLog, IGBCoreService, IGBInstance, IGBPackage } from 'botlib';
import { GBAdminService } from '../packages/admin.gbapp/services/GBAdminService.js';
import { AzureDeployerService } from '../packages/azuredeployer.gbapp/services/AzureDeployerService.js';
import { GBConfigService } from '../packages/core.gbapp/services/GBConfigService.js';
@ -54,24 +54,8 @@ import { GBMinService } from '../packages/core.gbapp/services/GBMinService.js';
import auth from 'basic-auth';
import child_process from 'child_process';
import * as winston from 'winston-logs-display';
import { RootData } from './RootData.js';
/**
* Global shared server data;
*/
export class RootData {
public publicAddress: string; // URI for BotServer
public server: any; // Express reference
public sysPackages: any[]; // Loaded system package list
public appPackages: any[]; // Loaded .gbapp package list
public minService: GBMinService; // Minimalist service core
public bootInstance: IGBInstance; // General Bot Interface Instance
public minInstances: any[]; // List of bot instances.
public minBoot: GBMinInstance; // Reference to boot bot.
public wwwroot: string; // .gbui or a static webapp.
public entryPointDialog: string; // To replace default welcome dialog.
public debugConversationId: any; // Used to self-message during debug.
public debuggers: any[]; // Client of attached Debugger instances by botId.
}
/**
* General Bots open-core entry point.
*/
@ -245,19 +229,20 @@ export class GBServer {
}
})();
};
// TODO: Move to .gbot folder myown.com pointing to generalbots.ai/myown
if (process.env.CERTIFICATE_PFX) {
const options = {
const options1 = {
passphrase: process.env.CERTIFICATE_PASSPHRASE,
pfx: Fs.readFileSync(process.env.CERTIFICATE_PFX)
};
const httpsServer = https.createServer(options, server).listen(port, mainCallback);
const httpsServer = https.createServer(options1, server).listen(port, mainCallback);
if (process.env.CERTIFICATE2_PFX) {
const options = {
const options2 = {
passphrase: process.env.CERTIFICATE2_PASSPHRASE,
pfx: Fs.readFileSync(process.env.CERTIFICATE2_PFX)
};
httpsServer.addContext(process.env.CERTIFICATE2_DOMAIN, options);
httpsServer.addContext(process.env.CERTIFICATE2_DOMAIN, options2);
}
} else {
server.listen(port, mainCallback);

View file

@ -19,7 +19,7 @@
"no-unsafe-any": false,
"no-floating-promises": false,
"no-var-requires": false,
"typedef": false,
"typedef": true,
"variable-name": false,
"no-parameter-properties": false,
"max-line-length": [
@ -29,10 +29,6 @@
"ignore-pattern": "^\\s+\\*"
}
],
"await-promise": [
true,
"Bluebird"
],
"no-reserved-keywords": false,
"no-unnecessary-class": false,
"no-string-literal": false,