UNPKG

@botonic/plugin-flow-builder

Version:

Use Flow Builder to show your contents

96 lines 4.71 kB
import { __awaiter, __rest } from "tslib"; import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime"; import { EventAction } from '@botonic/core'; import { getArgumentsByLocale } from '../functions'; import { HubtypeQueuesApi } from '../services/hubtype-queues-api'; import { getCommonFlowContentEventArgsForContentId, trackEvent, } from '../tracking'; import { ContentFieldsBase } from './content-fields-base'; var QueueStatusResult; (function (QueueStatusResult) { QueueStatusResult["OPEN"] = "open"; QueueStatusResult["CLOSED"] = "closed"; QueueStatusResult["OPEN_WITHOUT_AGENTS"] = "open-without-agents"; })(QueueStatusResult || (QueueStatusResult = {})); export class FlowQueueStatusConditional extends ContentFieldsBase { constructor() { super(...arguments); this.arguments = []; this.queueId = ''; this.queueName = ''; this.isQueueOpen = false; this.isAvailableAgent = false; } static fromHubtypeCMS(component, locale) { return __awaiter(this, void 0, void 0, function* () { const newChannelConditional = new FlowQueueStatusConditional(component.id); newChannelConditional.code = component.code; newChannelConditional.arguments = component.content.arguments; newChannelConditional.resultMapping = component.content .result_mapping; yield newChannelConditional.setConditionalResult(locale); return newChannelConditional; }); } setConditionalResult(locale) { var _a, _b, _c; return __awaiter(this, void 0, void 0, function* () { const args = getArgumentsByLocale(this.arguments, locale); const queueId = ((_a = args.find(arg => arg.name === 'queue_id')) === null || _a === void 0 ? void 0 : _a.value) || ''; const queueName = ((_b = args.find(arg => arg.name === 'queue_name')) === null || _b === void 0 ? void 0 : _b.value) || ''; const checkAvailableAgents = ((_c = args.find(arg => arg.name === 'check_available_agents')) === null || _c === void 0 ? void 0 : _c.value) || false; const queueStatus = yield this.conditionalQueueStatus({ queueId, queueName, checkAvailableAgents, }); const conditionalResult = this.resultMapping.find(rMap => rMap.result === queueStatus); if (!conditionalResult) { throw new Error(`No conditional result found for node ${this.code} with queue: ${queueName}`); } this.conditionalResult = conditionalResult; this.followUp = conditionalResult.target; }); } conditionalQueueStatus({ queueId, checkAvailableAgents, queueName, }) { return __awaiter(this, void 0, void 0, function* () { const queuesApi = new HubtypeQueuesApi(queueId, checkAvailableAgents); const data = yield queuesApi.getAvailability(); this.queueId = queueId; this.queueName = queueName; this.isQueueOpen = data.open; this.isAvailableAgent = data.available_agents > 0; if (checkAvailableAgents && data.open && data.available_agents === 0) { return QueueStatusResult.OPEN_WITHOUT_AGENTS; } return data.open ? QueueStatusResult.OPEN : QueueStatusResult.CLOSED; }); } trackFlow(request) { var _a; return __awaiter(this, void 0, void 0, function* () { const { flowThreadId, flowId, flowName, flowNodeId, flowNodeContentId } = getCommonFlowContentEventArgsForContentId(request, this.id); if (!((_a = this.conditionalResult) === null || _a === void 0 ? void 0 : _a.result)) { console.warn(`Tracking event for node ${this.code} but no conditional result found`); } const eventQueueStatusConditional = { action: EventAction.ConditionalQueueStatus, flowThreadId, flowId, flowName, flowNodeId, flowNodeContentId, flowNodeIsMeaningful: false, queueId: this.queueId, queueName: this.queueName, isQueueOpen: this.isQueueOpen, isAvailableAgent: this.isAvailableAgent, }; const { action } = eventQueueStatusConditional, eventArgs = __rest(eventQueueStatusConditional, ["action"]); yield trackEvent(request, action, eventArgs); }); } toBotonic() { return _jsx(_Fragment, {}); } } //# sourceMappingURL=flow-queue-status-conditional.js.map