Merge pull request #109 from rodrigorodriguez/master
fix(whastapp.gblib): Fix in pro-active messaging.
This commit is contained in:
commit
96bdb4fc35
5 changed files with 22 additions and 28 deletions
|
@ -373,9 +373,7 @@ STORAGE_SYNC=true
|
||||||
GBLog.info(`Loading sys package: ${e.name}...`);
|
GBLog.info(`Loading sys package: ${e.name}...`);
|
||||||
|
|
||||||
const p = Object.create(e.prototype) as IGBPackage;
|
const p = Object.create(e.prototype) as IGBPackage;
|
||||||
if (e.name === 'GBWhatsappPackage') {
|
sysPackages.push(p);
|
||||||
sysPackages.push(p);
|
|
||||||
}
|
|
||||||
p.loadPackage(core, core.sequelize);
|
p.loadPackage(core, core.sequelize);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -111,6 +111,7 @@ export class GBMinService {
|
||||||
bootInstance: IGBInstance,
|
bootInstance: IGBInstance,
|
||||||
server: any,
|
server: any,
|
||||||
appPackages: IGBPackage[],
|
appPackages: IGBPackage[],
|
||||||
|
sysPackages: IGBPackage[],
|
||||||
instances: IGBInstance[],
|
instances: IGBInstance[],
|
||||||
deployer: GBDeployer,
|
deployer: GBDeployer,
|
||||||
proxyAddress: string
|
proxyAddress: string
|
||||||
|
@ -137,7 +138,7 @@ export class GBMinService {
|
||||||
|
|
||||||
// Build bot adapter.
|
// Build bot adapter.
|
||||||
|
|
||||||
const { min, adapter, conversationState } = await this.buildBotAdapter(instance, proxyAddress);
|
const { min, adapter, conversationState } = await this.buildBotAdapter(instance, proxyAddress, sysPackages);
|
||||||
|
|
||||||
// Install default VBA module.
|
// Install default VBA module.
|
||||||
|
|
||||||
|
@ -145,7 +146,7 @@ export class GBMinService {
|
||||||
|
|
||||||
// Call the loadBot context.activity for all packages.
|
// Call the loadBot context.activity for all packages.
|
||||||
|
|
||||||
this.invokeLoadBot(appPackages, min, server);
|
this.invokeLoadBot(appPackages, sysPackages, min, server);
|
||||||
|
|
||||||
// Serves individual URL for each bot conversational interface...
|
// Serves individual URL for each bot conversational interface...
|
||||||
|
|
||||||
|
@ -313,7 +314,7 @@ export class GBMinService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async buildBotAdapter(instance: any, proxyAddress: string) {
|
private async buildBotAdapter(instance: any, proxyAddress: string, sysPackages: IGBPackage[]) {
|
||||||
const adapter = new BotFrameworkAdapter({
|
const adapter = new BotFrameworkAdapter({
|
||||||
appId: instance.marketplaceId,
|
appId: instance.marketplaceId,
|
||||||
appPassword: instance.marketplacePassword
|
appPassword: instance.marketplacePassword
|
||||||
|
@ -341,7 +342,7 @@ export class GBMinService {
|
||||||
min.cbMap = {};
|
min.cbMap = {};
|
||||||
min.scriptMap = {};
|
min.scriptMap = {};
|
||||||
min.sandBoxMap = {};
|
min.sandBoxMap = {};
|
||||||
min.packages = GBServer.globals.sysPackages[0]; // HACK: Whatsapp now.
|
min.packages = sysPackages;
|
||||||
min.userProfile = conversationState.createProperty('userProfile');
|
min.userProfile = conversationState.createProperty('userProfile');
|
||||||
const dialogState = conversationState.createProperty('dialogState');
|
const dialogState = conversationState.createProperty('dialogState');
|
||||||
|
|
||||||
|
@ -352,27 +353,17 @@ export class GBMinService {
|
||||||
return { min, adapter, conversationState };
|
return { min, adapter, conversationState };
|
||||||
}
|
}
|
||||||
|
|
||||||
private invokeLoadBot(appPackages: any[], min: GBMinInstance, server: any) {
|
private invokeLoadBot(appPackages: IGBPackage[], sysPackages: IGBPackage[], min: GBMinInstance, server: any) {
|
||||||
const sysPackages: IGBPackage[] = [];
|
let index = 0;
|
||||||
// NOTE: A semicolon is necessary before this line.
|
sysPackages.forEach(e => {
|
||||||
[
|
e.loadBot(min);
|
||||||
GBCorePackage,
|
if (index === 6) { // TODO: Remove this magic number and use a map.
|
||||||
GBSecurityPackage,
|
|
||||||
GBAdminPackage,
|
|
||||||
GBKBPackage,
|
|
||||||
GBAnalyticsPackage,
|
|
||||||
GBCustomerSatisfactionPackage,
|
|
||||||
GBWhatsappPackage
|
|
||||||
].forEach(sysPackage => {
|
|
||||||
const p = Object.create(sysPackage.prototype) as IGBPackage;
|
|
||||||
p.loadBot(min);
|
|
||||||
sysPackages.push(p);
|
|
||||||
if (sysPackage.name === 'GBWhatsappPackage') {
|
|
||||||
const url = '/instances/:botId/whatsapp';
|
const url = '/instances/:botId/whatsapp';
|
||||||
server.post(url, (req, res) => {
|
server.post(url, (req, res) => {
|
||||||
(p as any).channel.received(req, res);
|
(e as any).channel.received(req, res);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
index++;
|
||||||
}, this);
|
}, this);
|
||||||
|
|
||||||
appPackages.forEach(p => {
|
appPackages.forEach(p => {
|
||||||
|
|
|
@ -62,6 +62,10 @@ export class GBWhatsappPackage implements IGBPackage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getChannel() {
|
||||||
|
return this.channel;
|
||||||
|
}
|
||||||
|
|
||||||
public getDialogs(min: GBMinInstance) {
|
public getDialogs(min: GBMinInstance) {
|
||||||
GBLog.verbose(`getDialogs called.`);
|
GBLog.verbose(`getDialogs called.`);
|
||||||
}
|
}
|
||||||
|
|
|
@ -222,7 +222,8 @@ export class WhatsappDirectLine extends GBService {
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = request.post(options);
|
// tslint:disable-next-line: await-promise
|
||||||
|
const result = await request.post(options);
|
||||||
GBLog.info(result);
|
GBLog.info(result);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
GBLog.error(`Error sending message to Whatsapp provider ${error.message}`);
|
GBLog.error(`Error sending message to Whatsapp provider ${error.message}`);
|
||||||
|
|
|
@ -57,7 +57,7 @@ const appPackages: IGBPackage[] = [];
|
||||||
export class RootData {
|
export class RootData {
|
||||||
public publicAddress: string;
|
public publicAddress: string;
|
||||||
public server: any;
|
public server: any;
|
||||||
sysPackages: any;
|
public sysPackages: any[];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -123,7 +123,7 @@ export class GBServer {
|
||||||
// Deploys system and user packages.
|
// Deploys system and user packages.
|
||||||
|
|
||||||
GBLog.info(`Deploying packages...`);
|
GBLog.info(`Deploying packages...`);
|
||||||
GBServer.globals.sysPackages = core.loadSysPackages(core);
|
const sysPackages = core.loadSysPackages(core);
|
||||||
await core.checkStorage(azureDeployer);
|
await core.checkStorage(azureDeployer);
|
||||||
await deployer.deployPackages(core, server, appPackages);
|
await deployer.deployPackages(core, server, appPackages);
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ export class GBServer {
|
||||||
// Builds minimal service infrastructure.
|
// Builds minimal service infrastructure.
|
||||||
|
|
||||||
const minService: GBMinService = new GBMinService(core, conversationalService, adminService, deployer);
|
const minService: GBMinService = new GBMinService(core, conversationalService, adminService, deployer);
|
||||||
await minService.buildMin(bootInstance, server, appPackages, instances,
|
await minService.buildMin(bootInstance, server, appPackages, sysPackages, instances,
|
||||||
deployer, GBServer.globals.publicAddress);
|
deployer, GBServer.globals.publicAddress);
|
||||||
|
|
||||||
// Deployment of local applications for the first time.
|
// Deployment of local applications for the first time.
|
||||||
|
|
Loading…
Add table
Reference in a new issue