{
  "id": "vahoDTSi8PAN80pI",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Add upcoming movies to your Google calendar",
  "tags": [],
  "nodes": [
    {
      "id": "192657dc-e1b7-418f-b6ef-712dc451d890",
      "name": "Every Noon",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -112,
        0
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 12
            }
          ]
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "50b6fd5f-22d1-4db9-b89e-7842f68da353",
      "name": "Get movies",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        256,
        0
      ],
      "parameters": {
        "url": "https://api.themoviedb.org/3/discover/movie",
        "options": {},
        "sendQuery": true,
        "sendHeaders": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "sort_by",
              "value": "primary_release_date.asc"
            },
            {
              "name": "primary_release_date.gte",
              "value": "={{ $today.toFormat('yyyy-MM-dd') }}"
            }
          ]
        },
        "headerParameters": {
          "parameters": [
            {
              "name": "Authorization",
              "value": "=Bearer {{ $json.tmdb_access_token }}"
            }
          ]
        }
      },
      "typeVersion": 4.3
    },
    {
      "id": "ad76f3f2-0439-41ee-b859-7130e3fb622f",
      "name": "Config TMDB token and Telegram chat ID",
      "type": "n8n-nodes-base.set",
      "position": [
        48,
        0
      ],
      "parameters": {
        "mode": "raw",
        "options": {},
        "jsonOutput": "{\n  \"tmdb_access_token\": \"token\",\n  \"telegram_chat_id\": \"id\"\n}\n"
      },
      "typeVersion": 3.4
    },
    {
      "id": "cd808f89-2d09-4f12-9852-faad7a5bb287",
      "name": "Separate movies",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        400,
        0
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "results"
      },
      "typeVersion": 1
    },
    {
      "id": "9bbe381d-1d9d-49f5-ae07-0a45267b12bb",
      "name": "If new",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        528,
        0
      ],
      "parameters": {
        "filters": {
          "conditions": [
            {
              "keyName": "imdb_id",
              "keyValue": "={{ $json.id }}"
            }
          ]
        },
        "operation": "rowNotExists",
        "dataTableId": {
          "__rl": true,
          "mode": "list",
          "value": "o7x3ZT6nOpxZqIBJ",
          "cachedResultUrl": "/projects/1lm79qXlf70Tj1rt/datatables/o7x3ZT6nOpxZqIBJ",
          "cachedResultName": "movies"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "9e659731-523f-496e-8097-2a6b53e740c6",
      "name": "Add movie data to table",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        672,
        0
      ],
      "parameters": {
        "columns": {
          "value": {
            "movie": "={{ $json.title }}",
            "imdb_id": "={{ $json.id }}",
            "release": "={{ $json.release_date }}"
          },
          "schema": [
            {
              "id": "imdb_id",
              "type": "number",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "imdb_id",
              "defaultMatch": false
            },
            {
              "id": "movie",
              "type": "string",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "movie",
              "defaultMatch": false
            },
            {
              "id": "release",
              "type": "dateTime",
              "display": true,
              "removed": false,
              "readOnly": false,
              "required": false,
              "displayName": "release",
              "defaultMatch": false
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "movie"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "dataTableId": {
          "__rl": true,
          "mode": "list",
          "value": "o7x3ZT6nOpxZqIBJ",
          "cachedResultUrl": "/projects/1lm79qXlf70Tj1rt/datatables/o7x3ZT6nOpxZqIBJ",
          "cachedResultName": "movies"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "fb0432dd-8840-4574-9b5e-371366ab6421",
      "name": "Ask to add to calendar",
      "type": "n8n-nodes-base.telegram",
      "position": [
        864,
        0
      ],
      "parameters": {
        "text": "=\"{{ $('Separate movies').item.json.title }}\" is released at {{ $('Separate movies').item.json.release_date }}\n\n{{ $('Separate movies').item.json.overview }}",
        "chatId": "={{ $('Config TMDB token and Telegram chat ID').item.json.telegram_chat_id }}",
        "replyMarkup": "inlineKeyboard",
        "inlineKeyboard": {
          "rows": [
            {
              "row": {
                "buttons": [
                  {
                    "text": "Add to calendar",
                    "additionalFields": {
                      "callback_data": "={{ $('Separate movies').item.json.id }}"
                    }
                  }
                ]
              }
            }
          ]
        },
        "additionalFields": {
          "appendAttribution": true
        }
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "66224a7a-3734-4e9f-b385-26084a94bff5",
      "name": "Create an event",
      "type": "n8n-nodes-base.googleCalendar",
      "position": [
        288,
        304
      ],
      "parameters": {
        "end": "={{ $json.release.toDateTime().plus(2, 'hour') }}",
        "start": "={{ $json.release.toDateTime() }}",
        "calendar": {
          "__rl": true,
          "mode": "list",
          "value": "user@example.com",
          "cachedResultName": "user@example.com"
        },
        "additionalFields": {
          "summary": "=Movie \"{{ $json.movie }}\"",
          "description": "=Movie \"{{ $json.movie }}\""
        }
      },
      "credentials": {
        "googleCalendarOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "ef4e2bf5-0e7a-40f2-a85a-f7500dda6cff",
      "name": "Add to calendar button pressed",
      "type": "n8n-nodes-base.telegramTrigger",
      "position": [
        -112,
        304
      ],
      "parameters": {
        "updates": [
          "callback_query"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "7ed88af6-751e-48d5-8ae7-348a3d809eb6",
      "name": "Get movie from callback data",
      "type": "n8n-nodes-base.dataTable",
      "position": [
        112,
        304
      ],
      "parameters": {
        "filters": {
          "conditions": [
            {
              "keyName": "imdb_id",
              "keyValue": "={{ $json.callback_query.data }}"
            }
          ]
        },
        "operation": "get",
        "dataTableId": {
          "__rl": true,
          "mode": "list",
          "value": "o7x3ZT6nOpxZqIBJ",
          "cachedResultUrl": "/projects/1lm79qXlf70Tj1rt/datatables/o7x3ZT6nOpxZqIBJ",
          "cachedResultName": "movies"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "6496f0aa-5a3d-46b0-8c63-8a4a5b03e2d9",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -640,
        -112
      ],
      "parameters": {
        "width": 480,
        "height": 608,
        "content": "**Add Upcoming Movies to Your Google Calendar**\n\nThis n8n template demonstrates how to automatically fetch upcoming movie releases from TMDB and let users add selected movies to their Google Calendar directly from Telegram.\n\n**How it works:**\n\n1. On a daily schedule, the workflow queries the TMDB API for upcoming movie releases.\n\n2. Each movie is checked against an n8n data table to avoid duplicates.\n\n3. Movie details are sent to a Telegram chat with an inline \u201cAdd to calendar\u201d button.\n\n5. When the button is pressed, the workflow retrieves the movie data from the table and creates an event in Google Calendar using the movie\u2019s release date.\n\n\n**Requirements:**\n\n- TMDB API access token\n- Telegram bot token and user ID\n- Google Calendar OAuth credentials\n- One n8n data table for storing movie metadata\n"
      },
      "typeVersion": 1
    },
    {
      "id": "90a4b518-a534-45ee-8f9d-83985233937b",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -160,
        -112
      ],
      "parameters": {
        "color": 7,
        "width": 360,
        "height": 316,
        "content": "**1. Add your TMDB token and Telegram ID to the config.**"
      },
      "typeVersion": 1
    },
    {
      "id": "3bc0bc60-98a5-41d2-8e52-a2620af7424c",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        192,
        -112
      ],
      "parameters": {
        "color": 7,
        "width": 792,
        "height": 316,
        "content": "**2. Upcoming movies are requested from TMDB, saved, and each movie is sent separately to Telegram with callback button.**"
      },
      "typeVersion": 1
    },
    {
      "id": "b2eae768-9bd4-453e-ad5c-6548e7e84d08",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -160,
        224
      ],
      "parameters": {
        "color": 7,
        "width": 568,
        "height": 268,
        "content": "**3. Bot receives callbacks from buttons to add selected movie to calendar**"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "56284a9f-cc46-420e-b4a8-7b5f18eeb0ec",
  "connections": {
    "If new": {
      "main": [
        [
          {
            "node": "Add movie data to table",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Every Noon": {
      "main": [
        [
          {
            "node": "Config TMDB token and Telegram chat ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get movies": {
      "main": [
        [
          {
            "node": "Separate movies",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Separate movies": {
      "main": [
        [
          {
            "node": "If new",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add movie data to table": {
      "main": [
        [
          {
            "node": "Ask to add to calendar",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get movie from callback data": {
      "main": [
        [
          {
            "node": "Create an event",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add to calendar button pressed": {
      "main": [
        [
          {
            "node": "Get movie from callback data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Config TMDB token and Telegram chat ID": {
      "main": [
        [
          {
            "node": "Get movies",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}