UNPKG

@onereach/channel-transformer

Version:

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

28 lines (23 loc) 840 B
import { IGenericSection } from "../../../generic/types"; import { IMSTeamsAttachment, IMSTeamsEvent, IMSTeamsMessage } from "../../types"; import { getMethods } from "../methods"; const msteamsMessageFactory = ({attachments = [], body = {}}): IMSTeamsEvent => ({ messageType: 'message', attachments, body, }); export const transformSection = (section: IGenericSection) => { const attachments = [] as Array<IMSTeamsAttachment>; let body = {} as IMSTeamsMessage; for (const child of section.children) { const res = getMethods(child.type)(child); const type = res?.type; if (type === 'attachments') { attachments.push(...res.value); } if (type === 'text') { body = res.value; } } return msteamsMessageFactory({attachments, body}); };