Skip to content
Merged
2 changes: 1 addition & 1 deletion components/autodesk/autodesk.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/easypromos/easypromos.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/instantly/instantly.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/microsoft_outlook/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/microsoft_outlook",
"version": "1.0.3",
"version": "1.0.4",
"description": "Pipedream Microsoft Outlook Components",
"main": "microsoft_outlook.app.mjs",
"keywords": [
Expand Down
121 changes: 100 additions & 21 deletions components/microsoft_outlook/sources/new-email/new-email.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,46 @@ export default {
...common,
key: "microsoft_outlook-new-email",
name: "New Email Event (Instant)",
description: "Emit new event when an email received",
version: "0.0.9",
description: "Emit new event when an email is received in specified folders.",
version: "0.0.10",
type: "source",
props: {
...common.props,
folderIds: {
type: "string[]",
label: "Folder IDs to Monitor",
description: "Specify the folder IDs or names in Outlook that you want to monitor for new emails. Leave empty to monitor all folders.",
optional: true,
async options() {
const { value: folders } = await this.listFolders();
return folders?.map(({
id: value, displayName: label,
}) => ({
value,
label,
})) || [];
},
},
},
hooks: {
...common.hooks,
async deploy() {
this.db.set("sentItemFolderId", await this.getSentItemFolderId());

const events = await this.getSampleEvents({
pageSize: 25,
}); console.log(events);
if (!events || events.length == 0) {
return;
}
for (const item of events) {
this.emitEvent(item);
}
},
async activate() {
await this.activate({
changeType: "created",
resource: "/me/mailfolders('inbox')/messages",
resource: "/me/messages",
});
},
async deactivate() {
Expand All @@ -22,18 +53,53 @@ export default {
},
methods: {
...common.methods,
async getSampleEvents({ pageSize }) {
return this.microsoftOutlook.listMessages({
params: {
$top: pageSize,
$orderby: "createdDateTime desc",
},
listFolders() {
return this.microsoftOutlook._makeRequest({
path: "/me/mailFolders",
});
},
async getSentItemFolderId() {
const { value: folders } = await this.listFolders();
const { id } = folders.find(({ displayName }) => displayName === "Sent Items");
return id;
},
async getSampleEvents({ pageSize }) {
const folders = this.folderIds?.length
? this.folderIds.map((id) => `/me/mailFolders/${id}/messages`)
: [
"/me/messages",
];

const results = [];
for (const folder of folders) {
const { value: messages } = await this.microsoftOutlook.listMessages({
resource: folder,
params: {
$top: pageSize,
$orderby: "createdDateTime desc",
},
});
results.push(...messages);
}
return results;
},
isRelevant(item) {
if (this.folderIds?.length) {
return true;
}
// if no folderIds are specified, filter out items in Sent Items
const sentItemFolderId = this.db.get("sentItemFolderId");
return item.parentFolderId !== sentItemFolderId;
},
emitEvent(item) {
this.$emit({
email: item,
}, this.generateMeta(item));
if (this.isRelevant(item)) {
this.$emit(
{
email: item,
},
this.generateMeta(item),
);
}
},
generateMeta(item) {
return {
Expand All @@ -44,15 +110,28 @@ export default {
},
},
async run(event) {
await this.run({
event,
emitFn: async ({ resourceId } = {}) => {
const item = await this.microsoftOutlook.getMessage({
messageId: resourceId,
});
this.emitEvent(item);
},
});
const folders = this.folderIds?.length
? this.folderIds.map((id) => `/me/mailFolders/${id}/messages`)
: [
"/me/messages",
];

for (const folder of folders) {
await this.run({
event,
emitFn: async ({ resourceId } = {}) => {
try {
const item = await this.microsoftOutlook.getMessage({
resource: folder,
messageId: resourceId,
});
this.emitEvent(item);
} catch {
console.log(`Could not fetch message with ID: ${resourceId}`);
}
},
});
}
},
sampleEmit,
};
2 changes: 1 addition & 1 deletion components/motive/motive.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/textline/textline.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/traffit/traffit.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};