n8n-nodes-feishu-lark
Version:
n8n custom nodes for n8n to interact with Feishu/Lark, including Lark Bot, Lark MCP, and Lark Trigger.
75 lines • 3.19 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const n8n_workflow_1 = require("n8n-workflow");
const wording_1 = require("../../../help/wording");
const description_1 = require("../../../help/description");
exports.default = {
name: wording_1.WORDING.ParseMessageContent,
value: "parseContent",
order: 100,
options: [description_1.DESCRIPTIONS.RECEIVE_MESSAGE_TYPES],
async call(index) {
const inputData = this.getInputData();
if (inputData.length === 0) {
throw new n8n_workflow_1.NodeOperationError(this.getNode(), 'No input data found');
}
const item = inputData[index].json;
if (item.event_type !== "im.message.receive_v1") {
this.logger.debug('Unsupported event type for parse message content', {
eventType: item.event_type,
itemIndex: index,
});
return {
outputType: "none",
};
}
const messageTypes = this.getNodeParameter('messageTypes', index, []);
const { message } = item;
message.content = JSON.parse(message.content) || '{}';
if (message.message_type === "post") {
const content = message.content;
if (content && Array.isArray(content.content)) {
const tagGroups = {};
for (const contentArray of content.content) {
if (Array.isArray(contentArray)) {
for (const element of contentArray) {
if (element && typeof element === 'object' && element.tag) {
if (!tagGroups[element.tag]) {
tagGroups[element.tag] = [];
}
const { tag, ...elementWithoutTag } = element;
tagGroups[element.tag].push(elementWithoutTag);
}
}
}
}
const parsedContent = Object.keys(tagGroups).map((tag) => ({
tag,
elements: tagGroups[tag],
}));
message.rich_content = {
title: content.title || '',
content: parsedContent,
};
}
}
const returnData = Array.from({ length: messageTypes.length }, () => []);
const outputIndex = messageTypes.indexOf(message.message_type);
if (outputIndex === -1) {
this.logger.error('Message type not selected for parsing', {
messageType: message.message_type,
itemIndex: index,
});
return {
outputType: "none",
};
}
const executionData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray({ ...item }), { itemData: { item: index } });
returnData[outputIndex].push(...executionData);
return {
outputType: "multiple",
outputData: returnData,
};
},
};
//# sourceMappingURL=ContentParse.operation.js.map