@botonic/plugin-contentful
Version:
## What Does This Plugin Do?
53 lines • 2.32 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.TextDelivery = void 0;
const tslib_1 = require("tslib");
const cms = tslib_1.__importStar(require("../../cms"));
const delivery_utils_1 = require("../delivery-utils");
const reference_1 = require("./reference");
class TextDelivery extends reference_1.DeliveryWithReference {
constructor(delivery, button, resumeErrors) {
super(cms.ContentType.TEXT, delivery, resumeErrors);
this.delivery = delivery;
this.button = button;
}
text(id, context) {
return tslib_1.__awaiter(this, void 0, void 0, function* () {
// we only get the 1 level of included references...
const entry = yield this.getEntry(id, context);
// .. so we need to fetch the buttons
return this.fromEntry(entry, context);
});
}
fromEntry(entry, context) {
var _a;
return tslib_1.__awaiter(this, void 0, void 0, function* () {
const fields = entry.fields;
const buttonEntries = fields.buttons || [];
const followup = this.getReference().fromEntry(fields.followup, context);
const promises = [
followup,
this.button.fromReferenceSkipErrors(buttonEntries, context),
];
const followUpAndButtons = yield Promise.all(promises);
const followUp = followUpAndButtons[0];
const buttons = followUpAndButtons[1];
const common = delivery_utils_1.ContentfulEntryUtils.commonFieldsFromEntry(entry, followUp);
const buttonsStyle = this.getButtonsStyle(fields.buttonsStyle);
const referenceDelivery = {
delivery: this.reference,
context,
};
return (0, delivery_utils_1.addCustomFields)(new cms.Text(common, (_a = fields.text) !== null && _a !== void 0 ? _a : '', buttons, buttonsStyle), fields, referenceDelivery);
});
}
getButtonsStyle(buttonsStyle) {
if (buttonsStyle == 'QuickReplies')
return cms.ButtonStyle.QUICK_REPLY;
if (buttonsStyle == 'Buttons')
return cms.ButtonStyle.BUTTON;
return undefined;
}
}
exports.TextDelivery = TextDelivery;
//# sourceMappingURL=text.js.map