@botonic/plugin-flow-builder
Version:
Botonic plugin for **Hubtype Flow Builder**: run and bridge flow-driven logic from bots on the **current** line.
81 lines • 3.34 kB
JavaScript
import { __awaiter } from "tslib";
import { EventAction, storeCaseRating } from '@botonic/shared';
import { v7 as uuidv7 } from 'uuid';
import { AGENT_RATING_PAYLOAD, PUSH_FLOW_PAYLOAD, SEPARATOR, } from '../constants';
import { trackEvent } from '../tracking';
export function getContentsByPayload(fbContext) {
return __awaiter(this, void 0, void 0, function* () {
var _a;
const { cmsApi, flowBuilderPlugin, botonicContext, contentID } = fbContext;
const payload = botonicContext.input.payload;
if (payload === null || payload === void 0 ? void 0 : payload.startsWith(AGENT_RATING_PAYLOAD)) {
return yield resolveRatingPayload(fbContext);
}
if (payload === null || payload === void 0 ? void 0 : payload.startsWith(PUSH_FLOW_PAYLOAD)) {
return yield resolvePushFlowPayload(fbContext);
}
const id = contentID ? (_a = cmsApi.getNodeByContentID(contentID)) === null || _a === void 0 ? void 0 : _a.id : payload;
const targetNode = id ? cmsApi.getNodeById(id) : undefined;
if (targetNode) {
return yield flowBuilderPlugin.getContentsByNode(targetNode);
}
return [];
});
}
function resolveRatingPayload(fbContext) {
return __awaiter(this, void 0, void 0, function* () {
var _a;
const { cmsApi, flowBuilderPlugin, botonicContext } = fbContext;
const payload = botonicContext.input.payload;
if (!payload) {
return [];
}
const { target, text, value, possibleOptions, possibleValues } = flowBuilderPlugin.getRatingSubmittedInfo(payload);
const hubtypeCaseId = (_a = botonicContext.session.hubtypeCase) === null || _a === void 0 ? void 0 : _a.id;
if (hubtypeCaseId) {
const event = {
action: EventAction.FeedbackCase,
feedbackTargetId: hubtypeCaseId,
feedbackGroupId: uuidv7().toString(),
possibleOptions,
possibleValues,
option: text,
value,
};
yield storeCaseRating(botonicContext, value);
yield trackEvent(botonicContext, EventAction.FeedbackCase, event);
}
const targetNode = target
? cmsApi.getNodeById(target.id)
: undefined;
if (targetNode) {
return yield flowBuilderPlugin.getContentsByNode(targetNode);
}
return [];
});
}
function resolvePushFlowPayload(fbContext) {
return __awaiter(this, void 0, void 0, function* () {
const { cmsApi, flowBuilderPlugin, botonicContext } = fbContext;
if (!botonicContext.input.payload) {
return [];
}
const parts = botonicContext.input.payload.split(SEPARATOR);
const pushFlowId = parts.length > 1 ? parts[1] : '';
if (!pushFlowId) {
return [];
}
try {
const pushFlowNode = cmsApi.getNodeByCampaignId(pushFlowId);
if (!pushFlowNode) {
return [];
}
return yield flowBuilderPlugin.getContentsByNode(pushFlowNode);
}
catch (_a) {
// Campaign not found - return empty to trigger fallback
return [];
}
});
}
//# sourceMappingURL=payload.js.map