@onereach/channel-transformer
Version:
Convert data model between different channels (Slack, Microsoft Teams, Generic...)
47 lines (39 loc) • 1.34 kB
text/typescript
import { ISlackInput } from '../../types';
import { IGenericSection, IGenericUnicInputWrapper } from '../../../generic/types';
import { transformTextObject } from './text';
import { getMethods } from '../methods';
export const transformInput = ({ props, children }: IGenericUnicInputWrapper|IGenericSection): ISlackInput => {
const sectionChild = children[0];
const element = getMethods(sectionChild.type)({ props: sectionChild.props });
const res: ISlackInput = element.type === 'input'
? {
...element,
label: {
...props.slack?.label,
...element.label
}
}
: {
type: 'input',
element,
label: transformTextObject({
value: sectionChild.props?.label,
type: 'plain',
slack: props.slack?.label
// {
// type: props.slack?.label_type,
// emoji: props.slack?.label_emoji,
// verbatim: props.slack?.label_verbatim
// }
})
};
const dispatch_action = res.dispatch_action
|| props.slack?.dispatch_action
|| sectionChild.props?.web?.interactive;
if (typeof dispatch_action === 'boolean') {
res.dispatch_action = dispatch_action;
}
const block_id = props.slack?.block_id;
if (block_id) res.block_id = block_id;
return res;
};