Skip to content

Commit

Permalink
fix(whatsapp.lib): Enabling Whatsapp.
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigorodriguez committed May 15, 2019
1 parent bc9c588 commit 85249e5
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,7 @@ export class AzureDeployerService implements IGBInstallationDeployer {
// CHECK
if (!JSON.parse(res.bodyAsText).id) {
return false;
}
else {
} else {
return true;
}
}
Expand Down Expand Up @@ -292,7 +291,6 @@ export class AzureDeployerService implements IGBInstallationDeployer {
GBLog.info(`Bot proxy updated at: ${endpoint}.`);
}


public async openStorageFirewall(groupName, serverName) {
const username = GBConfigService.get('CLOUD_USERNAME');
const password = GBConfigService.get('CLOUD_PASSWORD');
Expand Down
4 changes: 2 additions & 2 deletions packages/core.gbapp/services/GBCoreService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,8 +347,8 @@ STORAGE_SYNC=true
GBCorePackage,
GBSecurityPackage,
GBKBPackage,
GBCustomerSatisfactionPackage
// GBWhatsappPackage
GBCustomerSatisfactionPackage,
GBWhatsappPackage
].forEach(e => {
GBLog.info(`Loading sys package: ${e.name}...`);
const p = Object.create(e.prototype) as IGBPackage;
Expand Down
18 changes: 8 additions & 10 deletions packages/core.gbapp/services/GBDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const graph = require('@microsoft/microsoft-graph-client');
import { GBError, GBLog, GBMinInstance, IGBCoreService, IGBInstance, IGBPackage } from 'botlib';
import { AzureSearch } from 'pragmatismo-io-framework';
import { GBServer } from '../../../src/app';
import { GuaribasPackage } from '../models/GBModel';
import { GuaribasPackage, GuaribasInstance } from '../models/GBModel';
import { GBAdminService } from './../../admin.gbapp/services/GBAdminService';
import { AzureDeployerService } from './../../azuredeployer.gbapp/services/AzureDeployerService';
import { KBService } from './../../kb.gbapp/services/KBService';
Expand Down Expand Up @@ -164,7 +164,7 @@ export class GBDeployer {
* Deploys a bot to the storage.
*/

public async deployBot(localPath: string, proxyAddress: string): Promise<IGBInstance> {
public async deployBot(localPath: string, proxyAddress: string): Promise<void> {
const packageName = Path.basename(localPath);

const service = new AzureDeployerService(this);
Expand All @@ -186,8 +186,7 @@ export class GBDeployer {
''
);

}
else {
} else {

instance = await service.internalDeployBot(
instance,
Expand All @@ -205,8 +204,7 @@ export class GBDeployer {
subscriptionId
);
}
return instance;

await this.core.saveInstance(instance);
}

public async deployPackageToStorage(instanceId: number, packageName: string): Promise<GuaribasPackage> {
Expand Down Expand Up @@ -234,12 +232,12 @@ export class GBDeployer {

switch (packageType) {
case '.gbot':
return this.deployBot(localPath, min.proxyAddress);
await this.deployBot(localPath, min.proxyAddress);

case '.gbkb':
const service = new KBService(this.core.sequelize);

return service.deployKb(this.core, this, localPath);
await service.deployKb(this.core, this, localPath);

case '.gbdialog':
const vm = new GBVMService();
Expand Down Expand Up @@ -348,10 +346,10 @@ export class GBDeployer {

// Deploys all .gbot files first.

botPackages.forEach(e => {
botPackages.forEach(async (e) => {
if (e !== 'packages\\boot.gbot') {
GBLog.info(`Deploying bot: ${e}...`);
_this.deployBot(e, GBServer.globals.proxyAddress);
await _this.deployBot(e, GBServer.globals.proxyAddress);
GBLog.info(`Bot: ${e} deployed...`);
}
});
Expand Down
8 changes: 4 additions & 4 deletions packages/core.gbapp/services/GBMinService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,8 +235,8 @@ export class GBMinService {
botId = bootInstance.botId;
}
const instance = await this.core.loadInstance(botId);
if (instance !== undefined) {
const speechToken = await this.getSTSToken(instance);
if (instance !== null) {
const speechToken = instance.speechKey != null ? await this.getSTSToken(instance) : null;
let theme = instance.theme;
if (theme !== undefined) {
theme = 'default.gbtheme';
Expand Down Expand Up @@ -355,8 +355,8 @@ export class GBMinService {
GBAdminPackage,
GBKBPackage,
GBAnalyticsPackage,
GBCustomerSatisfactionPackage
// DISABLED: GBWhatsappPackage
GBCustomerSatisfactionPackage,
GBWhatsappPackage
].forEach(sysPackage => {
const p = Object.create(sysPackage.prototype) as IGBPackage;
p.loadBot(min);
Expand Down
5 changes: 3 additions & 2 deletions packages/whatsapp.gblib/services/WhatsappDirectLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const Swagger = require('swagger-client');
const rp = require('request-promise');
import { GBLog, GBService } from 'botlib';
import * as request from 'request-promise-native';
import { GBServer } from '../../../src/app';

/**
* Support for Whatsapp.
Expand Down Expand Up @@ -57,7 +58,7 @@ export class WhatsappDirectLine extends GBService {
url: urlJoin(this.whatsappServiceUrl, 'webhook'),
qs: {
token: this.whatsappServiceKey,
webhookUrl: `${this.whatsappServiceWebhookUrl}/instances/${this.botId}/whatsapp`,
webhookUrl: `${GBServer.globals.proxyAddress}/instances/${this.botId}/whatsapp`,
set: true
},
headers: {
Expand Down Expand Up @@ -150,7 +151,7 @@ export class WhatsappDirectLine extends GBService {
.then(activities => {
this.printMessages(activities, conversationId, from, fromName);
});
}, this.pollInterval);
}, this.pollInterval);
}

public printMessages(activities, conversationId, from, fromName) {
Expand Down

0 comments on commit 85249e5

Please sign in to comment.