Skip to content

Commit

Permalink
Renaming everything to Dialog Flow
Browse files Browse the repository at this point in the history
  • Loading branch information
armonge committed Nov 13, 2017
1 parent 326eed9 commit 752b5fd
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 42 deletions.
5 changes: 2 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

const packageInfo = require('./package.json');
const StateMachineApp = require('./lib/StateMachineApp');
const DefaultRenderer = require('./lib/renderers/DefaultRenderer');

/**
* Plugins
Expand All @@ -24,8 +23,8 @@ const autoLoad = require('./lib/plugins/auto-load');


module.exports = StateMachineApp;
module.exports.Alexa = require('./lib/adapters/alexa/AlexaAdapter')
module.exports.ApiAi = require('./lib/adapters/api-ai/ApiAiAdapter')
module.exports.Alexa = require('./lib/adapters/alexa/AlexaAdapter');
module.exports.DialogFlow = require('./lib/adapters/dialog-flow/DialogFlowAdapter');

module.exports.version = packageInfo.version;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use strict';

const VoxaAdapter = require('../VoxaAdapter');
const ApiAiEvent = require('./ApiAiEvent');
const DialogFlowEvent = require('./DialogFlowEvent');
const ssml = require('../../ssml');
const _ = require('lodash');

class ApiAiAdapter extends VoxaAdapter {
class DialogFlowAdapter extends VoxaAdapter {
execute(rawEvent, context) {
const event = new ApiAiEvent(rawEvent, context);
const event = new DialogFlowEvent(rawEvent, context);
return this.app.execute(event)
.then(ApiAiAdapter.toApiAiResponse);
.then(DialogFlowAdapter.toDialogFlowResponse);
}

static sessionToContext(session) {
Expand Down Expand Up @@ -81,17 +81,17 @@ class ApiAiAdapter extends VoxaAdapter {
};
}

static toApiAiResponse(voxaReply) {
static toDialogFlowResponse(voxaReply) {
const speech = ssml.toSSML(voxaReply.msg.statements.join('\n'));
const contextOut = ApiAiAdapter.sessionToContext(voxaReply.session);
const contextOut = DialogFlowAdapter.sessionToContext(voxaReply.session);
const displayText = voxaReply.msg.plainStatements.join('\n');

const source = _.get(voxaReply, 'voxaEvent.originalRequest.source');

const integrations = {
google: ApiAiAdapter.google,
slack: ApiAiAdapter.slack,
slack_testbot: ApiAiAdapter.slack,
google: DialogFlowAdapter.google,
slack: DialogFlowAdapter.slack,
slack_testbot: DialogFlowAdapter.slack,
};

const response = {
Expand All @@ -110,4 +110,4 @@ class ApiAiAdapter extends VoxaAdapter {
}
}

module.exports = ApiAiAdapter;
module.exports = DialogFlowAdapter;
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const _ = require('lodash');
const VoxaEvent = require('../../VoxaEvent');

class ApiAiEvent extends VoxaEvent {
class DialogFlowEvent extends VoxaEvent {
constructor(event, lambdaContext) {
super();
_.merge(this, {
Expand All @@ -15,18 +15,18 @@ class ApiAiEvent extends VoxaEvent {
},
}, event);

this.session = new ApiAiSession(event);
this.session = new DialogFlowSession(event);
this.intent = new Intent(event);
this.raw = event;
this.type = 'apiai';
this.type = 'dialogFlow';
}

get user() {
return _.get(this, 'originalRequest.data.user');
}
}

class ApiAiSession {
class DialogFlowSession {
constructor(rawEvent) {
this.contexts = rawEvent.result.contexts;
this.attributes = this.getAttributes();
Expand Down Expand Up @@ -66,5 +66,5 @@ class Intent {
}
}

module.exports = ApiAiEvent;
module.exports = DialogFlowEvent;

2 changes: 1 addition & 1 deletion lib/renderers/DefaultRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class DefaultRenderer {
return Promise.reject(new Error('Locale not specified'));
}

debug('Setting locale to %s', JSON.stringify(voxaEvent, 2, null));
debug(`Setting locale to ${locale}`);
const t = i18next.getFixedT(locale);
let message = t(view, {
returnObjects: true,
Expand Down
10 changes: 5 additions & 5 deletions test/DefaultRenderer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const views = require('./views');
const variables = require('./variables');
const _ = require('lodash');
const AlexaEvent = require('../lib/adapters/alexa/AlexaEvent');
const ApiAiEvent = require('../lib/adapters/api-ai/ApiAiEvent');
const DialogFlowEvent = require('../lib/adapters/dialog-flow/DialogFlowEvent');

describe('I18NStateMachineApp', () => {
let statesDefinition;
Expand Down Expand Up @@ -178,11 +178,11 @@ describe('I18NStateMachineApp', () => {
it('should use deeply search to render array variable', () => expect(renderer.renderMessage({ card: '{exitArray}' }, { model: {} }))
.to.eventually.deep.equal({ card: [{ a: 1 }, { b: 2 }, { c: 3 }] }));

it('should use the apiai view if available', () => {
const apiAiEvent = new ApiAiEvent(require('./requests/apiai/launchIntent.json'));
return renderer.renderPath('LaunchIntent.OpenResponse', apiAiEvent)
it('should use the dialogFlow view if available', () => {
const dialogFlowEvent = new DialogFlowEvent(require('./requests/dialog-flow/launchIntent.json'));
return renderer.renderPath('LaunchIntent.OpenResponse', dialogFlowEvent)
.then((rendered) => {
expect(rendered.tell).to.equal('Hello from ApiAi');
expect(rendered.tell).to.equal('Hello from DialogFlow');
});
});
});
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
'use strict';

const expect = require('chai').expect;
const ApiAiEvent = require('../../lib/adapters/api-ai/ApiAiEvent');
const ApiAiAdapter = require('../../lib/adapters/api-ai/ApiAiAdapter');
const rawIntent = require('../requests/apiai/pizzaIntent.json');
const fallbackIntent = require('../requests/apiai/fallbackIntent.json');
const DialogFlowEvent = require('../../lib/adapters/dialog-flow/DialogFlowEvent');
const DialogFlowAdapter = require('../../lib/adapters/dialog-flow/DialogFlowAdapter');
const rawIntent = require('../requests/dialog-flow/pizzaIntent.json');
const fallbackIntent = require('../requests/dialog-flow/fallbackIntent.json');

describe('ApiAiAdapter', () => {
describe('DialogFlowAdapter', () => {
describe('sessionToContext', () => {
it('should transform a session map object to the apiai contextx format', () => {
const contexts = ApiAiAdapter.sessionToContext({
it('should transform a session map object to the DialogFlow context format', () => {
const contexts = DialogFlowAdapter.sessionToContext({
attributes: {
model: {
_state: 'someState',
Expand Down Expand Up @@ -44,7 +44,7 @@ describe('ApiAiAdapter', () => {
});

it('should return an empty context for an empty session', () => {
const contexts = ApiAiAdapter.sessionToContext({});
const contexts = DialogFlowAdapter.sessionToContext({});
expect(contexts).to.deep.equal([]);
});
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
'use strict';

const expect = require('chai').expect;
const ApiAiEvent = require('../../lib/adapters/api-ai/ApiAiEvent.js');
const rawIntent = require('../requests/apiai/pizzaIntent.json');
const fallbackIntent = require('../requests/apiai/fallbackIntent.json');
const DialogFlowEvent = require('../../lib/adapters/dialog-flow/DialogFlowEvent');
const rawIntent = require('../requests/dialog-flow/pizzaIntent.json');
const fallbackIntent = require('../requests/dialog-flow/fallbackIntent.json');

describe('ApiAiEvent', () => {
describe('DialogFlowEvent', () => {
it('should assign all event.request properties', () => {
const event = new ApiAiEvent(rawIntent);
const event = new DialogFlowEvent(rawIntent);
expect(event.result.metadata.intentId).to.equal('f55822e1-b76b-4907-b71d-d10e112a636c');
});

it('should format intent slots', () => {
const event = new ApiAiEvent(rawIntent);
const event = new DialogFlowEvent(rawIntent);
expect(event.intent.params).to.deep.equal({ number: '2', size: 'large', waterContent: '' });
});

it('should find users on the session', () => {
const event = new ApiAiEvent(fallbackIntent);
const event = new DialogFlowEvent(fallbackIntent);
expect(event.user.userId).to.equal('AI_yXq_n6kfU8IUzovfYOmX-j5Z3');
});

it('should format session parameters', () => {
const event = new ApiAiEvent(fallbackIntent);
const event = new DialogFlowEvent(fallbackIntent);
expect(event.session.attributes).to.deep.equal({
actions_capability_audio_output: {},
actions_capability_screen_output: {},
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions test/views.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const views = (function views() {
LaunchIntent: {
OpenResponse: {
tell: 'Hello! Good {time}',
apiai: {
tell: 'Hello from ApiAi',
dialogFlow: {
tell: 'Hello from DialogFlow',
},
},
},
Expand Down

0 comments on commit 752b5fd

Please sign in to comment.