@onereach/channel-transformer
Version:
Convert data model between different channels (Slack, Microsoft Teams, Generic...)
27 lines (21 loc) • 687 B
text/typescript
import { IGenericContext } from '../../../generic/types';
import { ISlackContext } from '../../types';
import { getMethods } from '../methods';
function omit(obj, key) {
const { [key]: omitted, ...rest } = obj;
return rest;
}
function transformContext ({ props, children }: IGenericContext): ISlackContext {
const block_id = props?.slack?.block_id;
const res: ISlackContext = {
type: 'context',
elements: children
.filter(child => child.type === 'text' || child.type === 'image')
.map(child => omit(getMethods(child.type)(child), 'title'))
};
if (block_id) res.block_id = block_id;
return res;
}
export {
transformContext
};