UNPKG

@onereach/channel-transformer

Version:

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

35 lines (28 loc) 796 B
import { IGenericSection } from "../../../../generic/types"; import { IRWCMessage } from "../../../types"; import { getMethods } from "../methods"; export const transformMessage = ( {type = 'message@message', components = [], text = '', message = ''} : IRWCMessage): IGenericSection => { const section: IGenericSection = { type: 'section', props: { rwc: { type: type, } }, children: [] }; if (components.length) { const children = components.reduce((acc, component) => { const name = component.name; acc.push(getMethods(name)(component)); return acc; }, []); section.children.push(...children); } else { const msg = text || message; msg && section.children.push(getMethods('rwc-text')(msg)); } return section; };