fix(code): Improvements on CODE_OF_CONDUCT and prettify.

This commit is contained in:
Rodrigo Rodriguez (pragmatismo.io) 2018-11-17 08:52:16 -02:00
parent 518aa5c6b3
commit e430532e66
4 changed files with 48 additions and 49 deletions

View file

@ -1,4 +0,0 @@
{
"typescript.tsdk": "./node_modules/typescript/lib",
}

View file

@ -22,6 +22,7 @@ Examples of unacceptable behavior by participants include:
* Public or private harassment * Public or private harassment
* Publishing others' private information, such as a physical or electronic address, without explicit permission * Publishing others' private information, such as a physical or electronic address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a professional setting * Other conduct which could reasonably be considered inappropriate in a professional setting
* Call a person other name than that declared by the person
## Our Responsibilities ## Our Responsibilities
@ -35,7 +36,7 @@ This Code of Conduct applies both within project spaces and in public spaces whe
## Enforcement ## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at security@pragmatismo.io. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the Pragmatismo.io security team at security@pragmatismo.io. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.

View file

@ -227,7 +227,7 @@ export class GBDeployer {
}) })
.done(function(result) { .done(function(result) {
if (botPackages.length === 0) { if (botPackages.length === 0) {
logger.warn( logger.info(
'No external packages to load, please use ADDITIONAL_DEPLOY_PATH to point to a .gbai package folder.' 'No external packages to load, please use ADDITIONAL_DEPLOY_PATH to point to a .gbai package folder.'
); );
} else { } else {

View file

@ -46,17 +46,17 @@ const AuthenticationContext = require('adal-node').AuthenticationContext;
import { import {
AutoSaveStateMiddleware, AutoSaveStateMiddleware,
BotFrameworkAdapter, BotFrameworkAdapter,
BotStateSet,
ConversationState, ConversationState,
MemoryStorage, MemoryStorage,
UserState UserState
} from 'botbuilder'; } from 'botbuilder';
import { GBMinInstance, IGBPackage } from 'botlib';
import { import {
GBMinInstance,
IGBAdminService, IGBAdminService,
IGBConversationalService, IGBConversationalService,
IGBCoreService IGBCoreService,
IGBPackage
} from 'botlib'; } from 'botlib';
import { GBAnalyticsPackage } from '../../analytics.gblib'; import { GBAnalyticsPackage } from '../../analytics.gblib';
import { GBCorePackage } from '../../core.gbapp'; import { GBCorePackage } from '../../core.gbapp';
@ -88,7 +88,7 @@ export class GBMinService {
core: IGBCoreService, core: IGBCoreService,
conversationalService: IGBConversationalService, conversationalService: IGBConversationalService,
adminService: IGBAdminService, adminService: IGBAdminService,
deployer: GBDeployer deployer: GBDeployer,
) { ) {
this.core = core; this.core = core;
this.conversationalService = conversationalService; this.conversationalService = conversationalService;
@ -110,14 +110,14 @@ export class GBMinService {
public async buildMin( public async buildMin(
server: any, server: any,
appPackages: IGBPackage[], appPackages: IGBPackage[],
instances: GuaribasInstance[] instances: GuaribasInstance[],
): Promise<GBMinInstance> { ): Promise<GBMinInstance> {
// Serves default UI on root address '/'. // Serves default UI on root address '/'.
const uiPackage = 'default.gbui'; const uiPackage = 'default.gbui';
server.use( server.use(
'/', '/',
express.static(UrlJoin(GBDeployer.deployFolder, uiPackage, 'build')) express.static(UrlJoin(GBDeployer.deployFolder, uiPackage, 'build')),
); );
Promise.all( Promise.all(
@ -152,8 +152,8 @@ export class GBMinService {
speechToken: speechToken, speechToken: speechToken,
conversationId: webchatToken.conversationId, conversationId: webchatToken.conversationId,
authenticatorTenant: instance.authenticatorTenant, authenticatorTenant: instance.authenticatorTenant,
authenticatorClientId: instance.authenticatorClientId authenticatorClientId: instance.authenticatorClientId,
}) }),
); );
} else { } else {
const error = `Instance not found: ${botId}.`; const error = `Instance not found: ${botId}.`;
@ -166,7 +166,7 @@ export class GBMinService {
// Build bot adapter. // Build bot adapter.
const { min, adapter, conversationState } = await this.buildBotAdapter( const { min, adapter, conversationState } = await this.buildBotAdapter(
instance instance,
); );
// Call the loadBot context.activity for all packages. // Call the loadBot context.activity for all packages.
@ -184,11 +184,11 @@ export class GBMinService {
conversationState, conversationState,
min, min,
instance, instance,
appPackages appPackages,
); );
}); });
logger.info( logger.info(
`GeneralBots(${instance.engineName}) listening on: ${url}.` `GeneralBots(${instance.engineName}) listening on: ${url}.`,
); );
// Serves individual URL for each bot user interface. // Serves individual URL for each bot user interface.
@ -196,12 +196,12 @@ export class GBMinService {
const uiUrl = `/${instance.botId}`; const uiUrl = `/${instance.botId}`;
server.use( server.use(
uiUrl, uiUrl,
express.static(UrlJoin(GBDeployer.deployFolder, uiPackage, 'build')) express.static(UrlJoin(GBDeployer.deployFolder, uiPackage, 'build')),
); );
logger.info(`Bot UI ${uiPackage} accessible at: ${uiUrl}.`); logger.info(`Bot UI ${uiPackage} accessible at: ${uiUrl}.`);
const state = `${instance.instanceId}${Math.floor( const state = `${instance.instanceId}${Math.floor(
Math.random() * 1000000000 Math.random() * 1000000000,
)}`; )}`;
// Clients get redirected here in order to create an OAuth authorize url and redirect them to AAD. // Clients get redirected here in order to create an OAuth authorize url and redirect them to AAD.
@ -211,7 +211,7 @@ export class GBMinService {
let authorizationUrl = UrlJoin( let authorizationUrl = UrlJoin(
min.instance.authenticatorAuthorityHostUrl, min.instance.authenticatorAuthorityHostUrl,
min.instance.authenticatorTenant, min.instance.authenticatorTenant,
'/oauth2/authorize' '/oauth2/authorize',
); );
authorizationUrl = `${authorizationUrl}?response_type=code&client_id=${ authorizationUrl = `${authorizationUrl}?response_type=code&client_id=${
min.instance.authenticatorClientId min.instance.authenticatorClientId
@ -229,10 +229,10 @@ export class GBMinService {
server.get(`/${min.instance.botId}/token`, async (req, res) => { server.get(`/${min.instance.botId}/token`, async (req, res) => {
const state = await min.adminService.getValue( const state = await min.adminService.getValue(
min.instance.instanceId, min.instance.instanceId,
'AntiCSRFAttackState' 'AntiCSRFAttackState',
); );
if (req.query.state != state) { if (req.query.state !== state) {
const msg = const msg =
'WARNING: state field was not provided as anti-CSRF token'; 'WARNING: state field was not provided as anti-CSRF token';
logger.error(msg); logger.error(msg);
@ -242,8 +242,8 @@ export class GBMinService {
const authenticationContext = new AuthenticationContext( const authenticationContext = new AuthenticationContext(
UrlJoin( UrlJoin(
min.instance.authenticatorAuthorityHostUrl, min.instance.authenticatorAuthorityHostUrl,
min.instance.authenticatorTenant min.instance.authenticatorTenant,
) ),
); );
const resource = 'https://graph.microsoft.com'; const resource = 'https://graph.microsoft.com';
@ -263,27 +263,27 @@ export class GBMinService {
await this.adminService.setValue( await this.adminService.setValue(
instance.instanceId, instance.instanceId,
'refreshToken', 'refreshToken',
token.refreshToken token.refreshToken,
); );
await this.adminService.setValue( await this.adminService.setValue(
instance.instanceId, instance.instanceId,
'accessToken', 'accessToken',
token.accessToken token.accessToken,
); );
await this.adminService.setValue( await this.adminService.setValue(
instance.instanceId, instance.instanceId,
'expiresOn', 'expiresOn',
token.expiresOn.toString() token.expiresOn.toString(),
); );
await this.adminService.setValue( await this.adminService.setValue(
instance.instanceId, instance.instanceId,
'AntiCSRFAttackState', 'AntiCSRFAttackState',
null null,
); );
res.redirect(min.instance.botEndpoint); res.redirect(min.instance.botEndpoint);
} }
} },
); );
}); });
@ -301,7 +301,7 @@ export class GBMinService {
// } // }
// ) // )
// next() // next()
}) }),
); );
} }
@ -316,15 +316,17 @@ export class GBMinService {
url: 'https://directline.botframework.com/v3/directline/tokens/generate', url: 'https://directline.botframework.com/v3/directline/tokens/generate',
method: 'POST', method: 'POST',
headers: { headers: {
Authorization: `Bearer ${instance.webchatKey}` Authorization: `Bearer ${instance.webchatKey}`,
} },
}; };
try { try {
const json = await request(options); const json = await request(options);
return Promise.resolve(JSON.parse(json)); return Promise.resolve(JSON.parse(json));
} catch (error) { } catch (error) {
const msg = `[botId:${instance.botId}] Error calling Direct Line client, verify Bot endpoint on the cloud. Error is: ${error}.`; const msg = `[botId:${
instance.botId
}] Error calling Direct Line client, verify Bot endpoint on the cloud. Error is: ${error}.`;
return Promise.reject(new Error(msg)); return Promise.reject(new Error(msg));
} }
} }
@ -342,8 +344,8 @@ export class GBMinService {
url: 'https://westus.api.cognitive.microsoft.com/sts/v1.0/issueToken', url: 'https://westus.api.cognitive.microsoft.com/sts/v1.0/issueToken',
method: 'POST', method: 'POST',
headers: { headers: {
'Ocp-Apim-Subscription-Key': instance.speechKey 'Ocp-Apim-Subscription-Key': instance.speechKey,
} },
}; };
try { try {
@ -357,7 +359,7 @@ export class GBMinService {
private async buildBotAdapter(instance: any) { private async buildBotAdapter(instance: any) {
const adapter = new BotFrameworkAdapter({ const adapter = new BotFrameworkAdapter({
appId: instance.marketplaceId, appId: instance.marketplaceId,
appPassword: instance.marketplacePassword appPassword: instance.marketplacePassword,
}); });
const storage = new MemoryStorage(); const storage = new MemoryStorage();
@ -393,7 +395,7 @@ export class GBMinService {
GBKBPackage, GBKBPackage,
GBAnalyticsPackage, GBAnalyticsPackage,
GBCustomerSatisfactionPackage, GBCustomerSatisfactionPackage,
GBWhatsappPackage GBWhatsappPackage,
].forEach(sysPackage => { ].forEach(sysPackage => {
const p = Object.create(sysPackage.prototype) as IGBPackage; const p = Object.create(sysPackage.prototype) as IGBPackage;
p.loadBot(min); p.loadBot(min);
@ -404,12 +406,12 @@ export class GBMinService {
p.channel.received(req, res); p.channel.received(req, res);
}); });
} }
}, this); }, this);
appPackages.forEach(e => { appPackages.forEach(e => {
e.sysPackages = sysPackages; e.sysPackages = sysPackages;
e.loadBot(min); e.loadBot(min);
}, this); }, this);
} }
/** /**
@ -422,7 +424,7 @@ export class GBMinService {
conversationState: ConversationState, conversationState: ConversationState,
min: any, min: any,
instance: any, instance: any,
appPackages: any[] appPackages: any[],
) { ) {
return adapter.processActivity(req, res, async context => { return adapter.processActivity(req, res, async context => {
const state = conversationState.get(context); const state = conversationState.get(context);
@ -436,8 +438,8 @@ export class GBMinService {
await min.conversationalService.sendEvent(step, 'loadInstance', { await min.conversationalService.sendEvent(step, 'loadInstance', {
instanceId: instance.instanceId, instanceId: instance.instanceId,
botId: instance.botId, botId: instance.botId,
theme: instance.theme ? instance.theme : 'default.gbtheme' , theme: instance.theme ? instance.theme : 'default.gbtheme',
secret: instance.webchatKey secret: instance.webchatKey,
}); });
user.loaded = true; user.loaded = true;
user.subjects = []; user.subjects = [];
@ -447,7 +449,7 @@ export class GBMinService {
logger.info( logger.info(
`User>: ${context.activity.text} (${context.activity.type}, ${ `User>: ${context.activity.text} (${context.activity.type}, ${
context.activity.name context.activity.name
}, ${context.activity.channelId}, {context.activity.value})` }, ${context.activity.channelId}, {context.activity.value})`,
); );
if ( if (
context.activity.type === 'conversationUpdate' && context.activity.type === 'conversationUpdate' &&
@ -476,7 +478,7 @@ export class GBMinService {
// Checks for /menu JSON signature. // Checks for /menu JSON signature.
} else if (context.activity.text.startsWith('{"title"')) { } else if (context.activity.text.startsWith('{"title"')) {
await step.beginDialog('/menu', { await step.beginDialog('/menu', {
data: JSON.parse(context.activity.text) data: JSON.parse(context.activity.text),
}); });
// Otherwise, continue to the active dialog in the stack. // Otherwise, continue to the active dialog in the stack.
@ -485,7 +487,7 @@ export class GBMinService {
await step.continueDialog(); await step.continueDialog();
} else { } else {
await step.beginDialog('/answer', { await step.beginDialog('/answer', {
query: context.activity.text query: context.activity.text,
}); });
} }
} }
@ -502,18 +504,18 @@ export class GBMinService {
await step.beginDialog('/menu'); await step.beginDialog('/menu');
} else if (context.activity.name === 'giveFeedback') { } else if (context.activity.name === 'giveFeedback') {
await step.beginDialog('/feedback', { await step.beginDialog('/feedback', {
fromMenu: true fromMenu: true,
}); });
} else if (context.activity.name === 'showFAQ') { } else if (context.activity.name === 'showFAQ') {
await step.beginDialog('/faq'); await step.beginDialog('/faq');
} else if (context.activity.name === 'answerEvent') { } else if (context.activity.name === 'answerEvent') {
await step.beginDialog('/answerEvent', { await step.beginDialog('/answerEvent', {
questionId: (context.activity as any).data, questionId: (context.activity as any).data,
fromFaq: true fromFaq: true,
}); });
} else if (context.activity.name === 'quality') { } else if (context.activity.name === 'quality') {
await step.beginDialog('/quality', { await step.beginDialog('/quality', {
score: (context.activity as any).data score: (context.activity as any).data,
}); });
} else if (context.activity.name === 'updateToken') { } else if (context.activity.name === 'updateToken') {
const token = (context.activity as any).data; const token = (context.activity as any).data;
@ -527,7 +529,7 @@ export class GBMinService {
logger.error(msg); logger.error(msg);
await step.context.sendActivity( await step.context.sendActivity(
Messages[step.context.activity.locale].very_sorry_about_error Messages[step.context.activity.locale].very_sorry_about_error,
); );
await step.beginDialog('/ask', { isReturning: true }); await step.beginDialog('/ask', { isReturning: true });
} }