n8n
Version:
n8n Workflow Automation Tool
43 lines • 1.72 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getMessage = getMessage;
exports.getLastNodeExecuted = getLastNodeExecuted;
exports.shouldResumeImmediately = shouldResumeImmediately;
const n8n_workflow_1 = require("n8n-workflow");
const AI_TOOL = 'ai_tool';
function getMessage(execution) {
const lastNodeExecuted = execution.data.resultData.lastNodeExecuted;
if (typeof lastNodeExecuted !== 'string')
return undefined;
const runIndex = execution.data.resultData.runData[lastNodeExecuted].length - 1;
const data = execution.data.resultData.runData[lastNodeExecuted][runIndex]?.data;
const outputs = data?.main ?? data?.[AI_TOOL];
if (outputs && Array.isArray(outputs)) {
for (const branch of outputs) {
if (branch && Array.isArray(branch) && branch.length > 0 && branch[0].sendMessage) {
return branch[0].sendMessage;
}
}
}
return undefined;
}
function getLastNodeExecuted(execution) {
const lastNodeExecuted = execution.data.resultData.lastNodeExecuted;
if (typeof lastNodeExecuted !== 'string')
return undefined;
return execution.workflowData?.nodes?.find((node) => node.name === lastNodeExecuted);
}
function shouldResumeImmediately(lastNode) {
if (lastNode?.type === n8n_workflow_1.RESPOND_TO_WEBHOOK_NODE_TYPE) {
return true;
}
if (lastNode?.parameters?.[n8n_workflow_1.CHAT_WAIT_USER_REPLY] === false) {
return true;
}
const options = lastNode?.parameters?.options;
if (options && options[n8n_workflow_1.CHAT_WAIT_USER_REPLY] === false) {
return true;
}
return false;
}
//# sourceMappingURL=utils.js.map