Skip to content

Commit

Permalink
fix(all): #123 done.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorodriguez committed Jul 17, 2023
1 parent 7e3ee7d commit 2d1efeb
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/core.gbapp/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import { LanguageDialog } from './dialogs/LanguageDialog.js';
import { SwitchBotDialog } from './dialogs/SwitchBot.js';
import { WelcomeDialog } from './dialogs/WelcomeDialog.js';
import { WhoAmIDialog } from './dialogs/WhoAmIDialog.js';
import { GuaribasChannel, GuaribasInstance, GuaribasLog, GuaribasPackage } from './models/GBModel.js';
import { GuaribasApplications, GuaribasChannel, GuaribasInstance, GuaribasLog, GuaribasPackage } from './models/GBModel.js';

/**
* Package for core.gbapp.
Expand All @@ -53,7 +53,7 @@ export class GBCorePackage implements IGBPackage {
public CurrentEngineName = 'guaribas-1.0.0';

public async loadPackage (core: IGBCoreService, sequelize: Sequelize): Promise<void> {
core.sequelize.addModels([GuaribasInstance, GuaribasPackage, GuaribasChannel, GuaribasLog]);
core.sequelize.addModels([GuaribasInstance, GuaribasPackage, GuaribasChannel, GuaribasLog, GuaribasApplications]);
}

public async getDialogs (min: GBMinInstance) {
Expand Down
23 changes: 22 additions & 1 deletion packages/core.gbapp/services/GBCoreService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import { GBCustomerSatisfactionPackage } from '../../customer-satisfaction.gbapp
import { GBKBPackage } from '../../kb.gbapp/index.js';
import { GBSecurityPackage } from '../../security.gbapp/index.js';
import { GBWhatsappPackage } from '../../whatsapp.gblib/index.js';
import { GuaribasInstance, GuaribasLog } from '../models/GBModel.js';
import { GuaribasApplications, GuaribasInstance, GuaribasLog } from '../models/GBModel.js';
import { GBConfigService } from './GBConfigService.js';
import { GBAzureDeployerPackage } from '../../azuredeployer.gbapp/index.js';
import { GBSharePointPackage } from '../../sharepoint.gblib/index.js';
Expand All @@ -60,6 +60,8 @@ import { GBGoogleChatPackage } from '../../google-chat.gblib/index.js';
import { GBHubSpotPackage } from '../../hubspot.gblib/index.js';
import open from 'open';
import ngrok from 'ngrok';
import Path from 'path';
import { file } from 'googleapis/build/src/apis/file/index.js';

/**
* GBCoreService contains main logic for handling storage services related
Expand Down Expand Up @@ -396,6 +398,25 @@ ENDPOINT_UPDATE=true
return await instance.save();
}

/**
* Loads all bot instances from object storage, if it's formatted.
*/
public async getApplicationsByInstanceId(appPackages, instanceId: number) {
const options = { where: { instanceId: instanceId } };
const apps = await GuaribasApplications.findAll(options);

let matchingAppPackages = [];
await CollectionUtil.asyncForEach(appPackages, async appPackage => {
const filenameOnly = Path.basename(appPackage.name);
const matchedApp = apps.find(app => app.name === filenameOnly || app.name === filenameOnly);
if (matchedApp) {
matchingAppPackages.push(appPackage);
}
});

return matchingAppPackages;
}

/**
* Loads all bot instances from object storage, if it's formatted.
*/
Expand Down
5 changes: 2 additions & 3 deletions packages/core.gbapp/services/GBMinService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -707,8 +707,7 @@ export class GBMinService {
min['scheduleMap'] = {};
min['conversationWelcomed'] = {};
min.packages = sysPackages;
min.appPackages = appPackages;


// NLP Manager.

const manager = new NlpManager({ languages: ['pt'], forceNER: true });
Expand All @@ -726,7 +725,7 @@ export class GBMinService {
});
}
// https://github.com/GeneralBots/BotServer/issues/123
// min.appPackages = core.getPackagesByInstanceId(min.instance.instanceId);
min.appPackages = await this.core['getApplicationsByInstanceId'] (appPackages, min.instance.instanceId);

// Creates a hub of services available in .gbapps.

Expand Down

0 comments on commit 2d1efeb

Please sign in to comment.