@pipedream/microsoft_outlook 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,9 +1,11 @@
1
1
  # Overview
2
2
 
3
- With the Microsoft Outlook API, you can build a wide range of applications and
4
- services that work with Outlook. Here are some examples:
3
+ The Microsoft Outlook API on Pipedream allows you to automate email-related tasks, manage calendars, and handle contacts effortlessly. With the API, you can trigger workflows on new emails, send emails programmatically, and synchronize calendars across platforms, among other functions. Pipedream's serverless platform facilitates the connection between Outlook and a myriad of other apps for efficient automation workflows.
5
4
 
6
- - A service that helps you keep track of your to-do list and get things done
7
- - A service that helps you monitor your email and respond to messages
8
- - A service that helps you find and connect with people in your network
9
- - A service that helps you stay up to date on the latest news and information
5
+ # Example Use Cases
6
+
7
+ - **Email Event to Slack Notification**: When receiving an email from a specific sender or with certain keywords, you can automatically post a message to a Slack channel. This keeps teams informed of important communications without manual monitoring of inboxes.
8
+
9
+ - **Calendar Sync with Google Calendar**: Upon the creation of a new event in Outlook Calendar, sync this event to Google Calendar. This is ideal for individuals who use multiple calendar services and want to ensure consistency across platforms without manual duplication of events.
10
+
11
+ - **Automated Email Responses**: Set up a workflow that sends an automated response to emails that meet specific criteria, such as out-of-office replies or acknowledging receipt of customer inquiries. This helps maintain communication with contacts even when you're not actively managing your inbox.
@@ -3,7 +3,7 @@ import microsoftOutlook from "../../microsoft_outlook.app.mjs";
3
3
  export default {
4
4
  type: "action",
5
5
  key: "microsoft_outlook-create-contact",
6
- version: "0.0.6",
6
+ version: "0.0.7",
7
7
  name: "Create Contact",
8
8
  description: "Add a contact to the root Contacts folder, [See the docs](https://docs.microsoft.com/en-us/graph/api/user-post-contacts)",
9
9
  props: {
@@ -3,7 +3,7 @@ import microsoftOutlook from "../../microsoft_outlook.app.mjs";
3
3
  export default {
4
4
  type: "action",
5
5
  key: "microsoft_outlook-create-draft-email",
6
- version: "0.0.6",
6
+ version: "0.0.7",
7
7
  name: "Create Draft Email",
8
8
  description: "Create a draft email, [See the docs](https://docs.microsoft.com/en-us/graph/api/user-post-messages)",
9
9
  props: {
@@ -3,7 +3,7 @@ import microsoftOutlook from "../../microsoft_outlook.app.mjs";
3
3
  export default {
4
4
  type: "action",
5
5
  key: "microsoft_outlook-find-contacts",
6
- version: "0.0.6",
6
+ version: "0.0.7",
7
7
  name: "Find Contacts",
8
8
  description: "Finds contacts with given search string",
9
9
  props: {
@@ -3,7 +3,7 @@ import microsoftOutlook from "../../microsoft_outlook.app.mjs";
3
3
  export default {
4
4
  type: "action",
5
5
  key: "microsoft_outlook-list-contacts",
6
- version: "0.0.6",
6
+ version: "0.0.7",
7
7
  name: "List Contacts",
8
8
  description: "Get a contact collection from the default contacts folder, [See the docs](https://docs.microsoft.com/en-us/graph/api/user-list-contacts)",
9
9
  props: {
@@ -3,7 +3,7 @@ import microsoftOutlook from "../../microsoft_outlook.app.mjs";
3
3
  export default {
4
4
  type: "action",
5
5
  key: "microsoft_outlook-send-email",
6
- version: "0.0.7",
6
+ version: "0.0.8",
7
7
  name: "Send Email",
8
8
  description: "Send an email to one or multiple recipients, [See the docs](https://docs.microsoft.com/en-us/graph/api/user-sendmail)",
9
9
  props: {
@@ -3,7 +3,7 @@ import microsoftOutlook from "../../microsoft_outlook.app.mjs";
3
3
  export default {
4
4
  type: "action",
5
5
  key: "microsoft_outlook-update-contact",
6
- version: "0.0.6",
6
+ version: "0.0.7",
7
7
  name: "Update Contact",
8
8
  description: "Add a contact to the root Contacts folder, [See the docs](https://docs.microsoft.com/en-us/graph/api/user-post-contacts)",
9
9
  props: {
@@ -12,23 +12,28 @@ export default {
12
12
  label: "Recipients",
13
13
  description: "Array of email addresses",
14
14
  type: "string[]",
15
+ optional: true,
16
+ default: [],
15
17
  },
16
18
  ccRecipients: {
17
19
  label: "CC Recipients",
18
20
  description: "Array of email addresses",
19
21
  type: "string[]",
20
22
  optional: true,
23
+ default: [],
21
24
  },
22
25
  bccRecipients: {
23
26
  label: "BCC Recipients",
24
27
  description: "Array of email addresses",
25
28
  type: "string[]",
26
29
  optional: true,
30
+ default: [],
27
31
  },
28
32
  subject: {
29
33
  label: "Subject",
30
34
  description: "Subject of the email",
31
35
  type: "string",
36
+ optional: true,
32
37
  },
33
38
  contentType: {
34
39
  label: "Content Type",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pipedream/microsoft_outlook",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Pipedream Microsoft Outlook Components",
5
5
  "main": "microsoft_outlook.app.mjs",
6
6
  "keywords": [
@@ -14,6 +14,7 @@
14
14
  "dependencies": {
15
15
  "axios": "^0.21.1",
16
16
  "js-base64": "^3.7.2",
17
+ "md5": "^2.3.0",
17
18
  "mime-types": "^2.1.35"
18
19
  },
19
20
  "publishConfig": {
@@ -5,7 +5,7 @@ export default {
5
5
  key: "microsoft_outlook-new-contact",
6
6
  name: "New Contact Event (Instant)",
7
7
  description: "Emit new event when a new Contact is created",
8
- version: "0.0.7",
8
+ version: "0.0.8",
9
9
  type: "source",
10
10
  hooks: {
11
11
  ...common.hooks,
@@ -1,19 +1,53 @@
1
1
  import common from "../common.mjs";
2
+ import md5 from "md5";
2
3
  import sampleEmit from "./test-event.mjs";
3
4
 
4
5
  export default {
5
6
  ...common,
6
7
  key: "microsoft_outlook-new-email",
7
8
  name: "New Email Event (Instant)",
8
- description: "Emit new event when an email received",
9
- version: "0.0.8",
9
+ description: "Emit new event when an email is received in specified folders.",
10
+ version: "0.0.10",
10
11
  type: "source",
12
+ dedupe: "unique",
13
+ props: {
14
+ ...common.props,
15
+ folderIds: {
16
+ type: "string[]",
17
+ label: "Folder IDs to Monitor",
18
+ description: "Specify the folder IDs or names in Outlook that you want to monitor for new emails. Leave empty to monitor all folders (excluding \"Sent Items\" and \"Drafts\").",
19
+ optional: true,
20
+ async options() {
21
+ const { value: folders } = await this.listFolders();
22
+ return folders?.map(({
23
+ id: value, displayName: label,
24
+ }) => ({
25
+ value,
26
+ label,
27
+ })) || [];
28
+ },
29
+ },
30
+ },
11
31
  hooks: {
12
32
  ...common.hooks,
33
+ async deploy() {
34
+ this.db.set("sentItemFolderId", await this.getFolderIdByName("Sent Items"));
35
+ this.db.set("draftsFolderId", await this.getFolderIdByName("Drafts"));
36
+
37
+ const events = await this.getSampleEvents({
38
+ pageSize: 25,
39
+ });
40
+ if (!events || events.length == 0) {
41
+ return;
42
+ }
43
+ for (const item of events) {
44
+ this.emitEvent(item);
45
+ }
46
+ },
13
47
  async activate() {
14
48
  await this.activate({
15
49
  changeType: "created",
16
- resource: "/me/mailfolders('inbox')/messages",
50
+ resource: "/me/messages",
17
51
  });
18
52
  },
19
53
  async deactivate() {
@@ -22,37 +56,86 @@ export default {
22
56
  },
23
57
  methods: {
24
58
  ...common.methods,
25
- async getSampleEvents({ pageSize }) {
26
- return this.microsoftOutlook.listMessages({
27
- params: {
28
- $top: pageSize,
29
- $orderby: "createdDateTime desc",
30
- },
59
+ listFolders() {
60
+ return this.microsoftOutlook._makeRequest({
61
+ path: "/me/mailFolders",
31
62
  });
32
63
  },
64
+ async getFolderIdByName(name) {
65
+ const { value: folders } = await this.listFolders();
66
+ const { id } = folders.find(({ displayName }) => displayName === name);
67
+ return id;
68
+ },
69
+ async getSampleEvents({ pageSize }) {
70
+ const folders = this.folderIds?.length
71
+ ? this.folderIds.map((id) => `/me/mailFolders/${id}/messages`)
72
+ : [
73
+ "/me/messages",
74
+ ];
75
+
76
+ const results = [];
77
+ for (const folder of folders) {
78
+ const { value: messages } = await this.microsoftOutlook.listMessages({
79
+ resource: folder,
80
+ params: {
81
+ $top: pageSize,
82
+ $orderby: "createdDateTime desc",
83
+ },
84
+ });
85
+ results.push(...messages);
86
+ }
87
+ return results;
88
+ },
89
+ isRelevant(item) {
90
+ if (this.folderIds?.length) {
91
+ return this.folderIds.includes(item.parentFolderId);
92
+ }
93
+ // if no folderIds are specified, filter out items in Sent Items & Drafts
94
+ const sentItemFolderId = this.db.get("sentItemFolderId");
95
+ const draftsFolderId = this.db.get("draftsFolderId");
96
+ return item.parentFolderId !== sentItemFolderId && item.parentFolderId !== draftsFolderId;
97
+ },
33
98
  emitEvent(item) {
34
- this.$emit({
35
- email: item,
36
- }, this.generateMeta(item));
99
+ if (this.isRelevant(item)) {
100
+ this.$emit(
101
+ {
102
+ email: item,
103
+ },
104
+ this.generateMeta(item),
105
+ );
106
+ }
37
107
  },
38
108
  generateMeta(item) {
39
109
  return {
40
- id: item.id,
110
+ id: md5(item.id), // id > 64 characters, so dedupe on hash of id
41
111
  summary: `New email (ID:${item.id})`,
42
112
  ts: Date.parse(item.createdDateTime),
43
113
  };
44
114
  },
45
115
  },
46
116
  async run(event) {
47
- await this.run({
48
- event,
49
- emitFn: async ({ resourceId } = {}) => {
50
- const item = await this.microsoftOutlook.getMessage({
51
- messageId: resourceId,
52
- });
53
- this.emitEvent(item);
54
- },
55
- });
117
+ const folders = this.folderIds?.length
118
+ ? this.folderIds.map((id) => `/me/mailFolders/${id}/messages`)
119
+ : [
120
+ "/me/messages",
121
+ ];
122
+
123
+ for (const folder of folders) {
124
+ await this.run({
125
+ event,
126
+ emitFn: async ({ resourceId } = {}) => {
127
+ try {
128
+ const item = await this.microsoftOutlook.getMessage({
129
+ resource: folder,
130
+ messageId: resourceId,
131
+ });
132
+ this.emitEvent(item);
133
+ } catch {
134
+ console.log(`Could not fetch message with ID: ${resourceId}`);
135
+ }
136
+ },
137
+ });
138
+ }
56
139
  },
57
140
  sampleEmit,
58
141
  };