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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
{
  "meta": {
    "instanceId": "a2434c94d549548a685cca39cc4614698e94f527bcea84eefa363f1037ae14cd"
  },
  "nodes": [
    {
      "id": "0bacf032-53d6-4ba6-ab71-e01625c49cc4",
      "name": "On schedule",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -1960,
        160
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes",
              "minutesInterval": 1
            }
          ]
        }
      },
      "typeVersion": 1.1
    },
    {
      "id": "2e0d9aef-0a60-4506-9c11-c6c2cccb16ea",
      "name": "Derive last request time",
      "type": "n8n-nodes-base.dateTime",
      "position": [
        -1740,
        160
      ],
      "parameters": {
        "duration": 1,
        "timeUnit": "minutes",
        "magnitude": "={{ $json.timestamp }}",
        "operation": "subtractFromDate",
        "outputFieldName": "last_request_time"
      },
      "typeVersion": 2
    },
    {
      "id": "f726c448-b4c4-4159-8ca5-c94c092127b7",
      "name": "Get emails from label and last request time",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -1520,
        160
      ],
      "parameters": {
        "filters": {
          "labelIds": [
            "Label_9178764513576607415"
          ]
        },
        "operation": "getAll",
        "returnAll": true
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "31",
          "name": "REPLACE ME"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "9b86331f-d33b-4266-ba34-bc0491a0da24",
      "name": "Create database page",
      "type": "n8n-nodes-base.notion",
      "position": [
        -620,
        60
      ],
      "parameters": {
        "title": "={{ $('If database page not found').item.json.Subject }}",
        "blockUi": {
          "blockValues": [
            {
              "type": "heading_3",
              "textContent": "Snippet"
            },
            {
              "textContent": "={{ $('If database page not found').item.json.snippet }}"
            },
            {
              "text": {
                "text": [
                  {
                    "text": "See more",
                    "isLink": true,
                    "textLink": "=https://mail.google.com/mail/u/{{ $json.emailAddress }}/#all/{{ $('If database page not found').item.json.id }}",
                    "annotationUi": {}
                  }
                ]
              },
              "richText": true
            }
          ]
        },
        "options": {
          "icon": "https://avatars.githubusercontent.com/u/45487711?s=280&v=4",
          "iconType": "file"
        },
        "resource": "databasePage",
        "databaseId": {
          "__rl": true,
          "mode": "list",
          "value": "e606a7c1-e93d-47fd-8b8d-8000cd6e7522",
          "cachedResultUrl": "https://www.notion.so/e606a7c1e93d47fd8b8d8000cd6e7522",
          "cachedResultName": "Gmail"
        },
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Thread ID|rich_text",
              "textContent": "={{ $('If database page not found').item.json.id }}"
            },
            {
              "key": "Email thread|url",
              "urlValue": "=https://mail.google.com/mail/u/{{ $json.emailAddress }}/#all/{{ $('If database page not found').item.json.id }}"
            }
          ]
        }
      },
      "credentials": {
        "notionApi": {
          "id": "18",
          "name": "[UPDATE ME]"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "d7198578-4c83-4f57-8eba-5b5a9b89195c",
      "name": "Try get database page",
      "type": "n8n-nodes-base.notion",
      "position": [
        -1360,
        220
      ],
      "parameters": {
        "filters": {
          "conditions": [
            {
              "key": "Thread ID|rich_text",
              "condition": "equals",
              "richTextValue": "={{ $json.id }}"
            }
          ]
        },
        "options": {},
        "resource": "databasePage",
        "operation": "getAll",
        "returnAll": true,
        "databaseId": {
          "__rl": true,
          "mode": "list",
          "value": "e606a7c1-e93d-47fd-8b8d-8000cd6e7522",
          "cachedResultUrl": "https://www.notion.so/e606a7c1e93d47fd8b8d8000cd6e7522",
          "cachedResultName": "My Gmail Tasks"
        },
        "filterType": "manual"
      },
      "credentials": {
        "notionApi": {
          "id": "18",
          "name": "[UPDATE ME]"
        }
      },
      "typeVersion": 2,
      "alwaysOutputData": true
    },
    {
      "id": "f8188ab9-9a80-4aa9-b773-73cd90b8dbd3",
      "name": "If checked off",
      "type": "n8n-nodes-base.if",
      "position": [
        -1740,
        460
      ],
      "parameters": {
        "conditions": {
          "boolean": [
            {
              "value1": "={{ $json.Complete }}",
              "value2": true
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "bfcfeeb1-ad8b-47fb-8a09-b58e7b649a25",
      "name": "On updated database page",
      "type": "n8n-nodes-base.notionTrigger",
      "position": [
        -1960,
        460
      ],
      "parameters": {
        "event": "pagedUpdatedInDatabase",
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "databaseId": {
          "__rl": true,
          "mode": "list",
          "value": "e606a7c1-e93d-47fd-8b8d-8000cd6e7522",
          "cachedResultUrl": "https://www.notion.so/e606a7c1e93d47fd8b8d8000cd6e7522",
          "cachedResultName": "My Gmail Tasks"
        }
      },
      "credentials": {
        "notionApi": {
          "id": "18",
          "name": "[UPDATE ME]"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "dc2c59b8-6e0d-46b3-946a-e48b0461c48f",
      "name": "Remove label from target email",
      "type": "n8n-nodes-base.gmail",
      "position": [
        -1520,
        460
      ],
      "parameters": {
        "labelIds": [
          "Label_9178764513576607415"
        ],
        "messageId": "={{ $json['Thread ID'] }}",
        "operation": "removeLabels"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "31",
          "name": "REPLACE ME"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "0f693c2f-ce89-4a2f-a85f-9230b7bcb94d",
      "name": "Not yet checked off, do nothing",
      "type": "n8n-nodes-base.noOp",
      "position": [
        -1520,
        660
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "bf792470-fc0a-45a2-b655-df5c977faa97",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        -1220,
        100
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "joinMode": "enrichInput1",
        "mergeByFields": {
          "values": [
            {
              "field1": "id",
              "field2": "property_thread_id"
            }
          ]
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "f910c34c-4c3d-481f-8223-a8aae710dbbd",
      "name": "If found, do nothing",
      "type": "n8n-nodes-base.noOp",
      "position": [
        -840,
        260
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "7086cd15-9f2e-40e4-be3b-47d117dde670",
      "name": "If database page not found",
      "type": "n8n-nodes-base.if",
      "position": [
        -1060,
        160
      ],
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{ $json.property_thread_id }}",
              "operation": "isEmpty"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "86ce380c-0810-4edb-94e4-fb67b0ca422c",
      "name": "Find my email address",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -840,
        60
      ],
      "parameters": {
        "url": "https://gmail.googleapis.com/gmail/v1/users/me/profile",
        "options": {},
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "gmailOAuth2"
      },
      "credentials": {
        "gmailOAuth2": {
          "id": "31",
          "name": "REPLACE ME"
        }
      },
      "typeVersion": 4.1
    },
    {
      "id": "f576f785-49e4-4ed2-b83e-400b001b6c3a",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2540,
        100
      ],
      "parameters": {
        "width": 501.0810810810809,
        "height": 545.405405405404,
        "content": "## Send labeled email to a Notion database\nThis workflow sends the contents of an email to a Notion database. The email must be labeled with a specific label for the workflow to trigger. The email subject will be the title of the Notion page, and a snippet of the email body will be the content of the Notion page. The email link will be added to the Notion page as a property.\n\n### How it works\nOn scheduled intervals, find all emails with a specific label. For each email, check if the email already exists in the Notion database. If it does not exist, create a new page in the Notion database, otherwise do nothing. When the task in the Notion database is checked off, the label will be removed from the email.\n\n### Setup\nThis workflow requires that you set up a Notion database or use an existing one with at least the following fields:\n- Title (title)\n- Thread ID (text)\n- Email thread (URL)\n\n\nAdditionally, create a label that will be used to trigger the workflow in Gmail. In this workflow, the label is called \"Notion\"."
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "Merge": {
      "main": [
        [
          {
            "node": "If database page not found",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "On schedule": {
      "main": [
        [
          {
            "node": "Derive last request time",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If checked off": {
      "main": [
        [
          {
            "node": "Remove label from target email",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Not yet checked off, do nothing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find my email address": {
      "main": [
        [
          {
            "node": "Create database page",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Try get database page": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Derive last request time": {
      "main": [
        [
          {
            "node": "Get emails from label and last request time",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "On updated database page": {
      "main": [
        [
          {
            "node": "If checked off",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "If database page not found": {
      "main": [
        [
          {
            "node": "Find my email address",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "If found, do nothing",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get emails from label and last request time": {
      "main": [
        [
          {
            "node": "Try get database page",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}