UNPKG

ask-cli-x

Version:

Alexa Skills Kit (ASK) Command Line Interfaces

76 lines (75 loc) 4.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EndTurnPrediction = exports.isActionPrediction = exports.isEventPrediction = exports.getSimulationDelegationType = exports.transformSimulationResponse = exports.DelegationType = exports.ResponseActEnum = exports.RequestActEnum = exports.PredictionType = void 0; var PredictionType; (function (PredictionType) { PredictionType["Utterance"] = "Utterance"; PredictionType["ResponseAction"] = "ResponseAction"; PredictionType["ApiAction"] = "APIAction"; })(PredictionType = exports.PredictionType || (exports.PredictionType = {})); var RequestActEnum; (function (RequestActEnum) { RequestActEnum["Invoke"] = "Invoke"; RequestActEnum["Inform"] = "Inform"; })(RequestActEnum = exports.RequestActEnum || (exports.RequestActEnum = {})); var ResponseActEnum; (function (ResponseActEnum) { ResponseActEnum["ConfirmArgs"] = "ConfirmArgs"; ResponseActEnum["ConfirmAction"] = "ConfirmAction"; ResponseActEnum["RequestArgs"] = "RequestArgs"; ResponseActEnum["Offer"] = "Offer"; ResponseActEnum["ProvideHelp"] = "ProvideHelp"; ResponseActEnum["YouAreWelcome"] = "YouAreWelcome"; ResponseActEnum["Welcome"] = "Welcome"; ResponseActEnum["OutOfDomain"] = "OutOfDomain"; ResponseActEnum["Bye"] = "Bye"; ResponseActEnum["ReqMore"] = "ReqMore"; ResponseActEnum["Notify"] = "Notify"; ResponseActEnum["Request"] = "Request"; })(ResponseActEnum = exports.ResponseActEnum || (exports.ResponseActEnum = {})); var DelegationType; (function (DelegationType) { /** * When the conversation transitions from a skill dialog manager to the Alexa Conversations dialog manager. */ DelegationType["Ingress"] = "Ingress"; /** * When the conversation transitions from a conversation dialog manger to the skill dialog manager or another skill. * Ex: Dialog.Delegate directive. */ DelegationType["Egress"] = "Egress"; DelegationType["Conversations"] = "Conversations"; DelegationType["Skill"] = "Skill"; })(DelegationType = exports.DelegationType || (exports.DelegationType = {})); function transformSimulationResponse(response) { var _a, _b; return { alexaResponses: (_a = response.result.alexaExecutionInfo.alexaResponses) !== null && _a !== void 0 ? _a : [], conversations: (_b = response.result.alexaExecutionInfo.conversations) !== null && _b !== void 0 ? _b : [], type: getSimulationDelegationType(response), }; } exports.transformSimulationResponse = transformSimulationResponse; function getSimulationDelegationType(response) { var _a, _b, _c, _d, _e; if (!response.result.alexaExecutionInfo.conversations) { return DelegationType.Skill; } const delegateDirective = (_e = (_d = (_c = (_b = (_a = response.result) === null || _a === void 0 ? void 0 : _a.alexaExecutionInfo) === null || _b === void 0 ? void 0 : _b.skillExecutionInfo) === null || _c === void 0 ? void 0 : _c.invocations) === null || _d === void 0 ? void 0 : _d.map((x) => { var _a, _b, _c; return (_c = (_b = (_a = x.invocationResponse) === null || _a === void 0 ? void 0 : _a.body) === null || _b === void 0 ? void 0 : _b.response) === null || _c === void 0 ? void 0 : _c.directives; }).filter((x) => !!x).map((x) => x.find((d) => d.type === "Dialog.DelegateRequest")).filter((x) => !!x)) !== null && _e !== void 0 ? _e : []; if ((delegateDirective === null || delegateDirective === void 0 ? void 0 : delegateDirective.length) > 0) { const delDir = delegateDirective[0]; if (delDir.target === "AMAZON.Conversations" && delDir.token === "AlexaConversationsWelcome") { return DelegationType.Ingress; } else if (delDir.target === "skill") { return DelegationType.Egress; } } return DelegationType.Conversations; } exports.getSimulationDelegationType = getSimulationDelegationType; const isEventPrediction = (prediction) => typeof prediction === "object" && prediction.type === PredictionType.Utterance; exports.isEventPrediction = isEventPrediction; const isActionPrediction = (prediction) => typeof prediction === "object" && (prediction.type === PredictionType.ApiAction || prediction.type === PredictionType.ResponseAction); exports.isActionPrediction = isActionPrediction; exports.EndTurnPrediction = ".endTurn";