{
  "id": "AILeadApprovalPublic",
  "name": "02 - Telegram Approval & Email Dispatcher",
  "nodes": [
    {
      "parameters": {
        "updates": [
          "callback_query",
          "message"
        ],
        "additionalFields": {
          "chatIds": "OWNER_CHAT_ID",
          "userIds": "OWNER_CHAT_ID"
        }
      },
      "id": "936b8e0c-b922-4a67-86c7-51d64e92ad86",
      "name": "Telegram Owner Response",
      "type": "n8n-nodes-base.telegramTrigger",
      "typeVersion": 1.4,
      "position": [
        -1180,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "const update = $json;\nif (update.callback_query) {\n  const query = update.callback_query;\n  const [action, leadId] = String(query.data || '').split('|');\n  return [{ json: {\n    event_type: 'CALLBACK',\n    action: String(action || '').toUpperCase(),\n    lead_id: leadId || '',\n    callback_query_id: query.id,\n    chat_id: String(query.message?.chat?.id || ''),\n    telegram_message_id: String(query.message?.message_id || ''),\n    owner_user_id: String(query.from?.id || '')\n  } }];\n}\nif (update.message) {\n  const message = update.message;\n  return [{ json: {\n    event_type: 'EDIT_MESSAGE',\n    edited_reply: String(message.text || '').trim(),\n    edit_prompt_message_id: String(message.reply_to_message?.message_id || ''),\n    chat_id: String(message.chat?.id || ''),\n    telegram_message_id: String(message.message_id || ''),\n    owner_user_id: String(message.from?.id || '')\n  } }];\n}\nreturn [];"
      },
      "id": "d1ced186-dd7c-4196-a699-1dba1aecf11d",
      "name": "Normalize Telegram Update",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -940,
        300
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "ee21c1fa-c5b5-43ee-8f9d-845940aa4514",
              "leftValue": "={{ $json.event_type }}",
              "rightValue": "CALLBACK",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "b8755f5f-f56b-4eed-868c-4eef20ac4f05",
      "name": "Is Button Callback?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        -700,
        300
      ]
    },
    {
      "parameters": {
        "resource": "callback",
        "operation": "answerQuery",
        "queryId": "={{ $('Normalize Telegram Update').item.json.callback_query_id }}",
        "additionalFields": {
          "text": "Processing your decision…",
          "cache_time": 0
        }
      },
      "id": "09ad565b-f2f8-4be5-ad31-e80af8e33438",
      "name": "Acknowledge Button Click",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        -450,
        170
      ]
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "resource": "sheet",
        "operation": "read",
        "documentId": {
          "mode": "id",
          "value": "SPREADSHEET_ID"
        },
        "sheetName": {
          "mode": "id",
          "value": "REPORT_SHEET_ID"
        },
        "filtersUI": {
          "values": [
            {
              "lookupColumn": "lead_id",
              "lookupValue": "={{ $('Normalize Telegram Update').item.json.lead_id }}"
            }
          ]
        },
        "combineFilters": "AND",
        "options": {
          "returnAllMatches": "returnFirstMatch"
        }
      },
      "id": "ef4ae7fb-0bfb-4cb3-92b3-c7d20be460e7",
      "name": "Find Report by Lead ID",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 3,
      "position": [
        -190,
        170
      ],
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "jsCode": "const event = $('Normalize Telegram Update').item.json;\nconst row = $json;\nconst now = new Date();\nconst created = new Date(row.created_at || 0);\nconst expired = !Number.isFinite(created.getTime()) || now.getTime() - created.getTime() > 24 * 60 * 60 * 1000;\nconst knownAction = ['APPROVE', 'EDIT', 'REJECT'].includes(event.action);\nconst pending = row.approval_status === 'PENDING';\nconst escapeHtml = (value) => String(value ?? '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');\nlet actionState = event.action;\nlet ownerMessage = '';\nif (!row.lead_id) {\n  actionState = 'INVALID';\n  ownerMessage = '⚠️ I could not find that lead in the Workflow Report.';\n} else if (expired && pending) {\n  actionState = 'INVALID';\n  row.approval_status = 'EXPIRED';\n  row.approval_action = 'EXPIRED';\n  ownerMessage = `⌛ The approval window for ${row.full_name} has expired.`;\n} else if (!pending) {\n  actionState = 'INVALID';\n  ownerMessage = `ℹ️ This lead is already ${row.approval_status}. No second action was taken.`;\n} else if (!knownAction) {\n  actionState = 'INVALID';\n  ownerMessage = '⚠️ That Telegram action is not recognized.';\n}\nreturn [{ json: { ...row, _action: actionState, _action_valid: actionState !== 'INVALID', _owner_message: ownerMessage, _safe_full_name: escapeHtml(row.full_name), _safe_reply_subject: escapeHtml(row.reply_subject), _safe_proposed_reply: escapeHtml(row.proposed_reply), _chat_id: event.chat_id, _telegram_message_id: event.telegram_message_id, last_updated_at: now.toISOString() } }];"
      },
      "id": "db121fa5-5f7a-448a-b30d-485948ed497e",
      "name": "Validate Callback State",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        60,
        170
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "7d3b2e6f-f3bd-42f5-b3d8-bca674d24aaa",
              "leftValue": "={{ $json._action_valid }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "90608444-89b1-4ded-a370-0a580a002f4a",
      "name": "Callback Is Actionable?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        300,
        170
      ]
    },
    {
      "parameters": {
        "resource": "message",
        "operation": "editMessageText",
        "chatId": "={{ $('Validate Callback State').item.json._chat_id }}",
        "messageId": "={{ $('Validate Callback State').item.json._telegram_message_id }}",
        "text": "=⏳ Processing {{ $('Validate Callback State').item.json._action.toLowerCase() }} for {{ $('Validate Callback State').item.json._safe_full_name }}…",
        "replyMarkup": "none",
        "additionalFields": {
          "parse_mode": "HTML",
          "appendAttribution": false
        }
      },
      "id": "7ec82352-c32e-47dd-967c-882c67373a9b",
      "name": "Lock Review Message",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        540,
        100
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "c72c81bf-c3ff-49b1-803e-aad63eb62b42",
              "leftValue": "={{ $('Validate Callback State').item.json._action }}",
              "rightValue": "APPROVE",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "2ee0fd1e-9246-40e0-9938-b27200ace440",
      "name": "Approve Selected?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        780,
        100
      ]
    },
    {
      "parameters": {
        "jsCode": "const row = $('Validate Callback State').item.json;\nreturn [{ json: { ...row, final_reply: row.proposed_reply, approval_action: 'APPROVED', approval_status: 'AUTHORISED', last_updated_at: new Date().toISOString() } }];"
      },
      "id": "7271489b-5b2e-4f4b-a2ac-31dbc82fb11f",
      "name": "Use Approved Reply",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1040,
        -20
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "86b69688-1b09-4465-8d84-c944cc139147",
              "leftValue": "={{ $('Validate Callback State').item.json._action }}",
              "rightValue": "EDIT",
              "operator": {
                "type": "string",
                "operation": "equals"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "6211fc4f-97ba-4d49-8121-d4dbc294aef4",
      "name": "Edit Selected?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        1040,
        180
      ]
    },
    {
      "parameters": {
        "resource": "message",
        "operation": "sendMessage",
        "chatId": "OWNER_CHAT_ID",
        "text": "=✏️ EDIT REPLY FOR {{ $('Validate Callback State').item.json._safe_full_name }}\n\nSubject: {{ $('Validate Callback State').item.json._safe_reply_subject }}\n\nCurrent draft:\n{{ $('Validate Callback State').item.json._safe_proposed_reply }}\n\nReply directly to this message with the complete revised email body. Your reply will be sent after validation.",
        "replyMarkup": "forceReply",
        "forceReply": {
          "force_reply": true,
          "selective": true
        },
        "additionalFields": {
          "parse_mode": "HTML",
          "appendAttribution": false
        }
      },
      "id": "18299488-a3c8-45d4-a172-700d79d81505",
      "name": "Request Edited Reply",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1290,
        120
      ]
    },
    {
      "parameters": {
        "jsCode": "const row = $('Validate Callback State').item.json;\nconst response = $json.result ?? $json;\nreturn [{ json: { ...row, approval_action: 'EDIT_REQUESTED', approval_status: 'AWAITING_EDIT', telegram_context: String(response.message_id || ''), last_updated_at: new Date().toISOString() } }];"
      },
      "id": "8ee13a91-e3b4-46a1-b2db-e83e47c19342",
      "name": "Save Edit Prompt Context",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1530,
        120
      ]
    },
    {
      "parameters": {
        "jsCode": "const row = $('Validate Callback State').item.json;\nreturn [{ json: { ...row, final_reply: '', approval_action: 'REJECTED', approval_status: 'REJECTED', email_delivery: JSON.stringify({ provider: 'SMTP', status: 'NOT_SENT' }), last_updated_at: new Date().toISOString() } }];"
      },
      "id": "d221d4df-66bc-473c-8562-bd52e11ddb2b",
      "name": "Record Rejection",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1290,
        280
      ]
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "resource": "sheet",
        "operation": "read",
        "documentId": {
          "mode": "id",
          "value": "SPREADSHEET_ID"
        },
        "sheetName": {
          "mode": "id",
          "value": "REPORT_SHEET_ID"
        },
        "filtersUI": {
          "values": [
            {
              "lookupColumn": "telegram_context",
              "lookupValue": "={{ $('Normalize Telegram Update').item.json.edit_prompt_message_id }}"
            }
          ]
        },
        "combineFilters": "AND",
        "options": {
          "returnAllMatches": "returnFirstMatch"
        }
      },
      "id": "89b29738-a6e0-47bd-86ae-5727c550e1e0",
      "name": "Find Report by Edit Prompt",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 3,
      "position": [
        -450,
        470
      ],
      "alwaysOutputData": true
    },
    {
      "parameters": {
        "jsCode": "const event = $('Normalize Telegram Update').item.json;\nconst row = $json;\nconst now = new Date();\nconst created = new Date(row.created_at || 0);\nconst expired = !Number.isFinite(created.getTime()) || now.getTime() - created.getTime() > 24 * 60 * 60 * 1000;\nconst valid = Boolean(row.lead_id && row.approval_status === 'AWAITING_EDIT' && event.edited_reply.length >= 10 && !expired);\nlet ownerMessage = '';\nif (!row.lead_id) ownerMessage = '⚠️ Reply directly to the bot’s edit prompt so I can identify the lead.';\nelse if (expired) { row.approval_status = 'EXPIRED'; row.approval_action = 'EXPIRED'; ownerMessage = `⌛ The edit window for ${row.full_name} has expired.`; }\nelse if (row.approval_status !== 'AWAITING_EDIT') ownerMessage = `ℹ️ This lead is already ${row.approval_status}.`;\nelse if (event.edited_reply.length < 10) ownerMessage = '⚠️ The revised reply is too short. Please reply again with the complete email body.';\nreturn [{ json: { ...row, _edit_valid: valid, _edited_reply: event.edited_reply, _owner_message: ownerMessage, last_updated_at: now.toISOString() } }];"
      },
      "id": "9f525a9e-7bea-4efb-861b-624fb290153d",
      "name": "Validate Edited Reply",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        -190,
        470
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict",
            "version": 3
          },
          "conditions": [
            {
              "id": "a8649035-090e-40ec-8be4-352043005134",
              "leftValue": "={{ $json._edit_valid }}",
              "rightValue": "",
              "operator": {
                "type": "boolean",
                "operation": "true",
                "singleValue": true
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "2024d862-706a-4a8d-af6a-3837ad1954cb",
      "name": "Edited Reply Is Valid?",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2.2,
      "position": [
        60,
        470
      ]
    },
    {
      "parameters": {
        "jsCode": "const row = $('Validate Edited Reply').item.json;\nreturn [{ json: { ...row, final_reply: row._edited_reply, approval_action: 'EDITED', approval_status: 'AUTHORISED', last_updated_at: new Date().toISOString() } }];"
      },
      "id": "73136f75-f581-4fba-92e5-caa871a15137",
      "name": "Use Edited Reply",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        300,
        400
      ]
    },
    {
      "parameters": {
        "jsCode": "const row = $json;\nreturn [{ json: { ...row, email_to: row.business_email, email_subject: row.reply_subject, email_body: row.final_reply } }];"
      },
      "id": "0bd1d523-2a22-44df-b84e-eebbc8a73c40",
      "name": "Prepare Email Payload",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1540,
        -40
      ]
    },
    {
      "parameters": {
        "resource": "email",
        "operation": "send",
        "fromEmail": "SENDER_NAME <VERIFIED_FROM_ADDRESS>",
        "toEmail": "={{ $json.email_to }}",
        "subject": "={{ $json.email_subject }}",
        "emailFormat": "text",
        "text": "={{ $json.email_body }}",
        "options": {
          "appendAttribution": false
        }
      },
      "id": "31944485-7516-4170-882a-52f13cce456d",
      "name": "Send via SMTP",
      "type": "n8n-nodes-base.emailSend",
      "typeVersion": 2.1,
      "position": [
        1800,
        -100
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 5000,
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "resource": "message",
        "operation": "send",
        "sendTo": "={{ $json.email_to }}",
        "subject": "={{ $json.email_subject }}",
        "emailType": "text",
        "message": "={{ $json.email_body }}",
        "options": {
          "appendAttribution": false
        }
      },
      "id": "da629c47-bf83-410b-b43d-33f42ab1e18b",
      "name": "Send via Gmail",
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.2,
      "position": [
        1800,
        80
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 5000,
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "jsCode": "const row = $('Prepare Email Payload').item.json;\nconst error = $json.error ?? null;\nconst success = !error;\nconst messageId = $json.messageId ?? $json.message_id ?? $json.id ?? '';\nconst provider = $('Send via Gmail').isExecuted ? 'GMAIL' : 'SMTP';\nconst delivery = {\n  provider,\n  status: success ? 'SENT' : 'FAILED',\n  sent_at: success ? new Date().toISOString() : '',\n  message_id: String(messageId || ''),\n  error: error ? String(error.message ?? error).slice(0, 500) : ''\n};\nreturn [{ json: { ...row, approval_status: success ? 'COMPLETED' : 'EMAIL_FAILED', email_delivery: JSON.stringify(delivery), last_updated_at: new Date().toISOString() } }];"
      },
      "id": "44c84c37-cd63-42ed-8d68-f58bbd0bc6db",
      "name": "Capture Email Delivery",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2040,
        -40
      ]
    },
    {
      "parameters": {
        "content": "## Choose one email provider\n\n**SMTP is connected in this template.**\n\nTo use Gmail instead:\n1. Delete the connections into and out of `Send via SMTP`.\n2. Connect `Prepare Email Payload` to `Send via Gmail`.\n3. Connect both the success and error outputs of `Send via Gmail` to `Capture Email Delivery`.\n4. Keep only one provider connected at a time.\n\nThe delivery report detects which provider node actually ran.",
        "height": 300,
        "width": 430,
        "color": 5
      },
      "id": "6f1ce595-f19e-4f10-a494-98c6dbfac509",
      "name": "Email Provider Switch Note",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1620,
        230
      ]
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "resource": "sheet",
        "operation": "appendOrUpdate",
        "documentId": {
          "mode": "id",
          "value": "SPREADSHEET_ID"
        },
        "sheetName": {
          "mode": "id",
          "value": "REPORT_SHEET_ID"
        },
        "dataMode": "autoMapInputData",
        "columnToMatchOn": "lead_id",
        "options": {
          "handlingExtraData": "ignoreIt"
        }
      },
      "id": "b0fe738a-3e1f-4eac-a8c4-0041b62b6726",
      "name": "Update Final Workflow Report",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 3,
      "position": [
        2500,
        160
      ]
    },
    {
      "parameters": {
        "jsCode": "const row = $json;\nconst escapeHtml = (value) => String(value ?? '').replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');\nlet message = row._owner_message || '';\nif (!message && row.approval_status === 'COMPLETED') {\n  const delivery = JSON.parse(row.email_delivery || '{}');\n  message = `✅ Email sent to ${row.business_email} via ${delivery.provider || 'configured provider'}.\\nLead: ${row.full_name}\\nAction: ${row.approval_action}`;\n}\nif (!message && row.approval_status === 'EMAIL_FAILED') {\n  const delivery = JSON.parse(row.email_delivery || '{}');\n  message = `⚠️ Email delivery failed for ${row.full_name}.\\nProvider: ${delivery.provider || 'unknown'}\\nError: ${delivery.error || 'Unknown error'}`;\n}\nif (!message && row.approval_status === 'REJECTED') message = `❌ ${row.full_name} was rejected. No email was sent.`;\nif (!message) message = `ℹ️ Lead status: ${row.approval_status || 'UNKNOWN'}`;\nreturn [{ json: { ...row, owner_status_message: escapeHtml(message) } }];"
      },
      "id": "7c8398af-0311-4a8b-bfa0-abf384979472",
      "name": "Prepare Owner Status",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2740,
        160
      ]
    },
    {
      "parameters": {
        "resource": "message",
        "operation": "sendMessage",
        "chatId": "OWNER_CHAT_ID",
        "text": "={{ $json.owner_status_message }}",
        "additionalFields": {
          "parse_mode": "HTML",
          "appendAttribution": false
        }
      },
      "id": "85d84815-57cd-4173-8ece-299ba83622d9",
      "name": "Send Owner Status",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        2980,
        160
      ],
      "retryOnFail": true,
      "maxTries": 3,
      "waitBetweenTries": 5000
    },
    {
      "parameters": {
        "authentication": "oAuth2",
        "resource": "sheet",
        "operation": "appendOrUpdate",
        "documentId": {
          "mode": "id",
          "value": "SPREADSHEET_ID"
        },
        "sheetName": {
          "mode": "id",
          "value": "REPORT_SHEET_ID"
        },
        "dataMode": "autoMapInputData",
        "columnToMatchOn": "lead_id",
        "options": {
          "handlingExtraData": "ignoreIt"
        }
      },
      "id": "a87a52d5-4058-4c1d-8a68-a2c40bf59b55",
      "name": "Save Awaiting Edit State",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 3,
      "position": [
        1770,
        120
      ]
    }
  ],
  "connections": {
    "Telegram Owner Response": {
      "main": [
        [
          {
            "node": "Normalize Telegram Update",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Normalize Telegram Update": {
      "main": [
        [
          {
            "node": "Is Button Callback?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Is Button Callback?": {
      "main": [
        [
          {
            "node": "Acknowledge Button Click",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Find Report by Edit Prompt",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Acknowledge Button Click": {
      "main": [
        [
          {
            "node": "Find Report by Lead ID",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find Report by Lead ID": {
      "main": [
        [
          {
            "node": "Validate Callback State",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate Callback State": {
      "main": [
        [
          {
            "node": "Callback Is Actionable?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Callback Is Actionable?": {
      "main": [
        [
          {
            "node": "Lock Review Message",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Update Final Workflow Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Lock Review Message": {
      "main": [
        [
          {
            "node": "Approve Selected?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Approve Selected?": {
      "main": [
        [
          {
            "node": "Use Approved Reply",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Edit Selected?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Use Approved Reply": {
      "main": [
        [
          {
            "node": "Prepare Email Payload",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Selected?": {
      "main": [
        [
          {
            "node": "Request Edited Reply",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Record Rejection",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Request Edited Reply": {
      "main": [
        [
          {
            "node": "Save Edit Prompt Context",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save Edit Prompt Context": {
      "main": [
        [
          {
            "node": "Save Awaiting Edit State",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Record Rejection": {
      "main": [
        [
          {
            "node": "Update Final Workflow Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find Report by Edit Prompt": {
      "main": [
        [
          {
            "node": "Validate Edited Reply",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Validate Edited Reply": {
      "main": [
        [
          {
            "node": "Edited Reply Is Valid?",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edited Reply Is Valid?": {
      "main": [
        [
          {
            "node": "Use Edited Reply",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Update Final Workflow Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Use Edited Reply": {
      "main": [
        [
          {
            "node": "Prepare Email Payload",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Email Payload": {
      "main": [
        [
          {
            "node": "Send via SMTP",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send via SMTP": {
      "main": [
        [
          {
            "node": "Capture Email Delivery",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Capture Email Delivery",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Capture Email Delivery": {
      "main": [
        [
          {
            "node": "Update Final Workflow Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Update Final Workflow Report": {
      "main": [
        [
          {
            "node": "Prepare Owner Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Owner Status": {
      "main": [
        [
          {
            "node": "Send Owner Status",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "pinData": {},
  "settings": {
    "executionOrder": "v1",
    "timezone": "UTC",
    "saveManualExecutions": true,
    "saveExecutionProgress": true,
    "saveDataErrorExecution": "all",
    "saveDataSuccessExecution": "all",
    "executionTimeout": 300,
    "errorWorkflow": "AILeadErrorHandlerPublic"
  },
  "active": false,
  "tags": []
}
