UNPKG

@onereach/channel-transformer

Version:

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

36 lines (29 loc) 971 B
import { IGenericWrapper } from '../../generic/types/wrapper'; import { ISNowEvent, IMessageEvent, IInputText } from '../types/index'; import { getMethods } from './methods'; export function transformServiceNowToGeneric(data: ISNowEvent): IGenericWrapper; export function transformServiceNowToGeneric(data: IMessageEvent): IGenericWrapper; export function transformServiceNowToGeneric(data): IGenericWrapper { const messages = data.messages || []; const props: any = {}; if (data.result) { messages.push(data); } else { props.rwc = { mergeTextSections: false }; } const children = messages.reduce((acc, { result }) => { if (typeof result === 'string') { const msg = { uiType: 'InputText', label: result } as IInputText; return acc.concat(getMethods(msg.uiType)(msg)); } return acc.concat(getMethods(result.uiType)(result)); }, []); return { type: 'wrapper', props, children }; }