UNPKG

@botonic/plugin-flow-builder

Version:

Use Flow Builder to show your contents

55 lines 2.49 kB
import { __awaiter } from "tslib"; import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime"; import { HandOffBuilder, HelpdeskEvent, isDev, isWebchat } from '@botonic/core'; import { WebchatSettings } from '@botonic/react'; import { ContentFieldsBase } from './content-fields-base'; export class FlowHandoff extends ContentFieldsBase { 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; 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(request) { return __awaiter(this, void 0, void 0, function* () { const handOffBuilder = new HandOffBuilder(request.session); handOffBuilder.withAutoAssignOnWaiting(this.handoffAutoAssign); if (this.hasQueuePositionChangedNotificationsEnabled) { handOffBuilder.withSubscribeHelpdeskEvents([ HelpdeskEvent.QueuePositionChanged, ]); } if (this.onFinishPayload) { handOffBuilder.withOnFinishPayload(this.onFinishPayload); } if (this.queue) { const language = request.getSystemLocale(); const country = request.getUserCountry(); handOffBuilder.withQueue(this.queue.id); handOffBuilder.withBotEvent({ language, country, }); handOffBuilder.withExtraData({ language, }); yield handOffBuilder.handOff(); } }); } toBotonic(id, request) { return isDev(request.session) || isWebchat(request.session) ? (_jsx(WebchatSettings, { enableUserInput: true }, id)) : (_jsx(_Fragment, {})); } } //# sourceMappingURL=flow-handoff.js.map