n8n-nodes-base
Version:
Base nodes of n8n
146 lines • 5.35 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.description = exports.properties = void 0;
exports.execute = execute;
const utilities_1 = require("../../../../../../utils/utilities");
const descriptions_1 = require("../../descriptions");
const utils_1 = require("../../helpers/utils");
const transport_1 = require("../../transport");
exports.properties = [
descriptions_1.messageRLC,
{
displayName: 'Output',
name: 'output',
type: 'options',
default: 'simple',
options: [
{
name: 'Simplified',
value: 'simple',
},
{
name: 'Raw',
value: 'raw',
},
{
name: 'Select Included Fields',
value: 'fields',
},
],
},
{
displayName: 'Fields',
name: 'fields',
type: 'multiOptions',
description: 'The fields to add to the output',
displayOptions: {
show: {
output: ['fields'],
},
},
options: utils_1.messageFields,
default: [],
},
{
displayName: 'Options',
name: 'options',
type: 'collection',
placeholder: 'Add option',
default: {},
options: [
{
displayName: 'Attachments Prefix',
name: 'attachmentsPrefix',
type: 'string',
default: 'attachment_',
description: 'Prefix for name of the output fields to put the binary files data in. An index starting from 0 will be added. So if name is "attachment_" the first attachment is saved to "attachment_0".',
},
{
displayName: 'Download Attachments',
name: 'downloadAttachments',
type: 'boolean',
default: false,
description: "Whether the message's attachments will be downloaded and included in the output",
},
{
displayName: 'Get MIME Content',
name: 'getMimeContent',
type: 'fixedCollection',
default: { values: { binaryPropertyName: 'data' } },
options: [
{
displayName: 'Values',
name: 'values',
values: [
{
displayName: 'Put Output in Field',
name: 'binaryPropertyName',
type: 'string',
default: '',
hint: 'The name of the output field to put the binary file data in',
},
{
displayName: 'File Name',
name: 'outputFileName',
type: 'string',
placeholder: 'message',
default: '',
description: 'Optional name of the output file, if not set message ID is used',
},
],
},
],
},
],
},
];
const displayOptions = {
show: {
resource: ['message'],
operation: ['get'],
},
};
exports.description = (0, utilities_1.updateDisplayOptions)(displayOptions, exports.properties);
async function execute(index) {
let responseData;
const qs = {};
const messageId = this.getNodeParameter('messageId', index, undefined, {
extractValue: true,
});
const options = this.getNodeParameter('options', index, {});
const output = this.getNodeParameter('output', index);
if (output === 'fields') {
const fields = this.getNodeParameter('fields', index);
if (options.downloadAttachments) {
fields.push('hasAttachments');
}
qs.$select = fields.join(',');
}
if (output === 'simple') {
qs.$select =
'id,conversationId,subject,bodyPreview,from,toRecipients,categories,hasAttachments';
}
responseData = await transport_1.microsoftApiRequest.call(this, 'GET', `/messages/${messageId}`, undefined, qs);
if (output === 'simple') {
responseData = (0, utils_1.simplifyOutputMessages)([responseData]);
}
let executionData = [];
if (options.downloadAttachments) {
const prefix = options.attachmentsPrefix || 'attachment_';
executionData = await transport_1.downloadAttachments.call(this, responseData, prefix);
}
else {
executionData = this.helpers.constructExecutionMetaData(this.helpers.returnJsonArray(responseData), { itemData: { item: index } });
}
if (options.getMimeContent) {
const { binaryPropertyName, outputFileName } = options.getMimeContent
.values;
const binary = await transport_1.getMimeContent.call(this, messageId, binaryPropertyName, outputFileName);
executionData[0].binary = {
...(executionData[0].binary || {}),
...binary,
};
}
return executionData;
}
//# sourceMappingURL=get.operation.js.map