UNPKG

wa-chat-server-mluvii

Version:

Mluvii adapter for the modules wa-chat-server

46 lines (45 loc) 1.78 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MluviiToWatsonConverter = void 0; class MluviiToWatsonConverter { constructor(mluviiRequest, dependencies, session) { this.mluviiRequest = mluviiRequest; this.dependencies = dependencies; this.session = session; this.log = dependencies.log; } getInputForSuggestion(utterance) { var _a; this.session.data.mluvii = this.session.data.mluvii || {}; const suggestions = (_a = this.session.data.mluvii) === null || _a === void 0 ? void 0 : _a.suggestions; delete this.session.data.mluvii.suggestions; if (suggestions) { const suggestion = suggestions.find((suggestion) => suggestion.label === utterance); const logHeader = `MluviiToWatsonConverter.ts (${this.session.sessionId}): `; if (suggestion) { this.log.info(`${logHeader} - Suggestion identified, using input:`, suggestion); return suggestion.input; } else { this.log.info(`${logHeader} - Response to suggestions does not match any suggestion`, { utterance, suggestions, }); } } return null; } /* * Converts Mluvii request to Watson Request */ convert() { const activity = this.mluviiRequest; const result = { input: { text: '' } }; if (activity.activity === 'Text') { const suggestionInput = this.getInputForSuggestion(activity.text); result.input = suggestionInput || { text: activity.text }; } return result; } } exports.MluviiToWatsonConverter = MluviiToWatsonConverter;