{
  "name": "Review triage from Typeform",
  "nodes": [
    {
      "id": "6cb6427f-8a6e-4f4f-9db5-abd96742819f",
      "name": "Read me first",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -688,
        -320
      ],
      "parameters": {
        "content": "## Review triage from Typeform\nEach review from your Typeform is logged and sorted. Safety issues and low scores reach you at once. Happy reviews you may share become a post that waits for your OK.\n\n### You need\n- The sprkly node: Settings, Community nodes, install `n8n-nodes-sprkly` (self-hosted n8n)\n- A sprkly API key: https://sprkly.app/docs/api?utm_source=n8n&utm_medium=workflow&utm_campaign=review-feedback-triage\n- A Typeform login and a review form with 4 questions: a score, what happened, first name, OK to share (yes or no)\n- A Google Sheets login and a Reviews tab with: Received At, Response ID, Score, Priority, First Name, Review\n- A Telegram bot and your chat ID\n\n### Set it up\n1. Add your Typeform login to **New review** and pick your form.\n2. In **Settings**, copy your 4 questions word for word. Set the top score (5 or 10), your chat ID and the accounts for shared reviews, as platform:handle.\n3. Pick your sheet in **Log every review**. Add your sprkly key to **Hold a post for your OK**.\n4. Failure alert: put your chat ID in **Write the failure alert** and your bot in **Send the failure alert**. Then in Workflow settings, set Error workflow to this workflow.\n\n### Test it\n- Fill in the form with a low score. You get a message to reply.\n- Fill it in again with a top score and say yes to sharing. A post waits for your OK in sprkly. Reject it after.",
        "height": 910,
        "width": 560,
        "color": 4
      }
    },
    {
      "id": "093d1ad4-b58e-4348-b2d3-58197946725f",
      "name": "Note: sort",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -48,
        -120
      ],
      "parameters": {
        "content": "## Log and sort\nEvery review is logged with its words as written. Words like allergy, unsafe, hurt, fraud or privacy make it urgent, whatever the score.",
        "height": 560,
        "width": 1240,
        "color": 7
      }
    },
    {
      "id": "0cac6210-d800-4909-993c-600ea2bdf2de",
      "name": "Note: act",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1272,
        -320
      ],
      "parameters": {
        "content": "## Act on it\nUrgent and low scores reach you now. A happy review becomes a post only if the person said yes, and only after you approve it. Nobody gets an automatic reply.",
        "height": 1360,
        "width": 1000,
        "color": 7
      }
    },
    {
      "id": "b54a7572-9e71-4c68-a12d-ee0e932991bc",
      "name": "New review",
      "type": "n8n-nodes-base.typeformTrigger",
      "typeVersion": 1.1,
      "position": [
        0,
        100
      ],
      "parameters": {
        "authentication": "accessToken",
        "formId": "",
        "simplifyAnswers": true,
        "onlyAnswers": false
      }
    },
    {
      "id": "0108f99f-c487-4a80-961b-76721bdd4b2d",
      "name": "Settings",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        240,
        100
      ],
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "f1",
              "name": "scoreQuestion",
              "type": "string",
              "value": "How would you rate us?"
            },
            {
              "id": "f2",
              "name": "textQuestion",
              "type": "string",
              "value": "What happened?"
            },
            {
              "id": "f3",
              "name": "nameQuestion",
              "type": "string",
              "value": "What is your first name?"
            },
            {
              "id": "f4",
              "name": "shareQuestion",
              "type": "string",
              "value": "Can we share your words on social media?"
            },
            {
              "id": "f5",
              "name": "topScore",
              "type": "number",
              "value": 5
            },
            {
              "id": "f6",
              "name": "accounts",
              "type": "string",
              "value": "facebook:Your Page, threads:yourhandle"
            },
            {
              "id": "f7",
              "name": "hoursFromNow",
              "type": "number",
              "value": 24
            },
            {
              "id": "f8",
              "name": "telegramChatId",
              "type": "string",
              "value": "YOUR_CHAT_ID"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      }
    },
    {
      "id": "920f980b-a213-4972-953f-cc3c3f8aa8be",
      "name": "Read the answers",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        480,
        100
      ],
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "f1",
              "name": "score",
              "type": "number",
              "value": "={{ Number((($json.form_response || {}).answers || {})[$json.scoreQuestion]) || 0 }}"
            },
            {
              "id": "f2",
              "name": "words",
              "type": "string",
              "value": "={{ String((($json.form_response || {}).answers || {})[$json.textQuestion] || '').trim() }}"
            },
            {
              "id": "f3",
              "name": "firstName",
              "type": "string",
              "value": "={{ String((($json.form_response || {}).answers || {})[$json.nameQuestion] || '').trim() }}"
            },
            {
              "id": "f4",
              "name": "canShare",
              "type": "boolean",
              "value": "={{ (($json.form_response || {}).answers || {})[$json.shareQuestion] === true }}"
            },
            {
              "id": "f5",
              "name": "responseToken",
              "type": "string",
              "value": "={{ String(($json.form_response || {}).token || '') }}"
            }
          ]
        },
        "includeOtherFields": false,
        "options": {}
      }
    },
    {
      "id": "a8956d0d-2b04-4207-a8bb-734ba94c65c4",
      "name": "Sort by urgency",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        720,
        100
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const s = $('Settings').first().json;\nconst top = Number(s.topScore) || 5;\n// Words that need a person today, whatever the score.\nconst urgent = /allerg|unsafe|injur|hurt|sick|fraud|scam|privacy|harass|threat|lawyer|police/i;\nreturn $input.all().map(({ json: r }) => {\n  const priority = urgent.test(r.words) ? 'Urgent' : r.score > 0 && r.score <= top * 0.4 ? 'Low score' : r.score >= top * 0.8 ? 'Happy' : 'Neutral';\n  return { json: { ...r, priority } };\n});"
      }
    },
    {
      "id": "ab177736-760e-4e2c-aca0-a918439d4860",
      "name": "Log every review",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "position": [
        960,
        -60
      ],
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "",
          "mode": "url"
        },
        "sheetName": {
          "__rl": true,
          "value": "Reviews",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "Received At": "={{ $now.toISO() }}",
            "Response ID": "={{ $json.responseToken }}",
            "Score": "={{ $json.score }}",
            "Priority": "={{ $json.priority }}",
            "First Name": "={{ $json.firstName }}",
            "Review": "={{ $json.words }}"
          },
          "matchingColumns": [],
          "schema": [
            {
              "id": "Received At",
              "displayName": "Received At",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Response ID",
              "displayName": "Response ID",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Score",
              "displayName": "Score",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Priority",
              "displayName": "Priority",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "First Name",
              "displayName": "First Name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "Review",
              "displayName": "Review",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "4a2d48df-5f2c-431e-93f5-86242a1233aa",
      "name": "Needs a reply?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        960,
        140
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "c1",
              "leftValue": "={{ ['Urgent', 'Low score'].includes($json.priority) }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "looseTypeValidation": true,
        "options": {}
      }
    },
    {
      "id": "c45573ef-b678-40a4-8664-fe992ab8d5f9",
      "name": "Tell you to reply",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1320,
        140
      ],
      "parameters": {
        "chatId": "={{ $('Settings').first().json.telegramChatId }}",
        "text": "={{ ($json.priority === 'Urgent' ? 'Urgent review. Please reply today.' : 'Low score: ' + $json.score + ' of ' + $('Settings').first().json.topScore + '.') + '\\n\\nFrom: ' + ($json.firstName || 'no name') + '\\n' + ($json.words || '(no words)') + '\\n\\nThis workflow does not reply for you.' }}",
        "additionalFields": {
          "appendAttribution": false
        }
      }
    },
    {
      "id": "7656d181-5c61-4b13-ab39-820d3cf3965c",
      "name": "Happy and OK to share?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        960,
        340
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "c1",
              "leftValue": "={{ $json.priority === 'Happy' && $json.canShare === true && $json.words.length > 0 && $json.responseToken.length > 0 }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "looseTypeValidation": true,
        "options": {}
      }
    },
    {
      "id": "2b352ecb-50ef-41d1-9def-75a4aa5eba42",
      "name": "Hold a post for your OK",
      "type": "n8n-nodes-sprkly.sprkly",
      "typeVersion": 1.1,
      "position": [
        1320,
        340
      ],
      "parameters": {
        "resource": "post",
        "operation": "create",
        "accountMode": "name",
        "accountNames": "={{ $('Settings').first().json.accounts }}",
        "caption": "={{ '\"' + $json.words + '\"' + ($json.firstName ? '\\n\\n' + $json.firstName : '') }}",
        "scheduledTime": "={{ $now.plus({ hours: Number($('Settings').first().json.hoursFromNow) || 24 }).toISO() }}",
        "output": "resultRow",
        "additionalFields": {
          "postType": "proof",
          "requiresApproval": true,
          "approvalNote": "={{ 'Review from ' + ($json.firstName || 'a customer') }}",
          "externalId": "={{ 'review-' + $json.responseToken }}",
          "requireExternalId": true
        }
      }
    },
    {
      "id": "cb1d673c-9116-4ebe-97aa-9b36c823e8ef",
      "name": "Tell you it waits",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1560,
        340
      ],
      "parameters": {
        "chatId": "={{ $('Settings').first().json.telegramChatId }}",
        "text": "={{ $json.ok === true ? 'A happy review waits for your OK in sprkly.\\nOpen it: https://sprkly.app/schedule?utm_source=n8n&utm_medium=workflow&utm_campaign=review-feedback-triage&post=' + encodeURIComponent(String($json.postId || '').split(',')[0].trim()) : 'A happy review was not turned into a post. Why: ' + (typeof $json.error === 'string' && $json.error ? $json.error : 'sprkly did not give a reason.') }}",
        "additionalFields": {
          "appendAttribution": false
        }
      }
    },
    {
      "id": "2eb62561-c1c6-45a6-84fa-756a8456107f",
      "name": "When this workflow fails",
      "type": "n8n-nodes-base.errorTrigger",
      "typeVersion": 1,
      "position": [
        -648,
        670
      ],
      "parameters": {}
    },
    {
      "id": "327cdcc9-df4a-448b-a8d7-222791f2ce4c",
      "name": "Write the failure alert",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -428,
        670
      ],
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "f1",
              "name": "telegramChatId",
              "type": "string",
              "value": "YOUR_TELEGRAM_CHAT_ID"
            },
            {
              "id": "f2",
              "name": "message",
              "type": "string",
              "value": "={{ 'A workflow stopped.\\n\\nWorkflow: ' + (($json.workflow || {}).name || 'unknown') + '\\nFailed step: ' + (($json.execution || {}).lastNodeExecuted || 'unknown') + '\\nWhy: ' + String((($json.execution || {}).error || {}).message || 'n8n did not give a reason.').slice(0, 300) + (($json.execution || {}).url ? '\\nOpen the run: ' + $json.execution.url : '') }}"
            }
          ]
        },
        "includeOtherFields": false,
        "options": {}
      }
    },
    {
      "id": "787c4c6e-0aee-447d-b9a1-d0dd135a4208",
      "name": "Send the failure alert",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        -208,
        670
      ],
      "parameters": {
        "chatId": "={{ $json.telegramChatId }}",
        "text": "={{ $json.message }}",
        "additionalFields": {
          "appendAttribution": false
        }
      }
    }
  ],
  "connections": {
    "New review": {
      "main": [
        [
          {
            "node": "Settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Settings": {
      "main": [
        [
          {
            "node": "Read the answers",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Read the answers": {
      "main": [
        [
          {
            "node": "Sort by urgency",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sort by urgency": {
      "main": [
        [
          {
            "node": "Log every review",
            "type": "main",
            "index": 0
          },
          {
            "node": "Needs a reply?",
            "type": "main",
            "index": 0
          },
          {
            "node": "Happy and OK to share?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Needs a reply?": {
      "main": [
        [
          {
            "node": "Tell you to reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Happy and OK to share?": {
      "main": [
        [
          {
            "node": "Hold a post for your OK",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Hold a post for your OK": {
      "main": [
        [
          {
            "node": "Tell you it waits",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When this workflow fails": {
      "main": [
        [
          {
            "node": "Write the failure alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write the failure alert": {
      "main": [
        [
          {
            "node": "Send the failure alert",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "tags": []
}
