{
  "id": "QbC2x7gDlwnxPCsM",
  "name": "Daily trivia to Slack + Google Sheets",
  "tags": [],
  "nodes": [
    {
      "id": "ae38a38c-9ff2-4b8a-8d98-d8dbe5e36469",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        608,
        432
      ],
      "parameters": {
        "numberInputs": 3
      },
      "typeVersion": 3.2
    },
    {
      "id": "0b944199-c67a-4f77-9d7f-ab1743ee956b",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -512,
        448
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 8
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "ffa93ec5-11a3-4390-aca4-2a29e23aca15",
      "name": "Sheets: Append Trivia",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1056,
        448
      ],
      "parameters": {
        "columns": {
          "value": {
            "date": "={{ $('Merge').item.json.date }}",
            "correct": "={{ $('Merge').item.json.correct }}",
            "category": "={{ $('Merge').item.json.category }}",
            "question": "={{ $('Merge').item.json.question }}",
            "incorrect": "={{ $('Merge').item.json.incorrect }}",
            "timestamp": "={{ $('Merge').item.json.timestamp }}",
            "difficulty": "={{ $('Merge').item.json.difficulty }}"
          },
          "schema": [
            {
              "id": "timestamp",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "timestamp",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "date",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "date",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "difficulty",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "difficulty",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "category",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "category",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "question",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "question",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "correct",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "correct",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "incorrect",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "incorrect",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "ok",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "ok",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "channel",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "channel",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "ts",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "ts",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "message",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "message",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 797615523,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1dLUTeDxFv8zOeVXDB6_e05BsZBWrG_Ar-r4T8V0GacE/edit#gid=797615523",
          "cachedResultName": "range"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1dLUTeDxFv8zOeVXDB6_e05BsZBWrG_Ar-r4T8V0GacE",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1dLUTeDxFv8zOeVXDB6_e05BsZBWrG_Ar-r4T8V0GacE/edit?usp=drivesdk",
          "cachedResultName": "n8n_sheet"
        }
      },
      "typeVersion": 4
    },
    {
      "id": "d6ed8342-6f43-47f8-ade3-ccfc353f2006",
      "name": "Slack: Post Trivia",
      "type": "n8n-nodes-base.slack",
      "position": [
        832,
        448
      ],
      "parameters": {
        "text": "={{ $json[\"messageTitle\"] + '\\n\\n' + $json[\"messageBody\"] }}",
        "channel": "#general",
        "attachments": [],
        "otherOptions": {},
        "authentication": "oAuth2"
      },
      "typeVersion": 1
    },
    {
      "id": "ee2920c2-ddf0-46da-a20c-6a80814bccc9",
      "name": "Switch: triviaType",
      "type": "n8n-nodes-base.switch",
      "position": [
        -64,
        432
      ],
      "parameters": {
        "rules": {
          "rules": [
            {
              "value2": "easy"
            },
            {
              "value2": "medium"
            },
            {
              "value2": "hard"
            }
          ]
        },
        "value1": "={{$json[\"difficulty\"]}}",
        "dataType": "string"
      },
      "typeVersion": 2
    },
    {
      "id": "d68d1cb6-b8ee-465d-881f-11c821a7b12e",
      "name": "Set: Choose Trivia Type",
      "type": "n8n-nodes-base.set",
      "position": [
        -288,
        448
      ],
      "parameters": {
        "values": {
          "string": [
            {
              "name": "=difficulty",
              "value": "={{ ['easy','medium','hard'][Math.floor(Math.random() * 3)] }}"
            }
          ]
        },
        "options": {},
        "keepOnlySet": true
      },
      "typeVersion": 2
    },
    {
      "id": "64cf3c29-bc3f-4d8b-b5cb-3c8c895f8a16",
      "name": "HTTP OpenTDB Easy",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        160,
        256
      ],
      "parameters": {
        "url": "https://opentdb.com/api.php?amount=1&difficulty=easy&type=multiple",
        "options": {}
      },
      "typeVersion": 2
    },
    {
      "id": "09adb329-e04a-4856-82c3-e9008a2b0f47",
      "name": "Set Message Easy",
      "type": "n8n-nodes-base.set",
      "position": [
        384,
        256
      ],
      "parameters": {
        "values": {
          "string": [
            {
              "name": "timestamp",
              "value": "={{(new Date()).toISOString()}}"
            },
            {
              "name": "date",
              "value": "={{(new Date()).toISOString().slice(0,10)}}"
            },
            {
              "name": "difficulty",
              "value": "easy"
            },
            {
              "name": "category",
              "value": "={{$json[\"results\"][0][\"category\"]}}"
            },
            {
              "name": "question",
              "value": "={{$json[\"results\"][0][\"question\"]}}"
            },
            {
              "name": "correct",
              "value": "={{$json[\"results\"][0][\"correct_answer\"]}}"
            },
            {
              "name": "incorrect",
              "value": "={{$json[\"results\"][0][\"incorrect_answers\"].join(\", \")}}"
            },
            {
              "name": "messageTitle",
              "value": "\ud83d\udfe2 \u4eca\u65e5\u306e\u30af\u30a4\u30ba\uff08EASY\uff09"
            },
            {
              "name": "messageBody",
              "value": "={{\"\u30ab\u30c6\u30b4\u30ea: \" + $json[\"results\"][0][\"category\"] + \"\\nQ: \" + $json[\"results\"][0][\"question\"] + \"\\n\\n\u6b63\u89e3: \" + $json[\"results\"][0][\"correct_answer\"] + \"\\n\u8aa4\u7b54\u5019\u88dc: \" + $json[\"results\"][0][\"incorrect_answers\"].join(\", \")}}"
            }
          ]
        },
        "options": {},
        "keepOnlySet": true
      },
      "typeVersion": 2
    },
    {
      "id": "0b87ced1-e968-4867-8e81-90d09f03c9f5",
      "name": "HTTP OpenTDB Medium",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        160,
        448
      ],
      "parameters": {
        "url": "https://opentdb.com/api.php?amount=1&difficulty=medium&type=multiple",
        "options": {}
      },
      "typeVersion": 2
    },
    {
      "id": "a3fd7aa8-672c-4420-b5be-b3b978b7e6c2",
      "name": "Set Message Medium",
      "type": "n8n-nodes-base.set",
      "position": [
        384,
        448
      ],
      "parameters": {
        "values": {
          "string": [
            {
              "name": "timestamp",
              "value": "={{(new Date()).toISOString()}}"
            },
            {
              "name": "date",
              "value": "={{(new Date()).toISOString().slice(0,10)}}"
            },
            {
              "name": "difficulty",
              "value": "medium"
            },
            {
              "name": "category",
              "value": "={{$json[\"results\"][0][\"category\"]}}"
            },
            {
              "name": "question",
              "value": "={{$json[\"results\"][0][\"question\"]}}"
            },
            {
              "name": "correct",
              "value": "={{$json[\"results\"][0][\"correct_answer\"]}}"
            },
            {
              "name": "incorrect",
              "value": "={{$json[\"results\"][0][\"incorrect_answers\"].join(\", \")}}"
            },
            {
              "name": "messageTitle",
              "value": "\ud83d\udfe1 \u4eca\u65e5\u306e\u30af\u30a4\u30ba\uff08MEDIUM\uff09"
            },
            {
              "name": "messageBody",
              "value": "={{\"\u30ab\u30c6\u30b4\u30ea: \" + $json[\"results\"][0][\"category\"] + \"\\nQ: \" + $json[\"results\"][0][\"question\"] + \"\\n\\n\u6b63\u89e3: \" + $json[\"results\"][0][\"correct_answer\"] + \"\\n\u8aa4\u7b54\u5019\u88dc: \" + $json[\"results\"][0][\"incorrect_answers\"].join(\", \")}}"
            }
          ]
        },
        "options": {},
        "keepOnlySet": true
      },
      "typeVersion": 2
    },
    {
      "id": "66b5cc85-50ca-4fe6-8b75-1722a8dcd744",
      "name": "HTTP OpenTDB Hard",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        160,
        640
      ],
      "parameters": {
        "url": "https://opentdb.com/api.php?amount=1&difficulty=hard&type=multiple",
        "options": {}
      },
      "typeVersion": 2
    },
    {
      "id": "5692e7f9-0737-4225-b3a0-c49bf9c3d22e",
      "name": "Set Message Hard",
      "type": "n8n-nodes-base.set",
      "position": [
        384,
        640
      ],
      "parameters": {
        "values": {
          "string": [
            {
              "name": "timestamp",
              "value": "={{(new Date()).toISOString()}}"
            },
            {
              "name": "date",
              "value": "={{(new Date()).toISOString().slice(0,10)}}"
            },
            {
              "name": "difficulty",
              "value": "hard"
            },
            {
              "name": "category",
              "value": "={{$json[\"results\"][0][\"category\"]}}"
            },
            {
              "name": "question",
              "value": "={{$json[\"results\"][0][\"question\"]}}"
            },
            {
              "name": "correct",
              "value": "={{$json[\"results\"][0][\"correct_answer\"]}}"
            },
            {
              "name": "incorrect",
              "value": "={{$json[\"results\"][0][\"incorrect_answers\"].join(\", \")}}"
            },
            {
              "name": "messageTitle",
              "value": "\ud83d\udd34 \u4eca\u65e5\u306e\u30af\u30a4\u30ba\uff08HARD\uff09"
            },
            {
              "name": "messageBody",
              "value": "={{\"\u30ab\u30c6\u30b4\u30ea: \" + $json[\"results\"][0][\"category\"] + \"\\nQ: \" + $json[\"results\"][0][\"question\"] + \"\\n\\n\u6b63\u89e3: \" + $json[\"results\"][0][\"correct_answer\"] + \"\\n\u8aa4\u7b54\u5019\u88dc: \" + $json[\"results\"][0][\"incorrect_answers\"].join(\", \")}}"
            }
          ]
        },
        "options": {},
        "keepOnlySet": true
      },
      "typeVersion": 2
    },
    {
      "id": "7ca423c6-44b7-4002-a94a-dbae89ce39a7",
      "name": "Sticky: Template Overview",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1600,
        -128
      ],
      "parameters": {
        "color": 5,
        "width": 900,
        "height": 520,
        "content": "## Daily trivia to Slack + Google Sheets\n\nThis workflow fetches a random multiple-choice trivia question from the Open Trivia Database (OpenTDB), posts it to Slack, and logs it in Google Sheets to build a reusable trivia archive.\n\n**Who it's for**\n- Teams that want a lightweight daily icebreaker in Slack\n- Creators who want to collect trivia questions over time\n\n**How it works**\n1. A Schedule Trigger runs once per day.\n2. A Set node randomly chooses the difficulty (easy / medium / hard).\n3. A Switch node routes to the matching OpenTDB HTTP request.\n4. Each branch reshapes the API response into a common trivia format.\n5. The branches merge into a single stream.\n6. A Slack node posts the trivia to your chosen channel.\n7. A Google Sheets node appends the same data as a new row.\n\n**Setup tips**\n- Connect your own Slack and Google Sheets credentials in the respective nodes.\n- Change the schedule time, Slack channel, and sheet columns to match your workspace."
      },
      "typeVersion": 1
    },
    {
      "id": "833aa505-da7f-4a43-a070-557e4b820c46",
      "name": "Sticky: Trigger & Routing",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -640,
        176
      ],
      "parameters": {
        "width": 520,
        "height": 260,
        "content": "## Trigger and difficulty routing\n\n- **Schedule Trigger** starts the workflow once per day at your chosen time.\n- **Set: Choose Trivia Type** randomly assigns a difficulty value (`easy`, `medium`, or `hard`) to the item.\n- **Switch: triviaType** reads the difficulty and routes the execution to the matching OpenTDB branch.\n\nAdjust the cron schedule and the probability logic in the Set node if you want to favor certain difficulty levels."
      },
      "typeVersion": 1
    },
    {
      "id": "f59b76ab-d7ba-4772-b4d3-3980b5d8977a",
      "name": "Sticky: Easy Branch",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        128,
        -144
      ],
      "parameters": {
        "width": 520,
        "height": 320,
        "content": "## Easy trivia branch\n\n- **HTTP OpenTDB Easy** calls the OpenTDB API with `difficulty=easy` and returns one multiple-choice question.\n- **Set Message Easy** normalizes the response into common fields:\n  - `timestamp`, `date`, `difficulty`, `category`\n  - `question`, `correct`, `incorrect`\n  - `messageTitle` and `messageBody` for Slack.\n\nThis structure matches the other branches so that the Merge node can combine them cleanly."
      },
      "typeVersion": 1
    },
    {
      "id": "0d642e28-3a34-44ba-b4f2-21b3e9f21dc6",
      "name": "Sticky: Medium & Hard Branches",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        64,
        832
      ],
      "parameters": {
        "width": 560,
        "height": 280,
        "content": "## Medium & hard trivia branches\n\n- **HTTP OpenTDB Medium** and **HTTP OpenTDB Hard** call the same OpenTDB endpoint with different `difficulty` values.\n- **Set Message Medium** and **Set Message Hard** reshape each response into the same unified trivia format as the easy branch.\n\nAll three branches produce identical field names, which makes it easy to merge and log them in a single sheet."
      },
      "typeVersion": 1
    },
    {
      "id": "49fe5900-8502-4046-9825-7f7e855ac288",
      "name": "Sticky: Merge, Slack & Sheets",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        800,
        64
      ],
      "parameters": {
        "width": 620,
        "height": 320,
        "content": "## Merge, Slack posting, and Sheets logging\n\n- **Merge** combines items from the easy, medium, and hard branches into a single stream.\n- **Slack: Post Trivia** uses `messageTitle` and `messageBody` to post a nicely formatted question to your Slack channel.\n- **Sheets: Append Trivia** appends one row per trivia question so you build a daily trivia archive over time.\n\nAfter importing this template, open the Slack and Google Sheets nodes and connect your own credentials and resources."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "84fc1dd6-1c85-4609-acf8-5631a2414423",
  "connections": {
    "Merge": {
      "main": [
        [
          {
            "node": "Slack: Post Trivia",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Set: Choose Trivia Type",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Message Easy": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Message Hard": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 2
          }
        ]
      ]
    },
    "HTTP OpenTDB Easy": {
      "main": [
        [
          {
            "node": "Set Message Easy",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP OpenTDB Hard": {
      "main": [
        [
          {
            "node": "Set Message Hard",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Message Medium": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Slack: Post Trivia": {
      "main": [
        [
          {
            "node": "Sheets: Append Trivia",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch: triviaType": {
      "main": [
        [
          {
            "node": "HTTP OpenTDB Easy",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "HTTP OpenTDB Medium",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "HTTP OpenTDB Hard",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP OpenTDB Medium": {
      "main": [
        [
          {
            "node": "Set Message Medium",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set: Choose Trivia Type": {
      "main": [
        [
          {
            "node": "Switch: triviaType",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}