UNPKG

@onereach/channel-transformer

Version:

Convert data model between different channels (Slack, Microsoft Teams, Generic...)

22 lines (16 loc) 799 B
import { IGenericAttachments } from "../../../../generic/types"; import { IRWCAnswerComponent, IRWCMedia } from '../../../types'; import { RWCAnswerComponent } from "../../../classes/v5"; export const transformAttachments = ({ props }: IGenericAttachments) : IRWCAnswerComponent | Array<IRWCMedia> => { const atts = props.value.filesValue || props.value.staticValue; const type = 'rwc-medias'; const medias : Array<IRWCMedia> = atts.map(att => { const result: IRWCMedia = { location: att.text, size: att.size, type: att?.type }; // eslint-disable-next-line no-prototype-builtins if (att.hasOwnProperty('isPrivate')) result.isPrivate = att.isPrivate; return result; }); const result = new RWCAnswerComponent({ medias }, type); return result; };