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 { 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(

View file

@ -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,15 +247,28 @@ 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 = {
message, message,
saveToSentItems, saveToSentItems,