Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More

@jargon/voxa-plugin

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jargon/voxa-plugin - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

@@ -0,2 +1,12 @@

### 0.2.0
Jargon variation support
This requires cloning the core Voxa directives into Jargon versions,
and changing at runtime the directiveHandlers in VoxaApp to use the
Jargon equivalent version instead of the originals. Only directives
that need to have variation support require a Jargon versions; directives
that pull full objects (such as APL or display templates) don't need the
modified versions.
### 0.1.0
Initial preview release

@@ -1,12 +0,18 @@

import { ResourceManager, ResourceManagerOptions, RenderOptions } from '@jargon/sdk-core';
import { RenderItem, RenderOptions, ResourceManager, ResourceManagerOptions } from '@jargon/sdk-core';
import { VoxaApp } from 'voxa';
declare module 'voxa/lib/src/VoxaEvent' {
declare module 'voxa' {
interface IVoxaEvent {
jrm?: ResourceManager;
jargonResourceManager?: ResourceManager;
jrm: ResourceManager;
jargonResourceManager: ResourceManager;
jargonRenderOptions?: RenderOptions;
$jargon: JargonInternal;
}
}
/** Jargon SDK internal state */
export interface JargonInternal {
renderItems: Map<string, RenderItem>;
}
export interface JargonVoxaOptions extends ResourceManagerOptions {
}
export declare function JargonVoxa(options: JargonVoxaOptions, voxaConfig: any): VoxaApp;
export declare function makeJargonInternal(): JargonInternal;

@@ -17,2 +17,3 @@ "use strict";

const voxa_1 = require("voxa");
const directives_1 = require("../directives");
const renderer_1 = require("../renderer");

@@ -27,8 +28,19 @@ function JargonVoxa(options, voxaConfig) {

exports.JargonVoxa = JargonVoxa;
const directiveReplacements = {
[voxa_1.Ask.key]: directives_1.JAsk,
[voxa_1.Hint.key]: directives_1.JHint,
[voxa_1.Reprompt.key]: directives_1.JReprompt,
[voxa_1.Say.key]: directives_1.JSay,
[voxa_1.Tell.key]: directives_1.JTell,
text: directives_1.JText // Voxa doesn't current export Text
};
class JargonVoxaPlugin {
constructor(options) {
this._modifiedDirectives = new Set();
this.requestHandler = (event, reply) => {
this.modifyDirectives(event.platform.app);
const locale = event.request.locale || 'en-US';
event.jrm = this._rmf.forLocale(locale);
event.jargonResourceManager = event.jrm;
event.$jargon = makeJargonInternal();
};

@@ -41,3 +53,15 @@ this._options = Object.assign({}, sdk_core_1.DefaultResourceManagerOptions, options);

}
modifyDirectives(app) {
if (!this._modifiedDirectives.has(app)) {
app.directiveHandlers = app.directiveHandlers.map(dc => directiveReplacements[dc.key] || dc);
this._modifiedDirectives.add(app);
}
}
}
function makeJargonInternal() {
return {
renderItems: new Map()
};
}
exports.makeJargonInternal = makeJargonInternal;
//# sourceMappingURL=index.js.map
import { IVoxaEvent, Renderer } from 'voxa';
import { IRendererConfig } from 'voxa/src/renderers/Renderer';
declare module 'voxa' {
interface Renderer {
render(view: string, voxaEvent: IVoxaEvent, variables?: any): Promise<string>;
}
}
export declare class JargonRenderer extends Renderer {
private _vars;
constructor(config: IRendererConfig);
constructor(config: any);
render(view: string, voxaEvent: IVoxaEvent, variables?: any): Promise<string>;
renderPath<T>(view: string, voxaEvent: IVoxaEvent, variables?: any): Promise<string | T>;
private _platformSpecificMessage;
private _makeRenderItem;
private _makeRenderParams;
}

@@ -24,4 +24,12 @@ "use strict";

const sdk_core_1 = require("@jargon/sdk-core");
const lodash_1 = require("lodash");
const voxa_1 = require("voxa");
// Ideally this would be constructed via referring to the actual platform classes,
// but we'd need to instantiate instances of each of them to do so
const platformNames = ['alexa', 'botframework', 'dialogflow'];
function messageFilter(value, key) {
return lodash_1.isString(value) && !platformNames.includes(key);
}
class JargonRenderer extends voxa_1.Renderer {
// Should be IRenderedConfig, but that's not currently exported from Voxa
constructor(config) {

@@ -31,8 +39,21 @@ super(Object.assign({ views: {} }, config));

}
render(view, voxaEvent, variables) {
return __awaiter(this, void 0, void 0, function* () {
const item = this._makeRenderItem(view, voxaEvent, variables);
const message = yield this._platformSpecificMessage(item, voxaEvent);
if (lodash_1.isString(message)) {
return message;
}
const variants = lodash_1.pickBy(message, messageFilter);
return voxaEvent.jrm.selectVariationFromObject(item, variants);
});
}
renderPath(view, voxaEvent, variables) {
const item = this._makeRenderItem(view, voxaEvent, variables);
return this._platformSpecificMessage(item, voxaEvent);
}
_platformSpecificMessage(item, voxaEvent) {
return __awaiter(this, void 0, void 0, function* () {
const params = this._makeRenderParams(voxaEvent, variables);
const item = sdk_core_1.ri(view, params, voxaEvent.jargonRenderOptions);
let message = yield voxaEvent.jrm.renderObject(item);
// Check for a platform-specific message
// Check for a platform-specific message, and filter out messages for other platforms
const platform = voxaEvent.platform.name;

@@ -42,5 +63,16 @@ if (platform && message[platform]) {

}
else {
for (const p of platformNames) {
delete message[p];
}
}
return message;
});
}
_makeRenderItem(view, voxaEvent, variables) {
const params = this._makeRenderParams(voxaEvent, variables);
const item = sdk_core_1.ri(view, params, voxaEvent.jargonRenderOptions);
voxaEvent.$jargon.renderItems.set(view, item);
return item;
}
_makeRenderParams(voxaEvent, variables) {

@@ -47,0 +79,0 @@ const params = Object.assign({}, variables);

{
"name": "@jargon/voxa-plugin",
"version": "0.1.0",
"version": "0.2.0",
"description": "A Voxa plugin for the Jargon SDK",
"keywords": [
"Jargon",
"Jargon",
"Voxa"

@@ -14,3 +14,4 @@ ],

"scripts": {
"gulp": "./node_modules/.bin/gulp"
"gulp": "./node_modules/.bin/gulp",
"test": "./node_modules/.bin/ts-mocha tst/**/*.spec.ts"
},

@@ -32,5 +33,6 @@ "author": "jargon.com",

"dependencies": {
"@jargon/sdk-core": "^1.1.0"
"@jargon/sdk-core": "^1.2.0"
},
"peerDependencies": {
"ask-sdk-model": "1.x",
"voxa": "^3.0.0"

@@ -43,2 +45,3 @@ },

"@types/node": "^10.12.1",
"ask-sdk-model": "1.x",
"chai": "^4.2.0",

@@ -50,3 +53,3 @@ "del": "^3.0.0",

"nyc": "^13.1.0",
"ts-node": "^7.0.1",
"ts-mocha": "^6.0.0",
"tslint": "^5.11.0",

@@ -53,0 +56,0 @@ "tslint-config-standard": "^8.0.1",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet