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