UNPKG

@botonic/plugin-contentful

Version:

## What Does This Plugin Do?

49 lines 2.12 kB
import { __awaiter } from "tslib"; import * as cms from '../../cms'; import { addCustomFields, ContentfulEntryUtils, } from '../delivery-utils'; import { DeliveryWithReference } from './reference'; export class TextDelivery extends DeliveryWithReference { constructor(delivery, button, resumeErrors) { super(cms.ContentType.TEXT, delivery, resumeErrors); this.delivery = delivery; this.button = button; } text(id, context) { return __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 __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 = ContentfulEntryUtils.commonFieldsFromEntry(entry, followUp); const buttonsStyle = this.getButtonsStyle(fields.buttonsStyle); const referenceDelivery = { delivery: this.reference, context, }; return 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; } } //# sourceMappingURL=text.js.map