@botonic/plugin-flow-builder
Version:
Use Flow Builder to show your contents
59 lines • 2.69 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FlowHandoff = void 0;
const tslib_1 = require("tslib");
const jsx_runtime_1 = require("react/jsx-runtime");
const core_1 = require("@botonic/core");
const react_1 = require("@botonic/react");
const content_fields_base_1 = require("./content-fields-base");
class FlowHandoff extends content_fields_base_1.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 tslib_1.__awaiter(this, void 0, void 0, function* () {
const handOffBuilder = new core_1.HandOffBuilder(request.session);
handOffBuilder.withAutoAssignOnWaiting(this.handoffAutoAssign);
if (this.hasQueuePositionChangedNotificationsEnabled) {
handOffBuilder.withSubscribeHelpdeskEvents([
core_1.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 (0, core_1.isDev)(request.session) || (0, core_1.isWebchat)(request.session) ? ((0, jsx_runtime_1.jsx)(react_1.WebchatSettings, { enableUserInput: true }, id)) : ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, {}));
}
}
exports.FlowHandoff = FlowHandoff;
//# sourceMappingURL=flow-handoff.js.map