{
  "name": "Typeform testimonial to sprkly",
  "nodes": [
    {
      "id": "596c0a9d-2c3b-489d-bfdc-39ae5d1520b1",
      "name": "Read me first",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -1640,
        -630
      ],
      "parameters": {
        "content": "## Typeform testimonial to sprkly\nKind words from a Typeform become a text 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=typeform-testimonial-to-sprkly\n- A Typeform login and a form with 3 questions: kind words, first name, OK to share\n- A Telegram bot and your chat ID\n- A Google Sheets login and a sheet, for the log of live posts\n\n### Set it up\n1. Add your Typeform login to **New answer** and pick your form.\n2. In **Settings**, copy your 3 questions word for word. Add your accounts as platform:handle and your chat ID.\n3. Add your sprkly key and your bot where a step asks. Put your sheet ID in **Published log settings**.\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 yourself and say yes to sharing.\n- A post waits for your OK and you get a Telegram message. Reject it in sprkly after.",
        "height": 806,
        "width": 560,
        "color": 4
      }
    },
    {
      "id": "89a52c32-a28e-4479-b769-71cd7248c049",
      "name": "Note: check",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -440,
        60
      ],
      "parameters": {
        "content": "## Check the answer\nNo kind words, or no yes to sharing: it stops here.",
        "height": 740,
        "width": 880,
        "color": 7
      }
    },
    {
      "id": "3567eef4-087b-4741-93c1-ee60228ecb22",
      "name": "Note: hold",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        440,
        60
      ],
      "parameters": {
        "content": "## Hold for your OK\nsprkly emails you an Approve link. Nothing goes out before you say yes.",
        "height": 740,
        "width": 220,
        "color": 7
      }
    },
    {
      "id": "8aa985dd-30f1-4422-bed6-0ddfe4602bb6",
      "name": "Note: tell you",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        660,
        60
      ],
      "parameters": {
        "content": "## Tell you\nOne message per answer. Nothing posts again.",
        "height": 740,
        "width": 440,
        "color": 7
      }
    },
    {
      "id": "46b9374d-de77-4405-8cdf-fe050245ef53",
      "name": "New answer",
      "type": "n8n-nodes-base.typeformTrigger",
      "typeVersion": 1.1,
      "position": [
        -400,
        320
      ],
      "parameters": {
        "authentication": "accessToken",
        "formId": "",
        "simplifyAnswers": true,
        "onlyAnswers": false
      }
    },
    {
      "id": "bf4f4211-5f79-41f9-961c-c6d40e89ee90",
      "name": "Settings",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -180,
        320
      ],
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "f1",
              "name": "wordsQuestion",
              "type": "string",
              "value": "What do you like about us?"
            },
            {
              "id": "f2",
              "name": "nameQuestion",
              "type": "string",
              "value": "What is your first name?"
            },
            {
              "id": "f3",
              "name": "shareQuestion",
              "type": "string",
              "value": "Can we share your words on social media?"
            },
            {
              "id": "f4",
              "name": "accounts",
              "type": "string",
              "value": "facebook:Your Page, threads:yourhandle, linkedin:Your Name"
            },
            {
              "id": "f5",
              "name": "hoursFromNow",
              "type": "number",
              "value": 24
            },
            {
              "id": "f6",
              "name": "telegramChatId",
              "type": "string",
              "value": "YOUR_CHAT_ID"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      }
    },
    {
      "id": "cfebd3bd-72af-402b-9ff4-6134b1726ce0",
      "name": "Pick the answers",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        40,
        320
      ],
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "f1",
              "name": "words",
              "type": "string",
              "value": "={{ String((($json.form_response || {}).answers || {})[$json.wordsQuestion] || '').trim() }}"
            },
            {
              "id": "f2",
              "name": "firstName",
              "type": "string",
              "value": "={{ String((($json.form_response || {}).answers || {})[$json.nameQuestion] || '').trim() }}"
            },
            {
              "id": "f3",
              "name": "canShare",
              "type": "boolean",
              "value": "={{ (($json.form_response || {}).answers || {})[$json.shareQuestion] === true }}"
            },
            {
              "id": "f4",
              "name": "responseToken",
              "type": "string",
              "value": "={{ String(($json.form_response || {}).token || '') }}"
            }
          ]
        },
        "includeOtherFields": false,
        "options": {}
      }
    },
    {
      "id": "f83cea0f-68c5-434f-8348-db4a812707af",
      "name": "Kind words, OK to share?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        260,
        320
      ],
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "loose",
            "version": 2
          },
          "conditions": [
            {
              "id": "c1",
              "leftValue": "={{ $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": "a1b12be1-2331-4a3c-bc15-0d039796286d",
      "name": "Hold post for your OK",
      "type": "n8n-nodes-sprkly.sprkly",
      "typeVersion": 1.1,
      "position": [
        480,
        320
      ],
      "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) || 1 }).toISO() }}",
        "output": "resultRow",
        "additionalFields": {
          "postType": "proof",
          "requiresApproval": true,
          "approvalNote": "={{ 'Testimonial from ' + ($json.firstName || 'a customer') }}",
          "externalId": "={{ 'typeform-' + $json.responseToken }}",
          "requireExternalId": true
        }
      }
    },
    {
      "id": "97ceadc4-c9d4-444d-aaa3-77bf0858bc34",
      "name": "Write the message",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        700,
        320
      ],
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "f1",
              "name": "message",
              "type": "string",
              "value": "={{ $json.ok === true ? 'Waiting for your OK: ' + 'testimonial from ' + ($('Pick the answers').item.json.firstName || 'a customer') + '\\nGoes out: ' + ($json.scheduledFor ? DateTime.fromISO($json.scheduledFor).setZone($now.zoneName).toFormat('d LLL yyyy, HH:mm') + ' ' + $now.zoneName : 'at the time you set') + '\\nApprove it from the email sprkly sent you.' + '\\nOpen it in sprkly: ' + 'https://sprkly.app/schedule?utm_source=n8n&utm_medium=workflow&utm_campaign=typeform-testimonial-to-sprkly&post=' + encodeURIComponent(String($json.postId || '').split(',')[0].trim()) : 'Not scheduled: ' + 'testimonial from ' + ($('Pick the answers').item.json.firstName || 'a customer') + '\\nWhy: ' + (typeof $json.error === 'string' && $json.error ? $json.error : ($json.error && $json.error.message) || $json.problem || 'sprkly did not give a reason.') + '\\nNothing was posted, and nothing will try again.' }}"
            }
          ]
        },
        "includeOtherFields": false,
        "options": {}
      }
    },
    {
      "id": "e06ddf36-b34c-465c-9247-6762d0bd3830",
      "name": "Send to Telegram",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        920,
        320
      ],
      "parameters": {
        "chatId": "={{ $('Settings').first().json.telegramChatId }}",
        "text": "={{ $json.message }}",
        "additionalFields": {
          "appendAttribution": false
        }
      }
    },
    {
      "name": "Note: automatic published post log",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "id": "0ded5bf9-02c4-58ab-8935-f833f9071a78",
      "position": [
        -1000,
        -630
      ],
      "parameters": {
        "content": "## Log posts as they go live\n\nSet **Spreadsheet ID** in **Published log settings**. Use the same Google Sheets credential in the two log steps and your sprkly API credential on **When this workflow's post goes live**.\n\nThe workflow checks each minute for its published posts. It creates **Published Posts** and its headers as needed, then writes one row per Post ID. This branch runs after publication. It leaves the scheduling and source status branches intact.",
        "height": 215,
        "width": 520,
        "color": 5
      }
    },
    {
      "name": "When this workflow's post goes live",
      "type": "n8n-nodes-sprkly.sprklyTrigger",
      "typeVersion": 1,
      "id": "84a86424-c24e-53cb-900a-0dd8648bab92",
      "position": [
        -1000,
        -380
      ],
      "parameters": {
        "pollTimes": {
          "item": [
            {
              "mode": "everyMinute"
            }
          ]
        },
        "event": "postPublished",
        "externalIdPrefix": "typeform-",
        "stripPrefix": false
      }
    },
    {
      "name": "Build published log rows",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "id": "fb7479cb-cc75-54cb-96a8-b649401fd404",
      "position": [
        -760,
        -380
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "const prefix = \"typeform-\";\nconst text = value => typeof value === 'string' || typeof value === 'number' ? String(value).trim() : '';\nconst values = input => Array.isArray(input) ? input.map(text).filter(Boolean) : [];\nconst rows = new Map();\n\nfor (const [index, item] of $input.all().entries()) {\n  const post = item.json;\n  const id = text(post.id);\n  const externalId = text(post.externalId);\n  if (!id || post.deleted || !['posted', 'published'].includes(post.status) ||\n      !externalId.startsWith(prefix) || externalId.length === prefix.length) continue;\n\n  const platforms = values(post.platforms);\n  const accounts = values(post.profileIds);\n  const suffix = ':' + platforms[0] + ':' + accounts[0];\n  const source = platforms.length && accounts.length && externalId.endsWith(suffix)\n    ? externalId.slice(0, -suffix.length) : externalId;\n  if (source.length <= prefix.length) continue;\n  const previous = rows.get(id)?.json;\n  rows.set(id, {\n    json: {\n      'Post ID': id,\n      Status: 'Published',\n      'Published At': text(post.publishedAt) || previous?.['Published At'] || '',\n      Platform: platforms.join(', '),\n      'Account ID': accounts.join(', '),\n      'Source ID': source,\n      'External ID': externalId,\n      'Live URL': text(post.permalink) || text(post.link) || previous?.['Live URL'] || '',\n      'Sprkly URL': 'https://sprkly.app/schedule?utm_source=n8n&utm_medium=workflow&utm_campaign=typeform-testimonial-to-sprkly&post=' + encodeURIComponent(id),\n    },\n    pairedItem: index,\n  });\n}\nreturn [...rows.values()];"
      }
    },
    {
      "name": "Published log settings",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "id": "3d9a0ccd-ac0a-50d3-af09-b8b1c0ed0966",
      "position": [
        -520,
        -380
      ],
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "a6f63948-a99b-53ec-8286-75ed3929b983",
              "name": "Spreadsheet ID",
              "type": "string",
              "value": ""
            },
            {
              "id": "66e7b77b-c11f-5dda-b988-a3db227b3753",
              "name": "Tab name",
              "type": "string",
              "value": "Published Posts"
            }
          ]
        },
        "includeOtherFields": false,
        "options": {}
      },
      "executeOnce": true
    },
    {
      "name": "Ensure published log tab",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "id": "44f2541d-249a-59df-bcb3-b257e8f9084d",
      "position": [
        -280,
        -380
      ],
      "parameters": {
        "resource": "sheet",
        "operation": "create",
        "documentId": {
          "__rl": true,
          "value": "={{ String($json[\"Spreadsheet ID\"]).trim() }}",
          "mode": "id"
        },
        "title": "={{ String($json[\"Tab name\"]).trim() }}",
        "options": {}
      },
      "alwaysOutputData": true,
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000
    },
    {
      "name": "Restore published log rows",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "id": "96b4141e-6421-5cf6-860f-e537a3117dd6",
      "position": [
        -40,
        -380
      ],
      "parameters": {
        "mode": "runOnceForAllItems",
        "jsCode": "// Create Sheet has one output for the setup call. Restore every publication in the trigger batch.\nreturn $('Build published log rows').all().map(({ json }) => ({ json, pairedItem: 0 }));"
      }
    },
    {
      "name": "Upsert published post log",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.7,
      "id": "e8103443-73dc-58a7-a238-e71f8e650a5d",
      "position": [
        200,
        -380
      ],
      "parameters": {
        "resource": "sheet",
        "operation": "appendOrUpdate",
        "documentId": {
          "__rl": true,
          "value": "={{ String($(\"Published log settings\").first().json[\"Spreadsheet ID\"]).trim() }}",
          "mode": "id"
        },
        "sheetName": {
          "__rl": true,
          "value": "={{ String($(\"Published log settings\").first().json[\"Tab name\"]).trim() }}",
          "mode": "name"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "matchingColumns": [
            "Post ID"
          ],
          "schema": []
        },
        "options": {
          "cellFormat": "RAW",
          "handlingExtraData": "insertInNewColumn",
          "useAppend": true
        }
      },
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 3000
    },
    {
      "id": "6559ade7-2278-4faa-b8e8-ea86117f9496",
      "name": "When this workflow fails",
      "type": "n8n-nodes-base.errorTrigger",
      "typeVersion": 1,
      "position": [
        -1600,
        256
      ],
      "parameters": {}
    },
    {
      "id": "47344e34-71c1-4c95-bca5-06e60d213554",
      "name": "Write the failure alert",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        -1380,
        256
      ],
      "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": "73e560d7-8797-4c09-ac10-c382f5f40838",
      "name": "Send the failure alert",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        -1160,
        256
      ],
      "parameters": {
        "chatId": "={{ $json.telegramChatId }}",
        "text": "={{ $json.message }}",
        "additionalFields": {
          "appendAttribution": false
        }
      }
    }
  ],
  "connections": {
    "New answer": {
      "main": [
        [
          {
            "node": "Settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Settings": {
      "main": [
        [
          {
            "node": "Pick the answers",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Pick the answers": {
      "main": [
        [
          {
            "node": "Kind words, OK to share?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Kind words, OK to share?": {
      "main": [
        [
          {
            "node": "Hold post for your OK",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Hold post for your OK": {
      "main": [
        [
          {
            "node": "Write the message",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write the message": {
      "main": [
        [
          {
            "node": "Send to Telegram",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When this workflow's post goes live": {
      "main": [
        [
          {
            "node": "Build published log rows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Build published log rows": {
      "main": [
        [
          {
            "node": "Published log settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Published log settings": {
      "main": [
        [
          {
            "node": "Ensure published log tab",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ensure published log tab": {
      "main": [
        [
          {
            "node": "Restore published log rows",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Restore published log rows": {
      "main": [
        [
          {
            "node": "Upsert published post log",
            "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"
  }
}
