UNPKG

@ebenos/cli-adapter

Version:

A CLI adapter for ebenos framework

67 lines 2.35 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const framework_1 = require("@ebenos/framework"); const inquirer_1 = __importDefault(require("inquirer")); async function sender(actions, type) { if (type === 'UNORDERED') { throw new Error('Not supported!'); } for (const a of actions) { if (a.type === 'message') { const msg = a.message; if (msg.text) { console.log(msg.text); continue; } if (msg.attachment) { console.log(msg.attachment); continue; } } } } function prompt(input) { inquirer_1.default .prompt({ type: 'input', message: 'test', name: 'input' }) .then((answers) => input('message', 'loneuser', { text: answers['input'] })) .then(() => prompt(input)); } class CliAdapter extends framework_1.GenericAdapter { constructor() { super(...arguments); this.sender = sender; this.operations = { handover: () => new Promise((resolve) => resolve()) }; } initialization() { const input = this.inputFunction(); prompt(input); } inputFunction() { const loader = (0, framework_1.inMemoryUserLoader)(); return async (type, id, data) => { var _a; const user = await loader(id); switch (type) { case 'postback': if (typeof data === 'string') { return (_a = this.routers.PostbackRouter) === null || _a === void 0 ? void 0 : _a.stringPayloadHandler(data, user); } throw new Error("This can't be a payload!"); case 'message': if (typeof data === 'object' && 'text' in data) { return this.handlers.text ? this.handlers.text(data, undefined, user) : undefined; } throw new Error("This can't be text message!"); } }; } } exports.default = CliAdapter; //# sourceMappingURL=adapter.js.map