Skip to content

Commit

Permalink
fix(core): Bot boot logic being fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rodrigo Rodriguez (pragmatismo.io) committed Nov 28, 2018
1 parent c1db8be commit 1761e06
Show file tree
Hide file tree
Showing 23 changed files with 438 additions and 470 deletions.
5 changes: 3 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"trailingComma": "all",
"trailingComma": "none",
"tabWidth": 2,
"printWidth": 80,
"printWidth": 120,
"arrowParens": "avoid",
"semi": true,
"singleQuote": true

}
34 changes: 10 additions & 24 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
"azure-arm-search": "^1.3.0-preview",
"azure-arm-sql": "5.6.0",
"azure-arm-website": "5.7.0",
"bluebird": "^3.5.3",
"body-parser": "1.18.3",
"botbuilder": "^4.1.5",
"botbuilder-ai": "^4.1.5",
Expand Down
10 changes: 5 additions & 5 deletions packages/admin.gbapp/dialogs/AdminDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ export class AdminDialog extends IGBDialog {
);
}

public static async deployPackageCommand(text: string, deployer: GBDeployer) {
public static async deployPackageCommand(min: GBMinInstance, text: string, deployer: GBDeployer) {
const packageName = text.split(' ')[1];
const additionalPath = GBConfigService.get('ADDITIONAL_DEPLOY_PATH');
await deployer.deployPackageFromLocalPath(
UrlJoin(additionalPath, packageName)
await deployer.deployPackageFromLocalPath(min,
UrlJoin(additionalPath, packageName)
);
}
/**
Expand Down Expand Up @@ -119,11 +119,11 @@ export class AdminDialog extends IGBDialog {
await AdminDialog.createFarmCommand(text, deployer);
await step.replaceDialog('/admin', { firstRun: false });
} else if (cmdName === 'deployPackage') {
await AdminDialog.deployPackageCommand(text, deployer);
await AdminDialog.deployPackageCommand(min, text, deployer);
await step.replaceDialog('/admin', { firstRun: false });
} else if (cmdName === 'redeployPackage') {
await AdminDialog.undeployPackageCommand(text, min);
await AdminDialog.deployPackageCommand(text, deployer);
await AdminDialog.deployPackageCommand(min, text, deployer);
await step.replaceDialog('/admin', { firstRun: false });
} else if (cmdName === 'undeployPackage') {
await AdminDialog.undeployPackageCommand(text, min);
Expand Down
12 changes: 12 additions & 0 deletions packages/boot.gbot/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": "1.0.0",
"theme": "default.gbtheme",
"ui": "default.gbui",
"kb": "default.gbkb",
"title": "Default General Bot",
"description": "Default General Bot",
"whoAmIVideo": "TODO.mp4",
"author": "pragmatismo.io",
"license": "AGPL",
"engineName": "guaribas-1.0.0"
}
3 changes: 3 additions & 0 deletions packages/boot.gbot/security.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"groups": [{}]
}
2 changes: 2 additions & 0 deletions packages/boot.gbot/services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
6 changes: 6 additions & 0 deletions packages/boot.gbot/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"enabledAdmin": "true",
"searchScore": ".15",
"nlpScore": ".15",
"nlpVsSearch": ".4"
}
8 changes: 6 additions & 2 deletions packages/core.gbapp/services/GBAPIService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class DialogClass {
this.min = min;
}

public async expectMessage(text: string): Promise<any> {
public async hear(text: string): Promise<any> {
return new Promise((resolve, reject) => {
this.min.dialogs.add(
new WaterfallDialog('/vmExpect', [
Expand All @@ -63,7 +63,11 @@ export class DialogClass {
});
}

public sendMessage(text: string) {
public post(url: string, data) {

}

public talk(text: string) {
this.min.dialogs.add(
new WaterfallDialog('/vmSend', [
async step => {
Expand Down
75 changes: 31 additions & 44 deletions packages/core.gbapp/services/GBConversationalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,15 @@
\*****************************************************************************/

/**
* @fileoverview General Bots server core.
* @fileoverview Conversation handling and external service calls.
*/

'use strict';

const logger = require('../../../src/logger');

import { any } from 'bluebird';
import { MessageFactory } from 'botbuilder';
import { LuisRecognizer } from 'botbuilder-ai';
import { IGBConversationalService } from 'botlib';
import { GBMinInstance } from 'botlib';
import { GBMinInstance, IGBConversationalService } from 'botlib';
import { AzureText } from 'pragmatismo-io-framework';
import { Messages } from '../strings';
import { GBCoreService } from './GBCoreService';
Expand Down Expand Up @@ -70,33 +67,27 @@ export class GBConversationalService implements IGBConversationalService {
msg.value = value;
msg.type = 'event';
msg.name = name;

return step.context.sendActivity(msg);
}
}

public async sendSms(
min: GBMinInstance,
mobile: string,
text: string
): Promise<any> {
return new Promise((resolve: any, reject: any): any => {
const nexmo = new Nexmo({
apiKey: min.instance.smsKey,
apiSecret: min.instance.smsSecret
});
nexmo.message.sendSms(
min.instance.smsServiceNumber,
mobile,
text,
(err, data) => {
public async sendSms(min: GBMinInstance, mobile: string, text: string): Promise<any> {
return new Promise(
(resolve: any, reject: any): any => {
const nexmo = new Nexmo({
apiKey: min.instance.smsKey,
apiSecret: min.instance.smsSecret
});
nexmo.message.sendSms(min.instance.smsServiceNumber, mobile, text, (err, data) => {
if (err) {
reject(err);
} else {
resolve(data);
}
}
);
});
});
}
);
}

public async routeNLP(step: any, min: GBMinInstance, text: string): Promise<boolean> {
Expand All @@ -112,53 +103,49 @@ export class GBConversationalService implements IGBConversationalService {
try {
nlp = await model.recognize(step.context);
} catch (error) {
if (error.statusCode == 404) {
logger.warn ('NLP application still not publish and there are no other options for answering.');
if (error.statusCode === 404) {
logger.warn('NLP application still not publish and there are no other options for answering.');

return Promise.resolve(false);
} else {
const msg = `Error calling NLP server, check if you have a published model and assigned keys on the service. Error: ${
error.statusCode ? error.statusCode : ''
} ${error.message}`;
return Promise.reject(new Error(msg)); }
const msg = `Error calling NLP, check if you have a published model and assigned keys. Error: ${
error.statusCode ? error.statusCode : ''
} ${error.message}`;

return Promise.reject(new Error(msg));
}
}

// Resolves intents returned from LUIS.

const topIntent = LuisRecognizer.topIntent(nlp);
if (topIntent) {
const intent = topIntent;
const entity =
nlp.entities && nlp.entities.length > 0
? nlp.entities[0].entity.toUpperCase()
: null;
const entity = nlp.entities && nlp.entities.length > 0 ? nlp.entities[0].entity.toUpperCase() : null;

if (intent === 'None') {
return Promise.resolve(false);
}

logger.info('NLP called:' + intent + ', ' + entity);
logger.info(`NLP called: ${intent}, ${entity}`);

try {
await step.replace('/' + intent, nlp.entities);
await step.replace(`/${intent}`, nlp.entities);

return Promise.resolve(true);
} catch (error) {
const msg = `Error finding dialog associated to NLP event: ${intent}: ${
error.message
}`;
const msg = `Error finding dialog associated to NLP event: ${intent}: ${error.message}`;

return Promise.reject(new Error(msg));
}
}

return Promise.resolve(false);
}

public async checkLanguage(step, min, text) {
const locale = await AzureText.getLocale(
min.instance.textAnalyticsKey,
min.instance.textAnalyticsEndpoint,
text
);
if (locale != step.context.activity.locale.split('-')[0]) {
const locale = await AzureText.getLocale(min.instance.textAnalyticsKey, min.instance.textAnalyticsEndpoint, text);
if (locale !== step.context.activity.locale.split('-')[0]) {
switch (locale) {
case 'pt':
step.context.activity.locale = 'pt-BR';
Expand Down
Loading

0 comments on commit 1761e06

Please sign in to comment.