@botonic/plugin-flow-builder
Version:
Use Flow Builder to show your contents
62 lines • 2.75 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getContentsByPayload = void 0;
const tslib_1 = require("tslib");
const core_1 = require("@botonic/core");
const uuid_1 = require("uuid");
const constants_1 = require("../constants");
const tracking_1 = require("../tracking");
function getContentsByPayload(context) {
var _a, _b;
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const { cmsApi, flowBuilderPlugin, request, contentID } = context;
if ((_a = request.input.payload) === null || _a === void 0 ? void 0 : _a.startsWith(constants_1.AGENT_RATING_PAYLOAD)) {
return yield resolveRatingPayload(context);
}
const id = contentID
? (_b = cmsApi.getNodeByContentID(contentID)) === null || _b === void 0 ? void 0 : _b.id
: request.input.payload;
const targetNode = id ? cmsApi.getNodeById(id) : undefined;
if (targetNode) {
return yield flowBuilderPlugin.getContentsByNode(targetNode);
}
return [];
});
}
exports.getContentsByPayload = getContentsByPayload;
function resolveRatingPayload(context) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const { cmsApi, flowBuilderPlugin, request } = context;
if (!request.input.payload) {
return [];
}
const id = request.input.payload;
const buttonId = id === null || id === void 0 ? void 0 : id.split(constants_1.SEPARATOR)[1];
const ratingNode = cmsApi.getRatingNodeByButtonId(buttonId);
const ratingButton = cmsApi.getRatingButtonById(ratingNode, buttonId);
const { target, text, value } = ratingButton;
const possibleOptions = ratingNode.content.buttons.map(button => button.text);
const possibleValues = ratingNode.content.buttons.map(button => button.value);
if (request.session._hubtype_case_id) {
const event = {
action: tracking_1.EventAction.FeedbackCase,
feedbackTargetId: request.session._hubtype_case_id,
feedbackGroupId: (0, uuid_1.v7)().toString(),
possibleOptions,
possibleValues,
option: text,
value,
};
yield (0, core_1.storeCaseRating)(request.session, value);
yield (0, tracking_1.trackEvent)(request, tracking_1.EventAction.FeedbackCase, event);
}
const targetNode = target
? cmsApi.getNodeById(target.id)
: undefined;
if (targetNode) {
return yield flowBuilderPlugin.getContentsByNode(targetNode);
}
return [];
});
}
//# sourceMappingURL=payload.js.map