UNPKG

@onereach/channel-transformer

Version:

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

33 lines (30 loc) 916 B
import { IGenericLink } from '../../../generic/types'; import { ISlackTextObject } from '../../types'; import { getMethods } from '../methods'; export const transformLink = ({ props, children }: IGenericLink): ISlackTextObject => { let result = ''; const { url, label } = props; if (label) { result = `<${url}|${label}>`; } else { const label = children?.reduce((acc, item) => { if (item.type === 'button') { acc += `${item.props?.label || item.props?.value}`; } else { const transformFn = getMethods(item.type); if (transformFn) { const result = transformFn(item); acc += typeof result?.text === 'string' ? result.text : (typeof result === 'string' ? result : ''); } } return acc; }, ''); result += `<${url}|${label || url}>`; } return { type: 'mrkdwn', text: result }; };