UNPKG

@botonic/core

Version:

Runtime and APIs for Botonic bots: actions, context, messaging, and integration hooks used by the **current** framework line.

42 lines 2.21 kB
import { __awaiter } from "tslib"; import { injectTypingEvents } from './send-messages-utils'; /** Full execution context with input, session, and hubtype service methods. */ export class BotonicContext { constructor(hubtypeService, base, plugins, defaultTyping, defaultDelay, defaultTypingMode, response) { this.hubtypeService = hubtypeService; this.sendMessages = (messages, options) => __awaiter(this, void 0, void 0, function* () { var _a; const typingMode = (_a = options === null || options === void 0 ? void 0 : options.typingMode) !== null && _a !== void 0 ? _a : this.defaultTypingMode; return yield this.hubtypeService.sendMessages(this, injectTypingEvents(messages, typingMode)); }); this.doHandoff = (handoffOptions) => __awaiter(this, void 0, void 0, function* () { return yield this.hubtypeService.doHandoff(this, handoffOptions); }); this.getBotSession = () => __awaiter(this, void 0, void 0, function* () { return yield this.hubtypeService.getBotSession(this); }); this.updateBotSession = (updates) => __awaiter(this, void 0, void 0, function* () { yield this.hubtypeService.updateBotSession(this, updates); this.bindSessionUpdateCallback(); }); this.input = base.input; this.session = base.session; this.settings = base.settings; this.secrets = base.secrets; this.params = {}; this.plugins = plugins; this.defaultTyping = defaultTyping; this.defaultDelay = defaultDelay; this.defaultTypingMode = defaultTypingMode; this.response = response; this.bindSessionUpdateCallback(); } /** * Session user setters notify via sync callback; `updateBotSession` is async. * Attach `.catch` so fetch/network failures are logged instead of unhandled rejections. */ bindSessionUpdateCallback() { this.session.setOnUpdate(u => { void this.updateBotSession(u).catch((err) => { console.error('[BotonicContext] updateBotSession failed (session sync)', err); }); }); } } //# sourceMappingURL=botonic-context.js.map