UNPKG

@botonic/core

Version:

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

122 lines 4.18 kB
import { BotonicPostbackData, BotonicTextData, MessageType, } from '@botonic/shared'; export var HelpdeskEvent; (function (HelpdeskEvent) { HelpdeskEvent["StatusChanged"] = "status_changed"; HelpdeskEvent["AgentMessageCreated"] = "agent_message_created"; HelpdeskEvent["QueuePositionChanged"] = "queue_position_changed"; })(HelpdeskEvent || (HelpdeskEvent = {})); export var InputType; (function (InputType) { InputType["Text"] = "text"; InputType["Image"] = "image"; InputType["Video"] = "video"; InputType["Audio"] = "audio"; InputType["Document"] = "document"; InputType["Location"] = "location"; InputType["Contact"] = "contact"; InputType["Custom"] = "custom"; InputType["Raw"] = "raw"; InputType["CaseEventQueuePosition"] = "case_event_queue_position"; InputType["Postback"] = "postback"; InputType["Event"] = "event"; /** Legacy typing: maps to v2 typing event_name "typing_on". */ InputType["StartTyping"] = "start_typing"; /** Legacy typing: maps to v2 typing event_name "typing_off". */ InputType["SendPaused"] = "send_paused"; })(InputType || (InputType = {})); export var NluType; (function (NluType) { NluType["Keyword"] = "keyword"; NluType["SmartIntent"] = "smart-intent"; NluType["Intent"] = "intent"; })(NluType || (NluType = {})); /** * Facade over {@link BotonicRequestInput}: wraps the wire payload and exposes * camelCase accessors (`text`, `botInteractionId`, …). It does not implement * `BotonicRequestInput` (naming and shape differ on purpose). */ export class BotonicContextInput { constructor(rawInput) { this.rawInput = rawInput; } // Delegate Input properties get type() { return this.rawInput.type; } get data() { return this.rawInput.data; } get providerId() { return this.rawInput.provider_id; } get sentBy() { return this.rawInput.sent_by; } get dbId() { return this.rawInput.db_id; } get botInteractionId() { return this.rawInput.bot_interaction_id; } get conversationId() { return this.rawInput.conversation_id; } get context() { return this.rawInput.context; } get nluResolution() { return this.rawInput.nluResolution; } set nluResolution(v) { this.rawInput.nluResolution = v; } getKeyDataStringValue(key) { const value = this.rawInput.data[key]; return typeof value === 'string' ? value : undefined; } get text() { return this.getKeyDataStringValue('text'); } set text(value) { ; this.rawInput.data.text = value; } get payload() { return this.getKeyDataStringValue('payload'); } set payload(value) { ; this.rawInput.data.payload = value; } get referral() { return this.getKeyDataStringValue('referral'); } get attachmentUrl() { var _a; return ((_a = this.getKeyDataStringValue('attachment_url')) !== null && _a !== void 0 ? _a : this.getKeyDataStringValue('attachment_content')); } get transcript() { return this.getKeyDataStringValue('transcript'); } /** True when the input is text with string data present. */ hasInputText() { return (this.type === MessageType.Text && this.text !== undefined && this.text !== ''); } /** * Replace the current input with a synthetic postback so type and data stay in sync. * Use for redirect flow instead of mutating payload/type/text individually. */ setAsPostback(payload) { this.rawInput = Object.assign(Object.assign({}, this.rawInput), { type: MessageType.Postback, data: new BotonicPostbackData(payload) }); } /** * Replace the current input with synthetic text so type and data stay in sync. * Use when converting e.g. WhatsApp referral to text input. */ setAsText(text) { this.rawInput = Object.assign(Object.assign({}, this.rawInput), { type: MessageType.Text, data: new BotonicTextData(text) }); } } //# sourceMappingURL=botonic-context-input.js.map