fix(Microsoft Outlook Node): Message -> Send with attachments (#8238)

This commit is contained in:
Michael Kret 2024-01-17 16:18:49 +02:00 committed by GitHub
parent 7268d24259
commit 01280815c9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 40 additions and 15 deletions

View file

@ -1,5 +1,4 @@
import type {
IBinaryKeyData,
IDataObject,
IExecuteFunctions,
INodeExecutionData,
@ -254,7 +253,9 @@ export async function execute(this: IExecuteFunctions, index: number, items: INo
if (additionalFields.attachments) {
const attachments = (additionalFields.attachments as IDataObject).attachments as IDataObject[];
// // Handle attachments
const data = attachments.map((attachment) => {
const data: IDataObject[] = [];
for (const attachment of attachments) {
const binaryPropertyName = attachment.binaryPropertyName as string;
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];
return {
const binaryData = this.helpers.assertBinaryData(index, binaryPropertyName);
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',
name: binaryData.fileName,
contentBytes: binaryData.data,
};
contentBytes: fileBase64,
});
}
for (const attachment of data) {
await microsoftApiRequest.call(

View file

@ -1,5 +1,4 @@
import type {
IBinaryKeyData,
IDataObject,
IExecuteFunctions,
INodeExecutionData,
@ -226,8 +225,9 @@ export async function execute(this: IExecuteFunctions, index: number, items: INo
if (additionalFields.attachments) {
const attachments = (additionalFields.attachments as IDataObject).attachments as IDataObject[];
// // Handle attachments
message.attachments = attachments.map((attachment) => {
const messageAttachments: IDataObject[] = [];
for (const attachment of attachments) {
const binaryPropertyName = attachment.binaryPropertyName as string;
if (items[index].binary === undefined) {
@ -247,15 +247,28 @@ export async function execute(this: IExecuteFunctions, index: number, items: INo
);
}
const binaryData = (items[index].binary as IBinaryKeyData)[binaryPropertyName];
return {
const binaryData = this.helpers.assertBinaryData(index, binaryPropertyName);
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',
name: binaryData.fileName,
contentBytes: binaryData.data,
};
contentBytes: fileBase64,
});
}
message.attachments = messageAttachments;
}
const body: IDataObject = {
message,
saveToSentItems,