export default class WabaTemplate { constructor({ id, tbName: name, components }) { const bodyComponent = components.find((component) => component.type === 'BODY'); const headerComponent = components.find((component) => component.type === 'HEADER'); const buttonsComponent = components.find((component) => component.type === 'BUTTONS'); const footerComponent = components.find((component) => component.type === 'FOOTER'); this.id = id; this.name = name; this.text = bodyComponent.text; this.exampleText = bodyComponent.example ? bodyComponent.example : {}; this.substitutionCount = (this.text.match(/{{.*?}}/g) || []).length; this.buttons = buttonsComponent ? buttonsComponent.buttons : []; this.footer = footerComponent ? footerComponent : []; this.header = headerComponent ? headerComponent : []; this.mediaType = headerComponent && headerComponent.format !== 'TEXT' ? headerComponent.format.toLowerCase() : null; } static get MEDIA_TYPES() { return { image: { id: 'image', supportedFileTypes: ['image/jpeg', 'image/jpg', 'image/png', 'image/JPEG', 'image/JPG', 'image/PNG'], }, document: { id: 'document', supportedFileTypes: ['application/pdf', 'application/PDF'], }, video: { id: 'video', supportedFileTypes: ['video/mp4', 'video/MP4'], }, } } }