{
  "id": "jYwQ5Z3sYPGhW7Q9",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Monoprix Order email to Family GCal event",
  "tags": [
    {
      "id": "BZXnS1iQSgfZL7ri",
      "name": "home-automation",
      "createdAt": "2025-03-09T08:46:06.574Z",
      "updatedAt": "2025-03-09T08:46:06.574Z"
    }
  ],
  "nodes": [
    {
      "id": "6cfb2b72-4940-4a76-a038-3ea5ea3adc57",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        320,
        220
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "7d3a6a9f-3524-4bea-80d3-3e2ffb67ada6",
      "name": "Set GCal fields",
      "type": "n8n-nodes-base.set",
      "position": [
        680,
        0
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "d52d7f3c-4cba-4d3e-923a-80dba3538701",
              "name": "order_id",
              "type": "string",
              "value": "={{ $json.output.order_id }}"
            },
            {
              "id": "36760e00-2e47-4b54-a43e-115967cb2783",
              "name": "delivery_date",
              "type": "string",
              "value": "={{ $json.output.delivery_date }}"
            },
            {
              "id": "cca8ed8e-fd63-460f-8619-d08880671b4d",
              "name": "delivery_time_range",
              "type": "string",
              "value": "={{ $json.output.delivery_time_start }}-{{ $json.output.delivery_time_end }}"
            },
            {
              "id": "4afcc50b-f968-414d-8af5-90ef811a48c8",
              "name": "delivery_datetime_start",
              "type": "string",
              "value": "={{ $json.output.delivery_date }} {{ $json.output.delivery_time_start }} {{ $json.output.delivery_time_zone }}"
            },
            {
              "id": "0f4e1cac-a380-4f02-b512-2325feffe0b6",
              "name": "delivery_datetime_end",
              "type": "string",
              "value": "={{ $json.output.delivery_date }} {{ $json.output.delivery_time_end }} {{ $json.output.delivery_time_zone }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "1066ac27-7e92-4ec6-a383-0660aed7cc6a",
      "name": "Update Calendar",
      "type": "n8n-nodes-base.googleCalendar",
      "position": [
        1020,
        0
      ],
      "parameters": {
        "end": "={{ $json.delivery_datetime_end.toDateTime().plus(30, 'minutes') }}",
        "start": "={{ $json.delivery_datetime_start.toDateTime().minus(30, 'minutes') }}",
        "calendar": {
          "__rl": true,
          "mode": "list",
          "value": "user@example.com",
          "cachedResultName": "M & S (shared)"
        },
        "additionalFields": {
          "summary": "=\ud83d\uded2 Grocery delivery ({{ $json.delivery_time_range }})",
          "attendees": [],
          "description": "=Order id: {{ $json.order_id }}\nDelivery date: {{ $json.delivery_date }}\nTime: {{ $json.delivery_time_range }}"
        },
        "useDefaultReminders": false
      },
      "credentials": {
        "googleCalendarOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "08b329b9-7ab8-4514-b009-7d16d2460bd3",
      "name": "Pull email from Gmail",
      "type": "n8n-nodes-base.gmailTrigger",
      "position": [
        0,
        0
      ],
      "parameters": {
        "simple": false,
        "filters": {
          "q": "\"Confirmation de commande Monoprix.fr\"",
          "sender": "user@example.com"
        },
        "options": {},
        "pollTimes": {
          "item": [
            {
              "minute": 15
            },
            {
              "mode": "everyHour",
              "minute": 32
            }
          ]
        }
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "4cde3dc5-339b-4226-a595-ede3b3ccb83b",
      "name": "Extract key info",
      "type": "@n8n/n8n-nodes-langchain.informationExtractor",
      "position": [
        260,
        0
      ],
      "parameters": {
        "text": "={{ $json.html }}",
        "options": {
          "systemPromptTemplate": "<instructions>\nYou are an expert extraction algorithm. Only extract relevant information from the text. If you do not know the value of an attribute asked to extract, you may omit the attribute's value.\n\nYou are analyzing an automated confirmation email for grocery delivery from Monoprix.fr that recaps all important information. \n\nI will provide you an input email body  to extract informaiton from on an upcoming delivery. Extract information from the email body as input, only extract the information you are sure to have. \n</instructions>\n\n<extract_fields>\nExtract the following fields:\n\norder_id: ID of the order, for example \"1911201637652\"\ndelivery_date: Delivery Date, for example \"25 mai 2025\"\ndelivery_time_start: Delivery time start of range, for example 08:00\ndelivery_time_end: Delivery time end of range, for example 14:00\ndelivery_time_zone: It is not included in the emial, but I would like you to infer it from the delivery_address. For instance, if delivery_address is \"France\" then the timezone is \"CET\"\n</extract_fields>\n\n<ignore_fields>\nIgnore the following fields:\ndelivery_address\ndelivery_fee\namount_paid\norder_items\n</ignore_fields>\n\n<input_email_body_format>\nMerci pour votre commande !\nBonjour Robert Masterson,\n\nVotre commande a bien \u00e9t\u00e9 enregistr\u00e9e. Vous trouverez le detail ci-dessous.\n\nPour visualiser votre commande, cliquez ici. Le jour de votre livraison, vous recevrez un mail vous informant de la pr\u00e9paration de votre commande.\n\n\ud83d\udca1 Bon \u00e0 savoir : Recevez nos codes promotionnels et nos actualit\u00e9s du moment en vous abonnant \u00e0 notre newsletter. Je m\u2019abonne\n\nMerci pour votre fid\u00e9lit\u00e9 et \u00e0 bient\u00f4t sur Monoprix.fr ou sur notre appli mobile !\n\n \nL'\u00e9quipe Monoprix\n\nR\u00e9capitulatif de votre commande\nNum\u00e9ro de commande\t<order_id>191120169999652</order_id>\nAdresse de livraison\t<delivery_address>13 rue Zola, 91100 Paris, France</delivery_address>\nCr\u00e9neau horaire\t<delivery_time_start>07:00</delivery_time_start> - <delivery_time_end>08:00</delivery_time_end>\nDate de livraison\t<delivery_date>25 mai 2025</delivery_date>\nFrais de livraison\t<delivery_fee>6,00 \u20ac</delivery_fee>\nConsigne de sacs\t0,60 \u20ac\nFrais de pr\u00e9paration\t2,00 \u20ac\nSous-total\t53,66 \u20ac\nEconomies\t- 8,16 \u20ac\nTotal=\t<amount_paid>90,10 \u20ac</amount_paid>\ndont Montant cagnott\u00e9\t0,00 \u20ac\nD\u00e9tails de votre commande\n<order_items>...</order_items>\n\n\nPour consulter les conditions g\u00e9n\u00e9rales de vente de Monoprix.fr, cliquez ici\n</input_email_body_format>\n\n\n\n\n\n\n\n\n\n\n\n"
        },
        "attributes": {
          "attributes": [
            {
              "name": "delivery_time_start",
              "required": true,
              "description": "Start Delivery Datetime "
            },
            {
              "name": "delivery_time_end",
              "required": true,
              "description": "End Delivery Datetime in Sun, 9 Mar 2025 08:33:01 +0100"
            },
            {
              "name": "delivery_date",
              "type": "date",
              "required": true,
              "description": "Date of delivery in YYYY-MM-DD"
            },
            {
              "name": "delivery_time_zone",
              "description": "Delivery timezone"
            },
            {
              "name": "order_id",
              "required": true,
              "description": "ID of the order, for example \"19117890637652\""
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "77ac45d9-7a4c-440c-8360-a7f6d18cea1b",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -40,
        -160
      ],
      "parameters": {
        "color": 5,
        "width": 547,
        "height": 132,
        "content": "### \ud83d\udee0\ufe0f Setup\n1. Add your **GMail**, **ChatGPT**, and **Google Calendar** credentials\n2. Click the Test Workflow button and check your Google calendar\n3. Activate the workflow to have your grocery delivery be automatically added to Google Calendar"
      },
      "typeVersion": 1
    },
    {
      "id": "acf976aa-e30d-4291-86ab-81ab53c86a65",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -20,
        180
      ],
      "parameters": {
        "color": 7,
        "width": 162,
        "height": 119,
        "content": "\ud83d\udc46 If you want to use another grocery delivery provider, update the email and subject"
      },
      "typeVersion": 1
    },
    {
      "id": "faf8255d-4212-480a-b999-d665d5f7e4fd",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        440,
        120
      ],
      "parameters": {
        "color": 7,
        "width": 162,
        "height": 119,
        "content": "\ud83d\udc46 If you want to use another grocery delivery provider, update the email format"
      },
      "typeVersion": 1
    },
    {
      "id": "6d1cbf3b-72fd-40db-b877-e2003a01d61f",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1040,
        160
      ],
      "parameters": {
        "color": 7,
        "width": 162,
        "height": 80,
        "content": "\ud83d\udc46 Feel free to update the Calendar content"
      },
      "typeVersion": 1
    }
  ],
  "active": true,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "e84a93d6-f7a4-4e7a-add0-d6c2f62a1bcf",
  "connections": {
    "Set GCal fields": {
      "main": [
        [
          {
            "node": "Update Calendar",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Extract key info": {
      "main": [
        [
          {
            "node": "Set GCal fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Extract key info",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Pull email from Gmail": {
      "main": [
        [
          {
            "node": "Extract key info",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}