UNPKG

@jargon/platform-jovo

Version:

A Jovo Framework plugin for the Jargon Platform SDK

80 lines 2.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.JJ = exports.jptBixby = exports.jptGoogleAssistant = exports.jptAlexa = void 0; // We're copying the Jovo platform names here as we don't want to rely // on anything coming from jovo-platform-* in common code, since we have // a peer dependency on those packages and we can't expect all of them to // be present exports.jptAlexa = 'Alexa'; exports.jptGoogleAssistant = 'GoogleAssistant'; exports.jptBixby = 'Bixby'; class JJ { constructor(jovo, rm) { this.jovo = jovo; this.rm = rm; } async respond(response) { let r = await this.rm.renderResponse(response); if (r.speech) { if (r.reprompt) { this.jovo.ask(r.speech.content, r.reprompt.content); } else { this.jovo.tell(r.speech.content); } } const pt = this.jovo.getPlatformType(); if (pt === exports.jptAlexa) { if (r.alexaCard) { const ac = r.alexaCard.content; const as = this.jovo.$alexaSkill; if (ac.type === 'Simple') { as.showSimpleCard(ac.title, ac.content); } else if (ac.type === 'Standard') { if (ac.image) { as.showStandardCard(ac.title, ac.text, { smallImageUrl: ac.image.smallImageUrl, largeImageUrl: ac.image.largeImageUrl }); } else { this.jovo.showSimpleCard(ac.title, ac.text); } } } for (const d in r.alexaDirectives) { const as = this.jovo.$alexaSkill; as.addDirective(r.alexaDirectives[d].content); } } else if (pt === exports.jptGoogleAssistant) { // Handle AoG responses } } async tell(speech) { let s = await this.rm.render(speech); this.jovo.tell(s); } async ask(speech, repromptSpeech) { let s; let rs = undefined; if (repromptSpeech) { [s, rs] = await this.rm.renderBatch([speech, repromptSpeech]); } else { s = await this.rm.render(speech); } this.jovo.ask(s, rs); } async showSimpleCard(title, content) { let [t, c] = await this.rm.renderBatch([title, content]); this.jovo.showSimpleCard(t, c); } async showImageCard(title, content, imageUrl) { let [t, c] = await this.rm.renderBatch([title, content]); this.jovo.showImageCard(t, c, imageUrl); } } exports.JJ = JJ; //# sourceMappingURL=index.js.map