UNPKG

@jargon/platform-jovo

Version:

A Jovo Framework plugin for the Jargon Platform SDK

57 lines 2.44 kB
"use strict"; /* * Copyright 2019 Jargon, Inc. or its affiliates. All Rights Reserved. * Licensed under the Apache License, Version 2.0 (the "License"). * You may not use this file except in compliance with the License. * A copy of the License is located at * http://www.apache.org/licenses/LICENSE-2.0 * * or in the "license" file accompanying this file. This file is distributed * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either * express or implied. See the License for the specific language governing * permissions and limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.JargonPlugin = void 0; const platform_sdk_core_1 = require("@jargon/platform-sdk-core"); const jovo_core_1 = require("jovo-core"); const jovojargon_1 = require("../jovojargon"); /** The Jargon plugin for the Jovo framework */ class JargonPlugin extends jovo_core_1.Extensible { /** Constructor for the plugin * @param {any} options Optional options for the plugin. The values in DefaultResourceManagerOptions will be used for anything not provided */ constructor(options = {}) { super(); this._options = Object.assign({}, platform_sdk_core_1.DefaultResourceManagerOptions, options); this._rmf = options.resourceManagerFactory || new platform_sdk_core_1.DefaultResourceManagerFactory(this._options); } /** Called by the Jovo framework after the plugin is installed */ install(app) { app.middleware('after.platform.init').use(async (handleRequest) => { const jovo = handleRequest.jovo; const req = jovo.$request; const locale = req.getLocale(); const platform = toJargonPlatform(jovo.getPlatformType()); let rm = await this._rmf.forLocaleAndPlatform(locale, platform); jovo.jargon = new jovojargon_1.JJ(jovo, rm); }); } uninstall(parent) { // Nothing to do here } } exports.JargonPlugin = JargonPlugin; function toJargonPlatform(jovoPlatform) { if (jovoPlatform === jovojargon_1.jptAlexa) { return 'Alexa'; } else if (jovoPlatform === jovojargon_1.jptGoogleAssistant) { return 'ActionsOnGoogle'; } else if (jovoPlatform === jovojargon_1.jptBixby) { return 'Bixby'; } throw new Error(`Unsupported platform ${jovoPlatform}`); } //# sourceMappingURL=index.js.map