UNPKG

ask-cli-x

Version:

Alexa Skills Kit (ASK) Command Line Interfaces

59 lines (58 loc) 2.55 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ReplayMode = void 0; const chalk_1 = __importDefault(require("chalk")); const stream_1 = require("stream"); const dialog_controller_1 = require("../../controllers/dialog-controller"); const dialog_repl_view_1 = require("../../view/dialog-repl-view"); const interactive_mode_1 = require("./interactive-mode"); class ReplayMode extends dialog_controller_1.DialogController { constructor(config) { super(config); this.config = config; this.userInputs = config.userInputs; this.replay = config.replay; } async start() { const replayInputStream = new stream_1.Readable({ read() { } }); const replayReplView = new dialog_repl_view_1.DialogReplView({ prompt: chalk_1.default.yellow.bold("User > "), header: this._getHeader(), footer: "Goodbye!", inputStream: replayInputStream, evalFunc: (replayInput, replayCallback) => { this._evaluateInput(replayInput, replayReplView, replayInputStream, replayCallback); }, }); replayInputStream.push(`${this.userInputs.shift()}\n`, "utf8"); await this.setupSpecialCommands(replayReplView); } _getHeader() { return ("Welcome to ASK Dialog\n" + `Replaying a multi turn conversation with Alexa from ${this.replay}\n` + "Alexa will then evaluate your input and give a response!"); } async _evaluateInput(replayInput, replayReplView, replayInputStream, replayCallback) { try { await this.evaluateUtterance(replayInput, replayReplView); } catch (err) { } if (this.userInputs.length > 0) { replayCallback(null, undefined); replayInputStream.push(`${this.userInputs.shift()}\n`, "utf8"); } else { replayReplView.clearSpecialCommands(); replayReplView.close(); this.config.header = "Switching to interactive dialog.\n" + "To automatically quit after replay, append '.quit' to the userInput of your replay file.\n"; this.config.newSession = false; const interactiveReplView = new interactive_mode_1.InteractiveMode(this.config); await interactiveReplView.start(); } } } exports.ReplayMode = ReplayMode;