{
  "name": "GT-Engine-Workflow",
  "nodes": [
    {
      "parameters": {},
      "id": "a668af24-5543-4f2a-808e-bf69b81667b5",
      "name": "When clicking \"Execute Workflow\"",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        100,
        300
      ]
    },
    {
      "parameters": {
        "operation": "getAll",
        "returnAll": true
      },
      "id": "ad88f1aa-d458-47bc-a6ad-c9f4060f6aef",
      "name": "Raindrop",
      "type": "n8n-nodes-base.raindrop",
      "typeVersion": 1,
      "position": [
        480,
        360
      ],
      "credentials": {
        "raindropOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "resource": "bookmark",
        "operation": "getAll",
        "collectionId": "={{ $json[\"_id\"] }}",
        "limit": 10
      },
      "id": "f0d5142e-4402-4343-8830-a6ce5336b316",
      "name": "Raindrop1",
      "type": "n8n-nodes-base.raindrop",
      "typeVersion": 1,
      "position": [
        700,
        360
      ],
      "credentials": {
        "raindropOAuth2Api": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "chatId": "@geektool_news",
        "text": "={{ $json.link }}",
        "additionalFields": {}
      },
      "id": "6a038cc9-292a-46d9-80d6-37de6c3f517a",
      "name": "Telegram",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1,
      "position": [
        1140,
        360
      ],
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "SELECT value FROM raindrop_config WHERE `config` = 'latest_bookmark_created_time';"
      },
      "id": "7aef6c8b-8d32-4cb0-9fa5-49fcbf7ddbd9",
      "name": "MySQL",
      "type": "n8n-nodes-base.mySql",
      "typeVersion": 1,
      "position": [
        300,
        360
      ],
      "credentials": {
        "mySql": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Loop over input items and add a new field\n// called 'myNewField' to the JSON of each one\n// Loop over input items and add a new field\n// called 'myNewField' to the JSON of each one\nconst latestBookmarkCreatedTimeString = $('MySQL').last().json.value\nlet latestBookmarkCreatedUnix = DateTime.fromISO(latestBookmarkCreatedTimeString).toMillis();\n\nconst newBookMarks = $('FilterNewBookmarks').all()\nfor (const item of newBookMarks) {\n  const createdTimeUnix = DateTime.fromISO(item.json.created).toMillis();\n  if(createdTimeUnix > latestBookmarkCreatedUnix) {\n      latestBookmarkCreatedUnix = createdTimeUnix;\n  }\n}\nconst isoString = DateTime.fromMillis(latestBookmarkCreatedUnix).toISO();\nreturn [\n  {\n    latest_bookmark_created_time: isoString\n  }\n]"
      },
      "id": "e8ba57ec-c34f-432b-a356-bf08558bbe96",
      "name": "GetLatestBookmarkCreateTime",
      "type": "n8n-nodes-base.code",
      "typeVersion": 1,
      "position": [
        1580,
        360
      ]
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "hours",
              "triggerAtMinute": 5
            }
          ]
        }
      },
      "id": "af4f0520-d156-4686-a7f2-6a577b58096a",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1,
      "position": [
        120,
        560
      ]
    },
    {
      "parameters": {
        "operation": "executeQuery",
        "query": "=UPDATE raindrop_config SET value = \"{{ $json.latest_bookmark_created_time }}\" WHERE config = \"latest_bookmark_created_time\";"
      },
      "id": "8fa81058-cfe1-450f-9d83-1151be33f758",
      "name": "StoreLatestBookmarkTime",
      "type": "n8n-nodes-base.mySql",
      "typeVersion": 1,
      "position": [
        1780,
        360
      ],
      "credentials": {
        "mySql": {
          "name": "<your credential>"
        }
      }
    },
    {
      "parameters": {
        "jsCode": "// Loop over input items and add a new field\n// called 'myNewField' to the JSON of each one\nconst latestBookmarkCreatedTimeString = $('MySQL').last().json.value\nconst latestBookmarkCreatedUnix = DateTime.fromISO(latestBookmarkCreatedTimeString).toMillis();\nconst newBookmarks = [];\nfor (const item of $input.all()) {\n  const createdTimeUnix = DateTime.fromISO(item.json.created).toMillis();\n  if(createdTimeUnix > latestBookmarkCreatedUnix) {\n      newBookmarks.push(item);\n  }\n}\nreturn newBookmarks;"
      },
      "id": "8668c6aa-edd8-4967-8e14-a1c60714ac51",
      "name": "FilterNewBookmarks",
      "type": "n8n-nodes-base.code",
      "typeVersion": 1,
      "position": [
        920,
        360
      ],
      "notesInFlow": true,
      "notes": "Filter Bookmark have created time > latest created time stored in DB"
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://mattermost.internal.dummylink/hooks/hook ",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "text",
              "value": "={{ $node.FilterNewBookmarks.json.link }}"
            }
          ]
        },
        "options": {}
      },
      "id": "b680d69b-7a3e-4ac4-aaf5-322bc09468cf",
      "name": "Mattermost",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 3,
      "position": [
        1360,
        360
      ]
    }
  ],
  "connections": {
    "When clicking \"Execute Workflow\"": {
      "main": [
        [
          {
            "node": "MySQL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Raindrop": {
      "main": [
        [
          {
            "node": "Raindrop1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Raindrop1": {
      "main": [
        [
          {
            "node": "FilterNewBookmarks",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "MySQL": {
      "main": [
        [
          {
            "node": "Raindrop",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Telegram": {
      "main": [
        [
          {
            "node": "Mattermost",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GetLatestBookmarkCreateTime": {
      "main": [
        [
          {
            "node": "StoreLatestBookmarkTime",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "MySQL",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "FilterNewBookmarks": {
      "main": [
        [
          {
            "node": "Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mattermost": {
      "main": [
        [
          {
            "node": "GetLatestBookmarkCreateTime",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": true,
  "settings": {},
  "versionId": "5a79e40d-5765-4758-9906-d468171ea868",
  "id": "1",
  "tags": [
    {
      "createdAt": "2023-03-18T00:18:08.197Z",
      "updatedAt": "2023-03-18T00:18:08.197Z",
      "id": "1",
      "name": "geektool"
    },
    {
      "createdAt": "2023-03-18T00:18:09.475Z",
      "updatedAt": "2023-03-18T00:18:09.475Z",
      "id": "2",
      "name": "pff"
    }
  ]
}