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", "lodash": "4.17.21",
"luxon": "3.1.0", "luxon": "3.1.0",
"mammoth": "1.5.1", "mammoth": "1.5.1",
"marked": "4.2.2",
"moment": "1.3.0", "moment": "1.3.0",
"ms-rest-azure": "3.0.2", "ms-rest-azure": "3.0.2",
"nexmo": "2.9.1", "nexmo": "2.9.1",

View file

@ -28,7 +28,7 @@
}, },
"scripts": { "scripts": {
"clean": "shx rm -rf node_modules/ dist/ docs/reference", "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": "npm install && npm run build-server && npm run build-gbui",
"build-server": "tsc", "build-server": "tsc",
"build-gbui": "cd packages/default.gbui && echo SKIP_PREFLIGHT_CHECK=true >.env && npm install && npm run build", "build-gbui": "cd packages/default.gbui && echo SKIP_PREFLIGHT_CHECK=true >.env && npm install && npm run build",
@ -104,13 +104,12 @@
"koa-router": "12.0.0", "koa-router": "12.0.0",
"lodash": "4.17.21", "lodash": "4.17.21",
"luxon": "3.1.0", "luxon": "3.1.0",
"mammoth": "1.5.1", "mammoth": "1.5.1",
"marked": "4.2.2",
"moment": "1.3.0", "moment": "1.3.0",
"ms-rest-azure": "3.0.2", "ms-rest-azure": "3.0.0",
"nexmo": "2.9.1", "nexmo": "2.9.1",
"node-cron": "3.0.2", "node-cron": "3.0.2",
"node-nlp": "^4.24.0", "node-nlp": "4.24.0",
"node-tesseract-ocr": "2.2.1", "node-tesseract-ocr": "2.2.1",
"npm": "9.1.2", "npm": "9.1.2",
"open": "8.4.0", "open": "8.4.0",

View file

@ -37,7 +37,7 @@
'use strict'; 'use strict';
import { AuthenticationContext, TokenResponse } from 'adal-node'; 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 { FindOptions } from 'sequelize/types';
import urlJoin from 'url-join'; import urlJoin from 'url-join';
import { AzureDeployerService } from '../../azuredeployer.gbapp/services/AzureDeployerService.js'; 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 phoneUtil from 'google-libphonenumber';
import phone from 'phone'; import phone from 'phone';
import DateDiff from 'date-diff'; 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 tesseract from 'node-tesseract-ocr';
import Path from 'path'; import Path from 'path';
import sgMail from '@sendgrid/mail'; import sgMail from '@sendgrid/mail';
@ -96,11 +96,11 @@ export class DialogKeywords {
*/ */
maxLines: number = 2000; maxLines: number = 2000;
public async getDeployer () { public async getDeployer() {
return this.min.deployService; return this.min.deployService;
} }
public async getMin () { public async getMin() {
return this.min; return this.min;
} }
@ -108,7 +108,7 @@ export class DialogKeywords {
* When creating this keyword facade,a bot instance is * When creating this keyword facade,a bot instance is
* specified among the deployer service. * specified among the deployer service.
*/ */
constructor (min: GBMinInstance, deployer: GBDeployer, user) { constructor(min: GBMinInstance, deployer: GBDeployer, user) {
this.min = min; this.min = min;
this.user = user; this.user = user;
this.internalSys = new SystemKeywords(min, deployer, this, null); this.internalSys = new SystemKeywords(min, deployer, this, null);
@ -120,7 +120,7 @@ export class DialogKeywords {
* Base reference of system keyword facade,called directly * Base reference of system keyword facade,called directly
* by the script. * by the script.
*/ */
public sys (): SystemKeywords { public sys(): SystemKeywords {
return this.internalSys; return this.internalSys;
} }
@ -137,7 +137,7 @@ export class DialogKeywords {
* @param legends * @param legends
* @see https://www.npmjs.com/package/plot * @see https://www.npmjs.com/package/plot
*/ */
public async chart ({ type, data, legends, transpose }) { public async chart({ type, data, legends, transpose }) {
let table = [[]]; let table = [[]];
if (legends) { if (legends) {
@ -206,7 +206,7 @@ export class DialogKeywords {
* Returns the OCR of image file. * Returns the OCR of image file.
* *
*/ */
public async getOCR ({ localFile }) { public async getOCR({ localFile }) {
GBLog.info(`BASIC: OCR processing on ${localFile}.`); GBLog.info(`BASIC: OCR processing on ${localFile}.`);
const config = { const config = {
@ -223,7 +223,7 @@ export class DialogKeywords {
* *
* @example x = TODAY * @example x = TODAY
*/ */
public async getToday ({}) { public async getToday({}) {
let d = new Date(), let d = new Date(),
month = '' + (d.getMonth() + 1), month = '' + (d.getMonth() + 1),
day = '' + d.getDate(), day = '' + d.getDate(),
@ -259,30 +259,30 @@ export class DialogKeywords {
* *
* @example EXIT * @example EXIT
*/ */
public async exit ({}) {} public async exit({}) {}
/** /**
* Get active tasks. * Get active tasks.
* *
* @example list = ACTIVE TASKS * @example list = ACTIVE TASKS
*/ */
public async getActiveTasks ({}) {} public async getActiveTasks({}) {}
/** /**
* Creates a new deal. * Creates a new deal.
* *
* @example CREATE DEAL dealname,contato,empresa,amount * @example CREATE DEAL dealname,contato,empresa,amount
*/ */
public async createDeal ({ dealName, contact, company, amount }) {} public async createDeal({ dealName, contact, company, amount }) {}
/** /**
* Finds contacts in XRM. * Finds contacts in XRM.
* *
* @example list = FIND CONTACT "Sandra" * @example list = FIND CONTACT "Sandra"
*/ */
public async fndContact ({ name }) {} public async fndContact({ name }) {}
public getContentLocaleWithCulture (contentLocale) { public getContentLocaleWithCulture(contentLocale) {
switch (contentLocale) { switch (contentLocale) {
case 'pt': case 'pt':
return 'pt-BR'; return 'pt-BR';
@ -295,7 +295,7 @@ export class DialogKeywords {
} }
} }
public async getCoded ({ value }) { public async getCoded({ value }) {
// Checks if it is a GB FILE object. // Checks if it is a GB FILE object.
if (value.data && value.filename) { if (value.data && value.filename) {
@ -311,7 +311,7 @@ export class DialogKeywords {
* @example day = WEEKDAY (date) * @example day = WEEKDAY (date)
* *
*/ */
public getWeekFromDate (date) { public getWeekFromDate(date) {
const contentLocale = this.min.core.getParam<string>( const contentLocale = this.min.core.getParam<string>(
this.min.instance, this.min.instance,
'Default Content Language', 'Default Content Language',
@ -340,7 +340,7 @@ export class DialogKeywords {
* @example days = DATEDIFF date1,date2,mode * @example days = DATEDIFF date1,date2,mode
* *
*/ */
public dateDiff (date1, date2, mode) { public dateDiff(date1, date2, mode) {
let dt1 = date1; let dt1 = date1;
let dt2 = date2; let dt2 = date2;
if (!(dt1 instanceof Date)) { if (!(dt1 instanceof Date)) {
@ -373,7 +373,7 @@ export class DialogKeywords {
* *
* https://stackoverflow.com/a/1214753/18511 * https://stackoverflow.com/a/1214753/18511
*/ */
public dateAdd (date, mode, units) { public dateAdd(date, mode, units) {
let dateCopy = date; let dateCopy = date;
if (!(dateCopy instanceof Date)) { if (!(dateCopy instanceof Date)) {
dateCopy = new Date(dateCopy); dateCopy = new Date(dateCopy);
@ -423,7 +423,7 @@ export class DialogKeywords {
* @example TALK TOLIST (array,member) * @example TALK TOLIST (array,member)
* *
*/ */
public getToLst (array, member) { public getToLst(array, member) {
if (!array) { if (!array) {
return '<Empty>'; return '<Empty>';
} }
@ -448,8 +448,8 @@ export class DialogKeywords {
* @example hour = HOUR (date) * @example hour = HOUR (date)
* *
*/ */
public getHourFromDate (date) { public getHourFromDate(date) {
function addZero (i) { function addZero(i) {
if (i < 10) { if (i < 10) {
i = '0' + i; i = '0' + i;
} }
@ -479,7 +479,7 @@ export class DialogKeywords {
* @example SAVE "contacts.xlsx", name, email, NOW * @example SAVE "contacts.xlsx", name, email, NOW
* *
*/ */
public async getNow ({}) { public async getNow({}) {
const contentLocale = this.min.core.getParam<string>( const contentLocale = this.min.core.getParam<string>(
this.min.instance, this.min.instance,
'Default Content Language', 'Default Content Language',
@ -504,7 +504,7 @@ export class DialogKeywords {
* SEND MAIL "email@domain.com","Subject", "Message text." * SEND MAIL "email@domain.com","Subject", "Message text."
* *
*/ */
public async sendEmail ({ to, subject, body }) { public async sendEmail({ to, subject, body }) {
// tslint:disable-next-line:no-console // tslint:disable-next-line:no-console
GBLog.info(`[E-mail]: to:${to},subject: ${subject},body: ${body}.`); GBLog.info(`[E-mail]: to:${to},subject: ${subject},body: ${body}.`);
@ -542,7 +542,7 @@ export class DialogKeywords {
* @example SEND FILE TO "+199988887777","image.jpg",caption * @example SEND FILE TO "+199988887777","image.jpg",caption
* *
*/ */
public async sendFileTo ({ mobile, filename, caption }) { public async sendFileTo({ mobile, filename, caption }) {
GBLog.info(`BASIC: SEND FILE TO '${mobile}',filename '${filename}'.`); GBLog.info(`BASIC: SEND FILE TO '${mobile}',filename '${filename}'.`);
return await this.internalSendFile({ mobile, filename, caption }); return await this.internalSendFile({ mobile, filename, caption });
} }
@ -553,7 +553,7 @@ export class DialogKeywords {
* @example SEND FILE "image.jpg" * @example SEND FILE "image.jpg"
* *
*/ */
public async sendFile ({ filename, caption }) { public async sendFile({ filename, caption }) {
const mobile = await this.userMobile(); const mobile = await this.userMobile();
GBLog.info(`BASIC: SEND FILE (current: ${mobile},filename '${filename}'.`); GBLog.info(`BASIC: SEND FILE (current: ${mobile},filename '${filename}'.`);
return await this.internalSendFile({ mobile, filename, caption }); return await this.internalSendFile({ mobile, filename, caption });
@ -565,7 +565,7 @@ export class DialogKeywords {
* @example SET LANGUAGE "pt" * @example SET LANGUAGE "pt"
* *
*/ */
public async setLanguage ({ language }) { public async setLanguage({ language }) {
const sec = new SecService(); const sec = new SecService();
await sec.updateUserLocale(this.user.userId, language); await sec.updateUserLocale(this.user.userId, language);
} }
@ -576,7 +576,7 @@ export class DialogKeywords {
* @example SET ID NUMBER * @example SET ID NUMBER
* *
*/ */
public async setIdGeneration ({ mode }) { public async setIdGeneration({ mode }) {
this['idGeneration'] = mode; this['idGeneration'] = mode;
this['id'] = await this.sys().getRandomId(); this['id'] = await this.sys().getRandomId();
} }
@ -587,7 +587,7 @@ export class DialogKeywords {
* @example SET MAX LINES 5000 * @example SET MAX LINES 5000
* *
*/ */
public async setMaxLines ({ count }) { public async setMaxLines({ count }) {
if (this.user) { if (this.user) {
// TODO: PARAM user.basicOptions.maxLines = count; // TODO: PARAM user.basicOptions.maxLines = count;
} else { } else {
@ -601,7 +601,7 @@ export class DialogKeywords {
* @example SET MAX COLUMNS 5000 * @example SET MAX COLUMNS 5000
* *
*/ */
public async setMaxColumns ({ count }) { public async setMaxColumns({ count }) {
// TODO: user.basicOptions.maxColumns = count; // TODO: user.basicOptions.maxColumns = count;
} }
@ -611,7 +611,7 @@ export class DialogKeywords {
* @example SET WHOLE WORD ON * @example SET WHOLE WORD ON
* *
*/ */
public async setWholeWord ({ on }) { public async setWholeWord({ on }) {
// TODO: user.basicOptions.wholeWord = (on.trim() === "on"); // TODO: user.basicOptions.wholeWord = (on.trim() === "on");
} }
@ -621,7 +621,7 @@ export class DialogKeywords {
* @example SET THEME "themename" * @example SET THEME "themename"
* *
*/ */
public async setTheme ({ theme }) { public async setTheme({ theme }) {
// TODO: user.basicOptions.theme = theme.trim(); // TODO: user.basicOptions.theme = theme.trim();
} }
@ -631,14 +631,14 @@ export class DialogKeywords {
* @example SET TRANSLATOR ON | OFF * @example SET TRANSLATOR ON | OFF
* *
*/ */
public async setTranslatorOn ({ on }) { public async setTranslatorOn({ on }) {
// TODO: user.basicOptions.translatorOn = (on.trim() === "on"); // TODO: user.basicOptions.translatorOn = (on.trim() === "on");
} }
/** /**
* Returns the name of the user acquired by WhatsApp API. * Returns the name of the user acquired by WhatsApp API.
*/ */
public async userName () { public async userName() {
// TODO: WhatsappDirectLine.usernames[await this.userMobile()] : 'N/A'; // TODO: WhatsappDirectLine.usernames[await this.userMobile()] : 'N/A';
return this.sys().getRandomId(); return this.sys().getRandomId();
} }
@ -646,7 +646,7 @@ export class DialogKeywords {
/** /**
* Returns current mobile number from user in conversation. * Returns current mobile number from user in conversation.
*/ */
public async userMobile () { public async userMobile() {
// TODO: return GBMinService.userMobile(); // TODO: return GBMinService.userMobile();
return this.sys().getRandomId(); return this.sys().getRandomId();
} }
@ -657,10 +657,10 @@ export class DialogKeywords {
* @example MENU * @example MENU
* *
*/ */
public async showMenu ({}) { public async showMenu({}) {
// TODO: return await beginDialog('/menu'); // TODO: return await beginDialog('/menu');
} }
private static async downloadAttachmentAndWrite (attachment) { private static async downloadAttachmentAndWrite(attachment) {
const url = attachment.contentUrl; const url = attachment.contentUrl;
const localFolder = Path.join('work'); // TODO: ,'${botId}','uploads'); const localFolder = Path.join('work'); // TODO: ,'${botId}','uploads');
const localFileName = Path.join(localFolder, attachment.name); const localFileName = Path.join(localFolder, attachment.name);
@ -705,7 +705,7 @@ export class DialogKeywords {
* @example TRANSFER * @example TRANSFER
* *
*/ */
public async transferTo ({ to }) { public async transferTo({ to }) {
// TODO: return await beginDialog('/t',{ to: to }); // TODO: return await beginDialog('/t',{ to: to });
} }
@ -715,7 +715,7 @@ export class DialogKeywords {
* @example HEAR name * @example HEAR name
* *
*/ */
public async getHear ({ kind, arg }) { public async getHear({ kind, arg }) {
// Handles first arg as an array of args. // Handles first arg as an array of args.
let args = []; let args = [];
@ -742,16 +742,33 @@ export class DialogKeywords {
// TODO: https://github.com/GeneralBots/BotServer/issues/266 // TODO: https://github.com/GeneralBots/BotServer/issues/266
if (args && args.length > 1) { 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).`); GBLog.info(`BASIC: HEAR with [${args.toString()}] (Asking for input).`);
} else { } else {
@ -980,7 +997,7 @@ export class DialogKeywords {
/** /**
* Prepares the next dialog to be shown to the specified user. * Prepares the next dialog to be shown to the specified user.
*/ */
public async gotoDialog ({ fromOrDialogName, dialogName }) { public async gotoDialog({ fromOrDialogName, dialogName }) {
if (dialogName) { if (dialogName) {
if (dialogName.charAt(0) === '/') { if (dialogName.charAt(0) === '/') {
// TODO: await step.beginDialog(fromOrDialogName); // TODO: await step.beginDialog(fromOrDialogName);
@ -1005,7 +1022,7 @@ export class DialogKeywords {
} }
} }
public async getSingleton ({}) { public async getSingleton({}) {
return { return {
id: this.sys().getRandomId(), id: this.sys().getRandomId(),
username: this.userName(), username: this.userName(),
@ -1023,7 +1040,7 @@ export class DialogKeywords {
/** /**
* Talks to the user by using the specified text. * Talks to the user by using the specified text.
*/ */
public async talk ({ text }) { public async talk({ text }) {
GBLog.info(`BASIC: TALK '${text}'.`); GBLog.info(`BASIC: TALK '${text}'.`);
if (this.user) { if (this.user) {
const translate = this.user ? this.user.basicOptions.translatorOn : false; const translate = this.user ? this.user.basicOptions.translatorOn : false;
@ -1032,7 +1049,7 @@ export class DialogKeywords {
} }
} }
private static getChannel (): string { private static getChannel(): string {
return 'whatsapp'; return 'whatsapp';
// TODO: // TODO:
} }
@ -1040,7 +1057,7 @@ export class DialogKeywords {
/** /**
* Processes the sending of the file. * Processes the sending of the file.
*/ */
private async internalSendFile ({ mobile, filename, caption }) { private async internalSendFile({ mobile, filename, caption }) {
// Handles SEND FILE TO mobile,element in Web Automation. // Handles SEND FILE TO mobile,element in Web Automation.
const element = filename._page ? filename._page : filename.screenshot ? filename : null; const element = filename._page ? filename._page : filename.screenshot ? filename : null;
@ -1085,7 +1102,7 @@ export class DialogKeywords {
} }
} }
public async getQRCode ({ text }) { public async getQRCode({ text }) {
const img = await qrcode.toDataURL(text); const img = await qrcode.toDataURL(text);
const data = img.replace(/^data:image\/\w+;base64,/, ''); const data = img.replace(/^data:image\/\w+;base64,/, '');
const buf = Buffer.from(data, 'base64'); const buf = Buffer.from(data, 'base64');

View file

@ -294,6 +294,7 @@ export class GBVMService extends GBService {
if (error) { if (error) {
reject(error); reject(error);
} else { } else {
text = text.replace('¨', '"');
text = text.replace('“', '"'); text = text.replace('“', '"');
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> { public async find ({ args }): Promise<any> {
const file = args[0]; const file = args[0];
args.shift(); args.shift();
GBLog.info(`BASIC: FIND running on ${file} and args: ${JSON.stringify(args)}...`);
const botId = this.min.instance.botId; const botId = this.min.instance.botId;
const path = `/${botId}.gbai/${botId}.gbdata`; const path = `/${botId}.gbai/${botId}.gbdata`;
@ -671,6 +671,7 @@ export class SystemKeywords {
} else { } else {
maxLines = this.dk.maxLines; 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) // 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. if (streaming) { // TODO: Do it with fetch.
options['responseType'] = 'stream'; options['responseType'] = 'stream';
options['encoding'] = null; options['encoding'] = null;
} }fetch
let result = await fetch(url, options); const result = await fetch(url, options);
try { try {
return JSON.parse(await result.text()); return JSON.parse(await result.text());

View file

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

View file

@ -256,7 +256,9 @@ export class GBMinService {
GBServer.globals.sysPackages, GBServer.globals.sysPackages,
GBServer.globals.appPackages GBServer.globals.appPackages
); );
min['groupCache'] = await KBService.getGroupReplies(instance.instanceId);
// TODO: min['groupCache'] = await KBService.getGroupReplies(instance.instanceId);
GBServer.globals.minInstances.push(min); GBServer.globals.minInstances.push(min);
await this.deployer.deployPackage(min, 'packages/default.gbtheme'); await this.deployer.deployPackage(min, 'packages/default.gbtheme');
@ -296,7 +298,7 @@ export class GBMinService {
// Loads Named Entity data for this bot. // Loads Named Entity data for this bot.
await KBService.RefreshNER(min); // TODO: await KBService.RefreshNER(min);
// Calls the loadBot context.activity for all packages. // 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 { export class GBGoogleChatPackage implements IGBPackage {
public sysPackages: 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) { public async getDialogs (min: GBMinInstance) {
GBLog.verbose(`getDialogs called.`); GBLog.verbose(`getDialogs called.`);

View file

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

View file

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

View file

@ -14,7 +14,8 @@ export const Messages = {
whats_mobile: 'Qual o seu celular?', whats_mobile: 'Qual o seu celular?',
confirm_mobile: 'Por favor, digite o código enviado para seu celular.', confirm_mobile: 'Por favor, digite o código enviado para seu celular.',
confirm_mobile_again: 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_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_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).' validation_enter_valid_mobile: 'Por favor, insira um número de celular válido (ex.: +55 21 98888-7766).'

View file

@ -45,24 +45,26 @@ import { Sequelize } from 'sequelize-typescript';
export class GBTeamsPackage implements IGBPackage { export class GBTeamsPackage implements IGBPackage {
public sysPackages: 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) { public async getDialogs(min: GBMinInstance) {
GBLog.verbose(`getDialogs called.`); GBLog.verbose(`getDialogs called.`);
} }
public async loadPackage (core: IGBCoreService, sequelize: Sequelize): Promise<void> { public async loadPackage(core: IGBCoreService, sequelize: Sequelize): Promise<void> {
GBLog.verbose(`loadPackage called.`); GBLog.verbose(`loadPackage called.`);
} }
public async unloadPackage (core: IGBCoreService): Promise<void> { public async unloadPackage(core: IGBCoreService): Promise<void> {
GBLog.verbose(`unloadPackage called.`); GBLog.verbose(`unloadPackage called.`);
} }
public async unloadBot (min: GBMinInstance): Promise<void> { public async unloadBot(min: GBMinInstance): Promise<void> {
GBLog.verbose(`unloadBot called.`); GBLog.verbose(`unloadBot called.`);
} }
public async onNewSession (min: GBMinInstance, step: GBDialogStep): Promise<void> { public async onNewSession(min: GBMinInstance, step: GBDialogStep): Promise<void> {
GBLog.verbose(`onNewSession called.`); GBLog.verbose(`onNewSession called.`);
} }
public async onExchangeData (min: GBMinInstance, kind: string, data: any) { public async onExchangeData(min: GBMinInstance, kind: string, data: any) {
GBLog.verbose(`onExchangeData called.`); GBLog.verbose(`onExchangeData called.`);
} }
} }

View file

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

View file

@ -314,6 +314,9 @@ export class WhatsappDirectLine extends GBService {
public async check() { public async check() {
switch (this.provider) { switch (this.provider) {
case 'GeneralBots': case 'GeneralBots':
// TODO: Verify if browser is OK.
return true; return true;
default: default:
GBLog.verbose(`GBWhatsapp: Checking server...`); 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 mkdirp from 'mkdirp';
import Path from 'path'; import Path from 'path';
import * as Fs from 'fs'; 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 { GBAdminService } from '../packages/admin.gbapp/services/GBAdminService.js';
import { AzureDeployerService } from '../packages/azuredeployer.gbapp/services/AzureDeployerService.js'; import { AzureDeployerService } from '../packages/azuredeployer.gbapp/services/AzureDeployerService.js';
import { GBConfigService } from '../packages/core.gbapp/services/GBConfigService.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 auth from 'basic-auth';
import child_process from 'child_process'; import child_process from 'child_process';
import * as winston from 'winston-logs-display'; 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. * 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) { if (process.env.CERTIFICATE_PFX) {
const options = { const options1 = {
passphrase: process.env.CERTIFICATE_PASSPHRASE, passphrase: process.env.CERTIFICATE_PASSPHRASE,
pfx: Fs.readFileSync(process.env.CERTIFICATE_PFX) 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) { if (process.env.CERTIFICATE2_PFX) {
const options = { const options2 = {
passphrase: process.env.CERTIFICATE2_PASSPHRASE, passphrase: process.env.CERTIFICATE2_PASSPHRASE,
pfx: Fs.readFileSync(process.env.CERTIFICATE2_PFX) pfx: Fs.readFileSync(process.env.CERTIFICATE2_PFX)
}; };
httpsServer.addContext(process.env.CERTIFICATE2_DOMAIN, options); httpsServer.addContext(process.env.CERTIFICATE2_DOMAIN, options2);
} }
} else { } else {
server.listen(port, mainCallback); server.listen(port, mainCallback);

View file

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