From c8caebdf613d5b41922401eed19f989d08b314e5 Mon Sep 17 00:00:00 2001 From: rodrigorodriguez Date: Wed, 14 Dec 2022 08:23:39 -0300 Subject: [PATCH] fix(all): Fixing bugs of 3.0. --- package-lock.json | 1 - package.json | 9 +- .../admin.gbapp/services/GBAdminService.ts | 2 +- .../basic.gblib/services/DialogKeywords.ts | 121 ++++++++++-------- packages/basic.gblib/services/GBVMService.ts | 1 + .../basic.gblib/services/SystemKeywords.ts | 7 +- .../services/WebAutomationKeywords.ts | 2 +- packages/core.gbapp/services/GBMinService.ts | 6 +- packages/google-chat.gblib/index.ts | 4 +- packages/hubspot.gblib/index.ts | 4 +- packages/security.gbapp/models/index.ts | 3 +- packages/security.gbapp/strings.ts | 3 +- packages/teams.gblib/index.ts | 16 ++- packages/whatsapp.gblib/index.ts | 4 +- .../services/WhatsappDirectLine.ts | 3 + src/RootData.ts | 56 ++++++++ src/app.ts | 29 +---- tslint.json | 6 +- 18 files changed, 173 insertions(+), 104 deletions(-) create mode 100644 src/RootData.ts diff --git a/package-lock.json b/package-lock.json index c6edbd0b6..2fcbbaed5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/package.json b/package.json index 1b3c9ea13..e64090ba2 100644 --- a/package.json +++ b/package.json @@ -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", @@ -104,13 +104,12 @@ "koa-router": "12.0.0", "lodash": "4.17.21", "luxon": "3.1.0", - "mammoth": "1.5.1", - "marked": "4.2.2", + "mammoth": "1.5.1", "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", diff --git a/packages/admin.gbapp/services/GBAdminService.ts b/packages/admin.gbapp/services/GBAdminService.ts index 7393f9e3e..14cb08404 100644 --- a/packages/admin.gbapp/services/GBAdminService.ts +++ b/packages/admin.gbapp/services/GBAdminService.ts @@ -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'; diff --git a/packages/basic.gblib/services/DialogKeywords.ts b/packages/basic.gblib/services/DialogKeywords.ts index 36f7319e3..eb5a74f74 100644 --- a/packages/basic.gblib/services/DialogKeywords.ts +++ b/packages/basic.gblib/services/DialogKeywords.ts @@ -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'; @@ -96,11 +96,11 @@ export class DialogKeywords { */ maxLines: number = 2000; - public async getDeployer () { + public async getDeployer() { return this.min.deployService; } - public async getMin () { + public async getMin() { return this.min; } @@ -108,7 +108,7 @@ export class DialogKeywords { * When creating this keyword facade,a bot instance is * specified among the deployer service. */ - constructor (min: GBMinInstance, deployer: GBDeployer, user) { + constructor(min: GBMinInstance, deployer: GBDeployer, user) { this.min = min; this.user = user; this.internalSys = new SystemKeywords(min, deployer, this, null); @@ -120,7 +120,7 @@ export class DialogKeywords { * Base reference of system keyword facade,called directly * by the script. */ - public sys (): SystemKeywords { + public sys(): SystemKeywords { return this.internalSys; } @@ -137,7 +137,7 @@ export class DialogKeywords { * @param legends * @see https://www.npmjs.com/package/plot */ - public async chart ({ type, data, legends, transpose }) { + public async chart({ type, data, legends, transpose }) { let table = [[]]; if (legends) { @@ -206,7 +206,7 @@ export class DialogKeywords { * Returns the OCR of image file. * */ - public async getOCR ({ localFile }) { + public async getOCR({ localFile }) { GBLog.info(`BASIC: OCR processing on ${localFile}.`); const config = { @@ -223,7 +223,7 @@ export class DialogKeywords { * * @example x = TODAY */ - public async getToday ({}) { + public async getToday({}) { let d = new Date(), month = '' + (d.getMonth() + 1), day = '' + d.getDate(), @@ -259,30 +259,30 @@ export class DialogKeywords { * * @example EXIT */ - public async exit ({}) {} + public async exit({}) {} /** * Get active tasks. * * @example list = ACTIVE TASKS */ - public async getActiveTasks ({}) {} + public async getActiveTasks({}) {} /** * Creates a new deal. * * @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. * * @example list = FIND CONTACT "Sandra" */ - public async fndContact ({ name }) {} + public async fndContact({ name }) {} - public getContentLocaleWithCulture (contentLocale) { + public getContentLocaleWithCulture(contentLocale) { switch (contentLocale) { case 'pt': 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. if (value.data && value.filename) { @@ -311,7 +311,7 @@ export class DialogKeywords { * @example day = WEEKDAY (date) * */ - public getWeekFromDate (date) { + public getWeekFromDate(date) { const contentLocale = this.min.core.getParam( this.min.instance, 'Default Content Language', @@ -340,7 +340,7 @@ export class DialogKeywords { * @example days = DATEDIFF date1,date2,mode * */ - public dateDiff (date1, date2, mode) { + public dateDiff(date1, date2, mode) { let dt1 = date1; let dt2 = date2; if (!(dt1 instanceof Date)) { @@ -373,7 +373,7 @@ export class DialogKeywords { * * https://stackoverflow.com/a/1214753/18511 */ - public dateAdd (date, mode, units) { + public dateAdd(date, mode, units) { let dateCopy = date; if (!(dateCopy instanceof Date)) { dateCopy = new Date(dateCopy); @@ -423,7 +423,7 @@ export class DialogKeywords { * @example TALK TOLIST (array,member) * */ - public getToLst (array, member) { + public getToLst(array, member) { if (!array) { return ''; } @@ -448,8 +448,8 @@ export class DialogKeywords { * @example hour = HOUR (date) * */ - public getHourFromDate (date) { - function addZero (i) { + public getHourFromDate(date) { + function addZero(i) { if (i < 10) { i = '0' + i; } @@ -479,7 +479,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', @@ -504,7 +504,7 @@ export class DialogKeywords { * 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 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 * */ - public async sendFileTo ({ mobile, filename, caption }) { + public async sendFileTo({ mobile, filename, caption }) { GBLog.info(`BASIC: SEND FILE TO '${mobile}',filename '${filename}'.`); return await this.internalSendFile({ mobile, filename, caption }); } @@ -553,7 +553,7 @@ export class DialogKeywords { * @example SEND FILE "image.jpg" * */ - public async sendFile ({ filename, caption }) { + public async sendFile({ filename, caption }) { const mobile = await this.userMobile(); GBLog.info(`BASIC: SEND FILE (current: ${mobile},filename '${filename}'.`); return await this.internalSendFile({ mobile, filename, caption }); @@ -565,7 +565,7 @@ export class DialogKeywords { * @example SET LANGUAGE "pt" * */ - public async setLanguage ({ language }) { + public async setLanguage({ language }) { const sec = new SecService(); await sec.updateUserLocale(this.user.userId, language); } @@ -576,7 +576,7 @@ export class DialogKeywords { * @example SET ID NUMBER * */ - public async setIdGeneration ({ mode }) { + public async setIdGeneration({ mode }) { this['idGeneration'] = mode; this['id'] = await this.sys().getRandomId(); } @@ -587,7 +587,7 @@ export class DialogKeywords { * @example SET MAX LINES 5000 * */ - public async setMaxLines ({ count }) { + public async setMaxLines({ count }) { if (this.user) { // TODO: PARAM user.basicOptions.maxLines = count; } else { @@ -601,7 +601,7 @@ export class DialogKeywords { * @example SET MAX COLUMNS 5000 * */ - public async setMaxColumns ({ count }) { + public async setMaxColumns({ count }) { // TODO: user.basicOptions.maxColumns = count; } @@ -611,7 +611,7 @@ export class DialogKeywords { * @example SET WHOLE WORD ON * */ - public async setWholeWord ({ on }) { + public async setWholeWord({ on }) { // TODO: user.basicOptions.wholeWord = (on.trim() === "on"); } @@ -621,7 +621,7 @@ export class DialogKeywords { * @example SET THEME "themename" * */ - public async setTheme ({ theme }) { + public async setTheme({ theme }) { // TODO: user.basicOptions.theme = theme.trim(); } @@ -631,14 +631,14 @@ export class DialogKeywords { * @example SET TRANSLATOR ON | OFF * */ - public async setTranslatorOn ({ on }) { + public async setTranslatorOn({ on }) { // TODO: user.basicOptions.translatorOn = (on.trim() === "on"); } /** * Returns the name of the user acquired by WhatsApp API. */ - public async userName () { + public async userName() { // TODO: WhatsappDirectLine.usernames[await this.userMobile()] : 'N/A'; return this.sys().getRandomId(); } @@ -646,7 +646,7 @@ export class DialogKeywords { /** * Returns current mobile number from user in conversation. */ - public async userMobile () { + public async userMobile() { // TODO: return GBMinService.userMobile(); return this.sys().getRandomId(); } @@ -657,10 +657,10 @@ export class DialogKeywords { * @example MENU * */ - public async showMenu ({}) { + public async showMenu({}) { // TODO: return await beginDialog('/menu'); } - private static async downloadAttachmentAndWrite (attachment) { + private static async downloadAttachmentAndWrite(attachment) { const url = attachment.contentUrl; const localFolder = Path.join('work'); // TODO: ,'${botId}','uploads'); const localFileName = Path.join(localFolder, attachment.name); @@ -705,7 +705,7 @@ export class DialogKeywords { * @example TRANSFER * */ - public async transferTo ({ to }) { + public async transferTo({ to }) { // TODO: return await beginDialog('/t',{ to: to }); } @@ -715,7 +715,7 @@ export class DialogKeywords { * @example HEAR name * */ - public async getHear ({ kind, arg }) { + public async getHear({ kind, arg }) { // Handles first arg as an array of args. let args = []; @@ -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 { @@ -980,7 +997,7 @@ export class DialogKeywords { /** * 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.charAt(0) === '/') { // TODO: await step.beginDialog(fromOrDialogName); @@ -1005,7 +1022,7 @@ export class DialogKeywords { } } - public async getSingleton ({}) { + public async getSingleton({}) { return { id: this.sys().getRandomId(), username: this.userName(), @@ -1023,7 +1040,7 @@ export class DialogKeywords { /** * Talks to the user by using the specified text. */ - public async talk ({ text }) { + public async talk({ text }) { GBLog.info(`BASIC: TALK '${text}'.`); if (this.user) { 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'; // TODO: } @@ -1040,7 +1057,7 @@ export class DialogKeywords { /** * 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. 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 data = img.replace(/^data:image\/\w+;base64,/, ''); const buf = Buffer.from(data, 'base64'); diff --git a/packages/basic.gblib/services/GBVMService.ts b/packages/basic.gblib/services/GBVMService.ts index 85d2fd928..1c72e7e6e 100644 --- a/packages/basic.gblib/services/GBVMService.ts +++ b/packages/basic.gblib/services/GBVMService.ts @@ -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('‘', "'"); diff --git a/packages/basic.gblib/services/SystemKeywords.ts b/packages/basic.gblib/services/SystemKeywords.ts index 4c4d5c60d..63d23be5f 100644 --- a/packages/basic.gblib/services/SystemKeywords.ts +++ b/packages/basic.gblib/services/SystemKeywords.ts @@ -656,7 +656,7 @@ export class SystemKeywords { public async find ({ args }): Promise { 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()); diff --git a/packages/basic.gblib/services/WebAutomationKeywords.ts b/packages/basic.gblib/services/WebAutomationKeywords.ts index 4ccaeac4d..6d0ab21b7 100644 --- a/packages/basic.gblib/services/WebAutomationKeywords.ts +++ b/packages/basic.gblib/services/WebAutomationKeywords.ts @@ -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}.`); diff --git a/packages/core.gbapp/services/GBMinService.ts b/packages/core.gbapp/services/GBMinService.ts index a9c99ca68..727a608a0 100644 --- a/packages/core.gbapp/services/GBMinService.ts +++ b/packages/core.gbapp/services/GBMinService.ts @@ -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. diff --git a/packages/google-chat.gblib/index.ts b/packages/google-chat.gblib/index.ts index 6214a26c5..ac53df6f1 100644 --- a/packages/google-chat.gblib/index.ts +++ b/packages/google-chat.gblib/index.ts @@ -46,7 +46,9 @@ import { GoogleChatDirectLine } from './services/GoogleChatDirectLine.js'; export class GBGoogleChatPackage implements IGBPackage { public sysPackages: IGBPackage[]; - public async loadBot (min: GBMinInstance): Promise {} + public async loadBot (min: GBMinInstance): Promise { + GBLog.verbose(`loadBot called.`); + } public async getDialogs (min: GBMinInstance) { GBLog.verbose(`getDialogs called.`); diff --git a/packages/hubspot.gblib/index.ts b/packages/hubspot.gblib/index.ts index 3f1424946..62ef6c7c4 100644 --- a/packages/hubspot.gblib/index.ts +++ b/packages/hubspot.gblib/index.ts @@ -45,7 +45,9 @@ import { Sequelize } from 'sequelize-typescript'; export class GBHubSpotPackage implements IGBPackage { public sysPackages: IGBPackage[]; - public async loadBot (min: GBMinInstance): Promise {} + public async loadBot (min: GBMinInstance): Promise { + GBLog.verbose(`loadBot called.`); + } public async getDialogs (min: GBMinInstance) { GBLog.verbose(`getDialogs called.`); diff --git a/packages/security.gbapp/models/index.ts b/packages/security.gbapp/models/index.ts index e1c608f04..5b6c38be0 100644 --- a/packages/security.gbapp/models/index.ts +++ b/packages/security.gbapp/models/index.ts @@ -63,8 +63,9 @@ export class GuaribasUser extends Model { @Column(DataType.STRING(255)) displayName: string; - @Column(DataType.INTEGER) + @Column(DataType.STRING(255)) userSystemId: string; + @Column(DataType.STRING(255)) userName: string; diff --git a/packages/security.gbapp/strings.ts b/packages/security.gbapp/strings.ts index 1e7e36bef..c3cbb6788 100644 --- a/packages/security.gbapp/strings.ts +++ b/packages/security.gbapp/strings.ts @@ -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).' diff --git a/packages/teams.gblib/index.ts b/packages/teams.gblib/index.ts index a41f1069f..9ec35d9b9 100644 --- a/packages/teams.gblib/index.ts +++ b/packages/teams.gblib/index.ts @@ -45,24 +45,26 @@ import { Sequelize } from 'sequelize-typescript'; export class GBTeamsPackage implements IGBPackage { public sysPackages: IGBPackage[]; - public async loadBot (min: GBMinInstance): Promise {} + public async loadBot(min: GBMinInstance): Promise { + GBLog.verbose(`loadBot called.`); + } - public async getDialogs (min: GBMinInstance) { + public async getDialogs(min: GBMinInstance) { GBLog.verbose(`getDialogs called.`); } - public async loadPackage (core: IGBCoreService, sequelize: Sequelize): Promise { + public async loadPackage(core: IGBCoreService, sequelize: Sequelize): Promise { GBLog.verbose(`loadPackage called.`); } - public async unloadPackage (core: IGBCoreService): Promise { + public async unloadPackage(core: IGBCoreService): Promise { GBLog.verbose(`unloadPackage called.`); } - public async unloadBot (min: GBMinInstance): Promise { + public async unloadBot(min: GBMinInstance): Promise { GBLog.verbose(`unloadBot called.`); } - public async onNewSession (min: GBMinInstance, step: GBDialogStep): Promise { + public async onNewSession(min: GBMinInstance, step: GBDialogStep): Promise { 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.`); } } diff --git a/packages/whatsapp.gblib/index.ts b/packages/whatsapp.gblib/index.ts index 66012f383..1582fc88c 100644 --- a/packages/whatsapp.gblib/index.ts +++ b/packages/whatsapp.gblib/index.ts @@ -46,7 +46,9 @@ import { WhatsappDirectLine } from './services/WhatsappDirectLine.js'; export class GBWhatsappPackage implements IGBPackage { public sysPackages: IGBPackage[]; - public async loadBot (min: GBMinInstance): Promise {} + public async loadBot (min: GBMinInstance): Promise { + GBLog.verbose(`loadBot called.`); + } public async getDialogs (min: GBMinInstance) { GBLog.verbose(`getDialogs called.`); diff --git a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts index cdc01a41b..5acb11937 100644 --- a/packages/whatsapp.gblib/services/WhatsappDirectLine.ts +++ b/packages/whatsapp.gblib/services/WhatsappDirectLine.ts @@ -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...`); diff --git a/src/RootData.ts b/src/RootData.ts new file mode 100644 index 000000000..ed5fafd9a --- /dev/null +++ b/src/RootData.ts @@ -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. +} diff --git a/src/app.ts b/src/app.ts index ad92ae79f..804ef5665 100644 --- a/src/app.ts +++ b/src/app.ts @@ -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); diff --git a/tslint.json b/tslint.json index 780c95c87..1b7a40768 100644 --- a/tslint.json +++ b/tslint.json @@ -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,