n8n-nodes-base
Version:
Base nodes of n8n
49 lines • 2.02 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.handleMessage = handleMessage;
const n8n_workflow_1 = require("n8n-workflow");
async function handleMessage(context, options) {
// No message in the context
if (!context.message) {
return null;
}
// ignore duplicate message check, don't think it's necessary, but it was in the rhea-lib example code
if (context.message.message_id && context.message.message_id === options.lastMessageId) {
return null;
}
let data = context.message;
if (options.jsonConvertByteArrayToString === true && data.body.content !== undefined) {
// The buffer is not ready... Stringify and parse back to load it.
const cont = (0, n8n_workflow_1.deepCopy)(data.body.content);
data.body = String.fromCharCode.apply(null, cont.data);
}
if (options.jsonConvertByteArrayToString === true && data.body.content !== undefined) {
// The buffer is not ready... Stringify and parse back to load it.
const content = (0, n8n_workflow_1.deepCopy)(data.body.content);
data.body = String.fromCharCode.apply(null, content.data);
}
if (options.jsonParseBody === true) {
data.body = (0, n8n_workflow_1.jsonParse)(data.body);
}
if (options.onlyBody === true) {
data = data.body;
}
let responsePromise = undefined;
if (!options.parallelProcessing) {
responsePromise = this.helpers.createDeferredPromise();
}
if (responsePromise) {
this.emit([this.helpers.returnJsonArray([data])], undefined, responsePromise);
await responsePromise.promise;
}
else {
this.emit([this.helpers.returnJsonArray([data])]);
}
if (!context.receiver?.has_credit()) {
setTimeout(() => {
context.receiver?.add_credit(options.pullMessagesNumber);
}, options.sleepTime || 10);
}
return { messageId: context.message.message_id };
}
//# sourceMappingURL=handleMessage.js.map