UNPKG

@botonic/plugin-flow-builder

Version:

Botonic plugin for **Hubtype Flow Builder**: run and bridge flow-driven logic from bots on the **current** line.

85 lines 3.58 kB
import { __awaiter } from "tslib"; import { BotServerMessageFactory, } from '@botonic/core'; import { EVENT_FORMAT_VERSION, HelpdeskEvent } from '@botonic/shared'; import { getCommonFlowContentEventArgsForContentId } from '../tracking'; import { ContentFieldsBase } from './content-fields-base'; export class FlowHandoff extends ContentFieldsBase { constructor() { super(...arguments); this.handoffAutoAssign = false; this.hasQueuePositionChangedNotificationsEnabled = false; this.isTestIntegration = false; } static fromHubtypeCMS(cmsHandoff, locale, cmsApi) { const newHandoff = new FlowHandoff(cmsHandoff.id); newHandoff.code = cmsHandoff.code; newHandoff.queue = this.getQueueByLocale(locale, cmsHandoff.content.queue); newHandoff.onFinishPayload = this.getOnFinishPayload(cmsHandoff, cmsApi); newHandoff.handoffAutoAssign = cmsHandoff.content.has_auto_assign; newHandoff.hasQueuePositionChangedNotificationsEnabled = cmsHandoff.content.has_queue_position_changed_notifications_enabled; newHandoff.followUp = cmsHandoff.follow_up; return newHandoff; } static getOnFinishPayload(cmsHandoff, cmsApi) { var _a; if ((_a = cmsHandoff.target) === null || _a === void 0 ? void 0 : _a.id) { return cmsApi.getPayload(cmsHandoff.target); } return undefined; } doHandoff(botonicContext) { return __awaiter(this, void 0, void 0, function* () { var _a; // TODO: Implement missing functionalities from HandoffBuilder const { flowId, flowName, flowNodeId, flowNodeContentId } = yield getCommonFlowContentEventArgsForContentId(botonicContext, this.id); const handoffOptions = { queue: (_a = this.queue) === null || _a === void 0 ? void 0 : _a.id, case_extra_data: { language: botonicContext.session.user.systemLocale, }, bot_event: { format_version: EVENT_FORMAT_VERSION, flow_id: flowId, flow_name: flowName, flow_node_id: flowNodeId, flow_node_content_id: flowNodeContentId, }, auto_assign_on_waiting: this.handoffAutoAssign, }; if (this.onFinishPayload) { handoffOptions.on_finish = this.onFinishPayload; } if (this.hasQueuePositionChangedNotificationsEnabled) { handoffOptions.subscribe_helpdesk_events = [ HelpdeskEvent.QueuePositionChanged, ]; } yield botonicContext.doHandoff(handoffOptions); }); } trackFlow() { return __awaiter(this, void 0, void 0, function* () { return; }); } processContent(botonicContext) { return __awaiter(this, void 0, void 0, function* () { yield this.doHandoff(botonicContext); return this.filterContent(botonicContext, this); }); } toBotonic(botonicContext) { return __awaiter(this, void 0, void 0, function* () { yield botonicContext.sendMessages([ BotServerMessageFactory.createWebchatClientSettings({ settings: { user_input_enabled: true, }, }), ]); return; }); } } //# sourceMappingURL=flow-handoff.js.map