mirror of
https://github.com/n8n-io/n8n.git
synced 2024-12-25 04:34:06 -08:00
fix(Microsoft Outlook Node): Message -> Send with attachments (#8238)
This commit is contained in:
parent
7268d24259
commit
01280815c9
|
@ -1,5 +1,4 @@
|
||||||
import type {
|
import type {
|
||||||
IBinaryKeyData,
|
|
||||||
IDataObject,
|
IDataObject,
|
||||||
IExecuteFunctions,
|
IExecuteFunctions,
|
||||||
INodeExecutionData,
|
INodeExecutionData,
|
||||||
|
@ -254,7 +253,9 @@ export async function execute(this: IExecuteFunctions, index: number, items: INo
|
||||||
if (additionalFields.attachments) {
|
if (additionalFields.attachments) {
|
||||||
const attachments = (additionalFields.attachments as IDataObject).attachments as IDataObject[];
|
const attachments = (additionalFields.attachments as IDataObject).attachments as IDataObject[];
|
||||||
// // Handle attachments
|
// // Handle attachments
|
||||||
const data = attachments.map((attachment) => {
|
const data: IDataObject[] = [];
|
||||||
|
|
||||||
|
for (const attachment of attachments) {
|
||||||
const binaryPropertyName = attachment.binaryPropertyName as string;
|
const binaryPropertyName = attachment.binaryPropertyName as string;
|
||||||
|
|
||||||
if (items[index].binary === undefined) {
|
if (items[index].binary === undefined) {
|
||||||
|
@ -274,13 +275,24 @@ export async function execute(this: IExecuteFunctions, index: number, items: INo
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const binaryData = (items[index].binary as IBinaryKeyData)[binaryPropertyName];
|
const binaryData = this.helpers.assertBinaryData(index, binaryPropertyName);
|
||||||
return {
|
|
||||||
|
let fileBase64;
|
||||||
|
if (binaryData.id) {
|
||||||
|
const chunkSize = 256 * 1024;
|
||||||
|
const stream = await this.helpers.getBinaryStream(binaryData.id, chunkSize);
|
||||||
|
const buffer = await this.helpers.binaryToBuffer(stream);
|
||||||
|
fileBase64 = buffer.toString('base64');
|
||||||
|
} else {
|
||||||
|
fileBase64 = binaryData.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
data.push({
|
||||||
'@odata.type': '#microsoft.graph.fileAttachment',
|
'@odata.type': '#microsoft.graph.fileAttachment',
|
||||||
name: binaryData.fileName,
|
name: binaryData.fileName,
|
||||||
contentBytes: binaryData.data,
|
contentBytes: fileBase64,
|
||||||
};
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
for (const attachment of data) {
|
for (const attachment of data) {
|
||||||
await microsoftApiRequest.call(
|
await microsoftApiRequest.call(
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
import type {
|
import type {
|
||||||
IBinaryKeyData,
|
|
||||||
IDataObject,
|
IDataObject,
|
||||||
IExecuteFunctions,
|
IExecuteFunctions,
|
||||||
INodeExecutionData,
|
INodeExecutionData,
|
||||||
|
@ -226,8 +225,9 @@ export async function execute(this: IExecuteFunctions, index: number, items: INo
|
||||||
if (additionalFields.attachments) {
|
if (additionalFields.attachments) {
|
||||||
const attachments = (additionalFields.attachments as IDataObject).attachments as IDataObject[];
|
const attachments = (additionalFields.attachments as IDataObject).attachments as IDataObject[];
|
||||||
|
|
||||||
// // Handle attachments
|
const messageAttachments: IDataObject[] = [];
|
||||||
message.attachments = attachments.map((attachment) => {
|
|
||||||
|
for (const attachment of attachments) {
|
||||||
const binaryPropertyName = attachment.binaryPropertyName as string;
|
const binaryPropertyName = attachment.binaryPropertyName as string;
|
||||||
|
|
||||||
if (items[index].binary === undefined) {
|
if (items[index].binary === undefined) {
|
||||||
|
@ -247,13 +247,26 @@ export async function execute(this: IExecuteFunctions, index: number, items: INo
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
const binaryData = (items[index].binary as IBinaryKeyData)[binaryPropertyName];
|
const binaryData = this.helpers.assertBinaryData(index, binaryPropertyName);
|
||||||
return {
|
|
||||||
|
let fileBase64;
|
||||||
|
if (binaryData.id) {
|
||||||
|
const chunkSize = 256 * 1024;
|
||||||
|
const stream = await this.helpers.getBinaryStream(binaryData.id, chunkSize);
|
||||||
|
const buffer = await this.helpers.binaryToBuffer(stream);
|
||||||
|
fileBase64 = buffer.toString('base64');
|
||||||
|
} else {
|
||||||
|
fileBase64 = binaryData.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
messageAttachments.push({
|
||||||
'@odata.type': '#microsoft.graph.fileAttachment',
|
'@odata.type': '#microsoft.graph.fileAttachment',
|
||||||
name: binaryData.fileName,
|
name: binaryData.fileName,
|
||||||
contentBytes: binaryData.data,
|
contentBytes: fileBase64,
|
||||||
};
|
});
|
||||||
});
|
}
|
||||||
|
|
||||||
|
message.attachments = messageAttachments;
|
||||||
}
|
}
|
||||||
|
|
||||||
const body: IDataObject = {
|
const body: IDataObject = {
|
||||||
|
|
Loading…
Reference in a new issue