diff --git a/packages/basic.gblib/services/DialogKeywords.ts b/packages/basic.gblib/services/DialogKeywords.ts index 1ee49ea2b..267416177 100644 --- a/packages/basic.gblib/services/DialogKeywords.ts +++ b/packages/basic.gblib/services/DialogKeywords.ts @@ -782,7 +782,7 @@ export class DialogKeywords { */ public async getConfig({ pid, name }) { let { min, user, params } = await DialogKeywords.getProcessInfo(pid); - return min.core.getParam(min.instance, name, null); + return min.core.getParam(min.instance, name, null, false); } /** diff --git a/packages/basic.gblib/services/GBVMService.ts b/packages/basic.gblib/services/GBVMService.ts index c70be6204..6e339992e 100644 --- a/packages/basic.gblib/services/GBVMService.ts +++ b/packages/basic.gblib/services/GBVMService.ts @@ -221,6 +221,72 @@ export class GBVMService extends GBService { } } + public static async loadConnections(min) { + + + // Loads storage custom connections. + const path = DialogKeywords.getGBAIPath(min.botId, null); + const filePath = Path.join('work', path, 'connections.json'); + let connections = []; + if (Fs.existsSync(filePath)) { + connections = JSON.parse(Fs.readFileSync(filePath, 'utf8')); + } + + connections.forEach(async con => { + const connectionName = con['name']; + + const dialect = con['storageDriver']; + const host = con['storageServer']; + const port = con['storagePort']; + const storageName = con['storageName']; + const username = con['storageUsername']; + const password = con['storagePassword']; + + const logging: boolean | Function = + GBConfigService.get('STORAGE_LOGGING') === 'true' + ? (str: string): void => { + GBLogEx.info(min, str); + } + : false; + + const encrypt: boolean = GBConfigService.get('STORAGE_ENCRYPT') === 'true'; + const acquire = parseInt(GBConfigService.get('STORAGE_ACQUIRE_TIMEOUT')); + const sequelizeOptions = { + define: { + charset: 'utf8', + collate: 'utf8_general_ci', + freezeTableName: true, + timestamps: false + }, + host: host, + port: port, + logging: logging as boolean, + dialect: dialect, + quoteIdentifiers: false, // set case-insensitive + dialectOptions: { + options: { + trustServerCertificate: true, + encrypt: encrypt, + requestTimeout: 120 * 1000 + } + }, + pool: { + max: 5, + min: 0, + idle: 10000, + evict: 10000, + acquire: acquire + } + }; + + if (!min[connectionName]) { + GBLogEx.info(min, `Loading custom connection ${connectionName}...`); + min[connectionName] = new Sequelize(storageName, username, password, sequelizeOptions); + min[connectionName]['gbconnection'] = con; + } + }); + } + private syncStorageFromTABLE(folder: string, filename: string, min: GBMinInstance, mainName: string) { const tablesFile = urlJoin(folder, `${filename}.tables.json`); let sync = false; @@ -282,68 +348,6 @@ export class GBVMService extends GBService { const associations = []; - // Loads storage custom connections. - const path = DialogKeywords.getGBAIPath(min.botId, null); - const filePath = Path.join('work', path, 'connections.json'); - let connections = []; - if (Fs.existsSync(filePath)) { - connections = JSON.parse(Fs.readFileSync(filePath, 'utf8')); - } - - connections.forEach(async con => { - const connectionName = con['name']; - - const dialect = con['storageDriver']; - const host = con['storageServer']; - const port = con['storagePort']; - const storageName = con['storageName']; - const username = con['storageUsername']; - const password = con['storagePassword']; - - const logging: boolean | Function = - GBConfigService.get('STORAGE_LOGGING') === 'true' - ? (str: string): void => { - GBLogEx.info(min, str); - } - : false; - - const encrypt: boolean = GBConfigService.get('STORAGE_ENCRYPT') === 'true'; - const acquire = parseInt(GBConfigService.get('STORAGE_ACQUIRE_TIMEOUT')); - const sequelizeOptions = { - define: { - charset: 'utf8', - collate: 'utf8_general_ci', - freezeTableName: true, - timestamps: false - }, - host: host, - port: port, - logging: logging as boolean, - dialect: dialect, - quoteIdentifiers: false, // set case-insensitive - dialectOptions: { - options: { - trustServerCertificate: true, - encrypt: encrypt, - requestTimeout: 120 * 1000 - } - }, - pool: { - max: 5, - min: 0, - idle: 10000, - evict: 10000, - acquire: acquire - } - }; - - if (!min[connectionName]) { - GBLogEx.info(min, `Loading custom connection ${connectionName}...`); - min[connectionName] = new Sequelize(storageName, username, password, sequelizeOptions); - min[connectionName]['gbconnection'] = con; - } - }); - const shouldSync = min.core.getParam(min.instance, 'Synchronize Database', false); tableDef.forEach(async t => { @@ -1144,7 +1148,6 @@ export class GBVMService extends GBService { }); const s = new VMScript(code, { filename: scriptPath }); result = vm1.run(s); - }); })(); } else { diff --git a/packages/core.gbapp/services/GBCoreService.ts b/packages/core.gbapp/services/GBCoreService.ts index bdc02c760..cf3cf2ca3 100644 --- a/packages/core.gbapp/services/GBCoreService.ts +++ b/packages/core.gbapp/services/GBCoreService.ts @@ -724,7 +724,7 @@ ENDPOINT_UPDATE=true * @param name Name of param to get from instance. * @param defaultValue Value returned when no param is defined in Config.xlsx. */ - public getParam(instance: IGBInstance, name: string, defaultValue?: T): any { + public getParam(instance: IGBInstance, name: string, defaultValue?: T, platform=false): any { let value = null; let params; name = name.trim(); @@ -774,6 +774,10 @@ ENDPOINT_UPDATE=true value = null; } + if (!value && platform){ + value = process.env[name.replace(/ /g, "_").toUpperCase()]; + } + if (value && typeof defaultValue === 'boolean') { return new Boolean(value ? value.toString().toLowerCase() === 'true' : defaultValue).valueOf(); } diff --git a/packages/core.gbapp/services/GBDeployer.ts b/packages/core.gbapp/services/GBDeployer.ts index 03aa73620..9245f8a09 100644 --- a/packages/core.gbapp/services/GBDeployer.ts +++ b/packages/core.gbapp/services/GBDeployer.ts @@ -447,7 +447,7 @@ export class GBDeployer implements IGBDeployer { rows.shift(); } } else if (Fs.existsSync(csv)) { - await workbook.csv.readFile(filePath); + await workbook.csv.readFile(csv); let worksheet = workbook.worksheets[0]; // Assuming the CSV file has only one sheet rows = worksheet.getSheetValues(); @@ -636,12 +636,23 @@ export class GBDeployer implements IGBDeployer { const connectionName = t.replace(strFind, ''); let con = {}; con['name'] = connectionName; - con['storageServer'] = min.core.getParam(min.instance, `${connectionName} Server`, null); - con['storageUsername'] = min.core.getParam(min.instance, `${connectionName} Username`, null); - con['storageName'] = min.core.getParam(min.instance, `${connectionName} Name`, null); - con['storagePort'] = min.core.getParam(min.instance, `${connectionName} Port`, null); - con['storagePassword'] = min.core.getParam(min.instance, `${connectionName} Password`, null); con['storageDriver'] = min.core.getParam(min.instance, `${connectionName} Driver`, null); + const storageName = min.core.getParam(min.instance, `${connectionName} Name`, null); + + let file = min.core.getParam(min.instance, `${connectionName} File`, null); + + if (storageName) { + con['storageName'] = storageName; + con['storageServer'] = min.core.getParam(min.instance, `${connectionName} Server`, null); + con['storageUsername'] = min.core.getParam(min.instance, `${connectionName} Username`, null); + con['storagePort'] = min.core.getParam(min.instance, `${connectionName} Port`, null); + con['storagePassword'] = min.core.getParam(min.instance, `${connectionName} Password`, null); + } else if (file) { + const path = DialogKeywords.getGBAIPath(min.botId, 'gbdata'); + con['storageFile'] = Path.join(GBConfigService.get('STORAGE_LIBRARY'), path, file); + } else { + GBLogEx.debug(min, `No storage information found for ${connectionName}, missing storage name or file.`); + } connections.push(con); }); diff --git a/packages/core.gbapp/services/GBMinService.ts b/packages/core.gbapp/services/GBMinService.ts index 35d3909f7..f6cc73a78 100644 --- a/packages/core.gbapp/services/GBMinService.ts +++ b/packages/core.gbapp/services/GBMinService.ts @@ -377,9 +377,9 @@ export class GBMinService { } res.end(); }); + GBLog.verbose(`GeneralBots(${instance.engineName}) listening on: ${url}.`); - // Generates MS Teams manifest. const manifest = `${instance.botId}-Teams.zip`; @@ -390,7 +390,9 @@ export class GBMinService { Fs.writeFileSync(packageTeams, data); } - // Serves individual URL for each bot user interface. + await GBVMService.loadConnections(min); + + // Serves individual URL for each bot user interface. if (process.env.DISABLE_WEB !== 'true') { const uiUrl = `/${instance.botId}`; diff --git a/packages/kb.gbapp/services/KBService.ts b/packages/kb.gbapp/services/KBService.ts index 76c346aa6..34e11b49f 100644 --- a/packages/kb.gbapp/services/KBService.ts +++ b/packages/kb.gbapp/services/KBService.ts @@ -1061,7 +1061,7 @@ export class KBService implements IGBKBService { let logo = await this.getLogoByPage(min, page); if (logo) { path = DialogKeywords.getGBAIPath(min.botId); - const logoPath = Path.join(process.env.PWD, 'work', path, 'cache'); + const baseUrl = page.url().split('/').slice(0, 3).join('/'); logo = logo.startsWith('https') ? logo : urlJoin(baseUrl, logo); diff --git a/packages/llm.gblib/services/ChatServices.ts b/packages/llm.gblib/services/ChatServices.ts index 1a2e3f2fa..53c51d0bd 100644 --- a/packages/llm.gblib/services/ChatServices.ts +++ b/packages/llm.gblib/services/ChatServices.ts @@ -294,28 +294,29 @@ export class ChatServices { let model; - const azureOpenAIKey = await min.core.getParam(min.instance, 'Azure Open AI Key', null); - const azureOpenAIGPTModel = await min.core.getParam(min.instance, 'Azure Open AI GPT Model', null); - const azureOpenAIVersion = await min.core.getParam(min.instance, 'Azure Open AI Version', null); - const azureOpenAIApiInstanceName = await min.core.getParam(min.instance, 'Azure Open AI Instance', null); + const azureOpenAIKey = await (min.core as any)['getParam'](min.instance, 'Azure Open AI Key', null, true); + const azureOpenAIGPTModel = await (min.core as any)['getParam']( + min.instance, + 'Azure Open AI GPT Model', + null, + true + ); + const azureOpenAIVersion = await (min.core as any)['getParam'](min.instance, 'Azure Open AI Version', null, true); + const azureOpenAIApiInstanceName = await (min.core as any)['getParam']( + min.instance, + 'Azure Open AI Instance', + null, + true + ); - if (azureOpenAIKey) { - model = new ChatOpenAI({ - azureOpenAIApiKey: azureOpenAIKey, - azureOpenAIApiInstanceName: azureOpenAIApiInstanceName, - azureOpenAIApiDeploymentName: azureOpenAIGPTModel, - azureOpenAIApiVersion: azureOpenAIVersion, - temperature: 0, - callbacks: [logHandler] - }); - } else { - model = new ChatOpenAI({ - openAIApiKey: process.env.OPENAI_API_KEY, - modelName: 'gpt-3.5-turbo-0125', - temperature: 0, - callbacks: [logHandler] - }); - } + model = new ChatOpenAI({ + azureOpenAIApiKey: azureOpenAIKey, + azureOpenAIApiInstanceName: azureOpenAIApiInstanceName, + azureOpenAIApiDeploymentName: azureOpenAIGPTModel, + azureOpenAIApiVersion: azureOpenAIVersion, + temperature: 0, + callbacks: [logHandler] + }); let tools = await ChatServices.getTools(min); let toolsAsText = ChatServices.getToolsAsText(tools); @@ -476,21 +477,24 @@ export class ChatServices { }); } else if (LLMMode === 'sql') { const con = min[`llm`]['gbconnection']; - + const dialect = con['storageDriver']; - const host = con['storageServer']; - const port = con['storagePort']; - const storageName = con['storageName']; - const username = con['storageUsername']; - const password = con['storagePassword']; let dataSource; if (dialect === 'sqlite') { dataSource = new DataSource({ type: 'sqlite', - database: storageName + database: con['storageFile'], + synchronize: false, + logging: true }); } else { + const host = con['storageServer']; + const port = con['storagePort']; + const storageName = con['storageName']; + const username = con['storageUsername']; + const password = con['storagePassword']; + dataSource = new DataSource({ type: dialect as any, host: host, diff --git a/templates/instagram.gbai/instagram.gbdialog/poster.bas b/templates/instagram.gbai/instagram.gbdialog/poster.bas deleted file mode 100644 index 7bed7e8e8..000000000 --- a/templates/instagram.gbai/instagram.gbdialog/poster.bas +++ /dev/null @@ -1,7 +0,0 @@ -REM SET SCHEDULE "* 8 * * * *" -user = “user@domain.com” -pass= "*************" -o =get "https://oooooooooo" -caption = REWRITE "Crie um post sobre hotmart e seus produtos, no estilo dica do dia incluíndo 10 hashtags, estilo instagram o texto! Importante, retorne só a saída de texto pronta" -image = GET IMAGE caption -POST username, password, image, caption diff --git a/templates/marketing.gbai/marketing.gbdialog/poster.bas b/templates/marketing.gbai/marketing.gbdialog/poster.bas new file mode 100644 index 000000000..d85f64af7 --- /dev/null +++ b/templates/marketing.gbai/marketing.gbdialog/poster.bas @@ -0,0 +1,20 @@ +REM SET SCHEDULE "* 8 * * * *" + +user = "user@domain.com" +pass = "*************" +o = get "https://oooooooooo" + +# Criar a legenda para o post +caption = REWRITE "Crie um post sobre Hotmart e seus produtos, no estilo dica do dia, incluindo 10 hashtags, estilo Instagram o texto! Importante, retorne só a saída de texto pronta" + +# Obter uma imagem relacionada ao conteúdo +image = GET IMAGE caption + +# Postar no Instagram +POST TO INSTAGRAM username, password, image, caption + +# Postar no Facebook +POST TO FACEBOOK username, password, image, caption + +# Postar no Twitter +TWEET username, password, image, caption