UNPKG

n8n-nodes-feishu-lark

Version:

n8n custom nodes for n8n to interact with Feishu/Lark, including Lark Bot, Lark MCP, and Lark Trigger.

102 lines 4.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const n8n_workflow_1 = require("n8n-workflow"); const wording_1 = require("../../../help/wording"); const properties_1 = require("../../../help/utils/properties"); const aes_cipher_1 = require("../../../lark-sdk/utils/aes-cipher"); const consts_1 = require("../../../lark-sdk/consts"); const event_handler_1 = require("../../../lark-sdk/handler/event-handler"); const generateChallenge = (data, options) => { if ('encrypt' in data && !options.encryptKey) { throw new Error('auto-challenge need encryptKey, please check for missing in dispatcher'); } const targetData = 'encrypt' in data ? JSON.parse(new aes_cipher_1.AESCipher(options.encryptKey).decrypt(data.encrypt)) : data; return { isChallenge: targetData.type === 'url_verification', challenge: { challenge: targetData.challenge, }, }; }; exports.default = { name: wording_1.WORDING.ParseWebhookMessage, value: "parseWebhook", order: 10, options: [ { displayName: 'Encrypt Key', name: 'encryptKey', type: 'string', required: true, description: 'Used to encrypt the transmission. <a target="_blank" href="https://open.feishu.cn/document/event-subscription-guide/event-subscriptions/event-subscription-configure-/choose-a-subscription-mode/send-notifications-to-developers-server#e0dff53d">Check Doc</a>.', typeOptions: { password: true, }, default: '', }, { displayName: 'Verification Token', name: 'verificationToken', type: 'string', required: true, description: 'Used for the application verification identifier. <a target="_blank" href="https://open.feishu.cn/document/event-subscription-guide/event-subscriptions/event-subscription-configure-/choose-a-subscription-mode/send-notifications-to-developers-server#c589dfb1">Check Doc</a>.', typeOptions: { password: true, }, default: '', }, properties_1.triggerEventProperty, { displayName: `<a target="_blank" href="https://open.feishu.cn/document/event-subscription-guide/event-subscriptions/event-subscription-configure-/choose-a-subscription-mode/send-notifications-to-developers-server">${wording_1.WORDING.OpenDocument}</a>`, name: 'notice', type: 'notice', default: '', }, ], async call(index) { const connectedNodes = this.getParentNodes(this.getNode().name); if (!connectedNodes.some(({ type }) => type === n8n_workflow_1.WEBHOOK_NODE_TYPE)) { throw new n8n_workflow_1.NodeOperationError(this.getNode(), new Error('No Webhook node found in the workflow'), { description: 'Insert a Webhook node to your workflow and set the “Respond” parameter to “Using Respond to Webhook Node” ', }); } const encryptKey = this.getNodeParameter('encryptKey', index); const verificationToken = this.getNodeParameter('verificationToken', index); const { json: { body: reqData, headers: headerData }, } = this.getInputData()[index]; const { isChallenge, challenge } = generateChallenge(reqData, { encryptKey, }); if (isChallenge) { return { parsed: true, data: challenge, }; } const events = this.getNodeParameter('events', index, []); const isAnyEvent = events.includes(consts_1.ANY_EVENT); const handlers = {}; for (const event of events) { handlers[event] = async (data) => data; } const data = Object.assign(Object.create({ headers: headerData, }), reqData); const eventDispatcher = new event_handler_1.EventDispatcher({ logger: this.logger, isAnyEvent, encryptKey, verificationToken, }).register(handlers); const eventData = await eventDispatcher.invoke(data, { needCheck: true }); if (eventData) { return { parsed: true, data: eventData, }; } return { parsed: false, }; }, }; //# sourceMappingURL=WebhookParse.operation.js.map