@onereach/channel-transformer
Version:
Convert data model between different channels (Slack, Microsoft Teams, Generic...)
33 lines (27 loc) • 929 B
text/typescript
import { IGenericSection } from "../../../../generic/types";
import { IRWCMessage } from "../../../types";
import { getMethods } from "../methods";
export const transformMessage = (msg: IRWCMessage): IGenericSection => {
const section: IGenericSection = {
type: 'section',
children: []
};
if (msg.message || msg.answer?.message) {
const text = msg.message || msg.answer.message;
section.children.push(getMethods('text')(text));
}
if (msg.answerComponent) {
const type = msg.answerComponent.component || msg.answerComponent.name;
const transformed = getMethods(type)(msg.answerComponent);
if (Array.isArray(transformed)) {
section.children.push(...transformed);
} else {
section.children.push(transformed);
}
}
if (msg.medias?.length) {
const attachments = getMethods('medias')(msg.medias);
section.children.push(attachments);
}
return section;
};