{
  "elementsLearnedData": [],
  "elementsTestData": [],
  "flow": {
    "id": "801CF2C3-FDFD-4FEA-9891-78B7CB1ADDBC",
    "name": "Captain: indexing problems reach the team"
  },
  "flowVersion": {
    "clientMetadata": {
      "viewport": {
        "x": -70,
        "y": -540,
        "zoom": 1
      },
      "autoSave": false,
      "descriptions": {
        "flow": "When a Captain indexing job completes with errors or fails, reads the job's per-file results, posts each failed file and its error to the team's Slack channel, and logs one row per file in a Google Sheet with the collection, file, error and job ID.",
        "initialData": "",
        "initialDataFields": {}
      }
    },
    "description": "When a Captain indexing job completes with errors or fails, reads the job's per-file results, posts each failed file and its error to the team's Slack channel, and logs one row per file in a Google Sheet with the collection, file, error and job ID.",
    "elements": [
      {
        "clientMetadata": {
          "elementId": "custom-cloud-code",
          "isFirstElement": false,
          "blockDefinitionId": "custom-cloud-code",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Pick out the failed files Result"
          },
          "position": {
            "x": 751,
            "y": 589
          }
        },
        "flowElementId": "5B575624-D744-40C9-A6F9-8D3299A468F2",
        "groupId": null,
        "id": "88544182-FC7D-4AB4-96E9-02D75298E035",
        "metaInfo": {
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "codeArguments": [
            {
              "name": "event",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Problem",
                    "subPathSegments": [
                      {
                        "key": "data",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "B5FBA554-5BCD-4C50-8766-359A5CF30607"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "job",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Job details",
                    "subPathSegments": null,
                    "type": "ELEMENT_LINK",
                    "value": "71153E19-B078-4248-B35F-580E58CD4A6F"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "codeBody": {
            "expression": [
              {
                "id": "TEXT",
                "label": null,
                "type": "INPUT",
                "value": "const d = (event && event.data) ? event.data : (event || {});\nconst type = (event && event.type) || d.status || '';\nconst files = Array.isArray(job?.files) ? job.files : [];\nconst name = (uri) => {\n  if (!uri) return '(unnamed file)';\n  const s = String(uri);\n  try { return decodeURIComponent(s.split('?')[0].split('/').pop() || s); } catch { return s; }\n};\nconst status = f => String(f.status || f.stage || '').toLowerCase();\nconst failed = files.filter(f => status(f) === 'failed' || status(f) === 'error');\nconst errorOf = f => f.error_message || f.error || f.progress_message || 'No error text from Captain';\nconst when = d.completed_at || job?.completed_at || new Date().toISOString();\nconst collection = d.collection_name || job?.collection_name || '';\nconst jobId = d.job_id || job?.job_id || '';\nconst jobStatus = d.status || job?.status || '';\nconst rows = failed.map(f => ({ Collection: collection, File: name(f.uri), Error: errorOf(f), 'Job ID': jobId, Status: jobStatus, When: when }));\nif (!rows.length) {\n  rows.push({ Collection: collection, File: '(whole job)', Error: d.error_code || job?.progress_message || 'Job failed with no per-file detail', 'Job ID': jobId, Status: jobStatus, When: when });\n}\nconst counts = d.files || {};\nconst progress = job?.progress || {};\nconst indexed = counts.indexed ?? progress.files_processed ?? 0;\nconst failedCount = counts.failed ?? progress.files_failed ?? failed.length;\nconst skipped = counts.skipped ?? progress.files_skipped ?? 0;\nconst total = counts.total ?? progress.files_total ?? files.length;\nconst isFailed = type === 'job.failed' || jobStatus === 'failed';\nconst headline = isFailed\n  ? `Captain indexing job failed in ${collection}` + (d.error_code ? ` (${d.error_code})` : '')\n  : `Captain indexing job finished with errors in ${collection}`;\nconst lines = [`*${headline}*`, `Job ${jobId}: ${indexed} indexed, ${failedCount} failed, ${skipped} skipped of ${total}.`];\nfailed.slice(0, 20).forEach(f => lines.push(`• ${name(f.uri)}: ${errorOf(f)}`));\nif (failed.length > 20) lines.push(`and ${failed.length - 20} more, all in the log sheet.`);\nif (!failed.length && d.error_code) lines.push(`Error code: ${d.error_code}`);\nreturn { text: lines.join('\\n'), rows };"
              }
            ],
            "mode": "EXPRESSION",
            "parseJsonString": false,
            "resultType": null
          },
          "enabled": true,
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "onFailElemId": null,
          "resultAlias": "Failed files",
          "retryPolicy": null,
          "saveToVariable": null,
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "type": "CUSTOM_CLOUD_CODE"
        },
        "name": "Pick out the failed files",
        "nextElementIds": [
          "011A1EB2-369E-44E8-80AC-F89FAB47B905"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "notes": "Adds new data rows to Google Sheets for AI agents to store processed results, log user interactions, or collect data from automated workflows. Perfect for building databases, tracking metrics, saving form submissions, or creating data collection pipelines.",
          "elementId": "EXTENSION:::SHARED:::default:::google-sheets:::addRow",
          "isFirstElement": true,
          "blockDefinitionId": "api-service-method",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Log the file in the sheet Result"
          },
          "newElementId": "EXTENSION:::SHARED:::default:::google-sheets:::addRow",
          "legacyElementId": "JS###v1###GoogleSheets###addRow",
          "methodName": "addRow",
          "position": {
            "x": 110,
            "y": 40
          }
        },
        "flowElementId": "10BF08CC-7CD5-462C-8F62-9E620DBD25AF",
        "groupId": "BA493C8C-CBB1-4D0A-AB7A-735B6E23F479",
        "id": "3B74A573-7DD7-42BD-A6FA-7F286B861036",
        "metaInfo": {
          "bodyParams": [
            {
              "name": "documentId",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "PLACEHOLDER_DATA",
                    "label": "Indexing log sheet",
                    "subPathSegments": null,
                    "type": "EXECUTION_CONTEXT_STATIC_DATA",
                    "value": "Indexing log sheet"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "sheetId",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "NUMBER",
                    "label": null,
                    "type": "INPUT",
                    "value": 0
                  }
                ],
                "mode": "BASIC",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "row",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "LIST_ITERATOR_CURRENT_ELEMENT",
                    "label": null,
                    "subPathSegments": null,
                    "type": "LIST_ITERATOR_CURRENT_ELEMENT",
                    "value": "BA493C8C-CBB1-4D0A-AB7A-735B6E23F479"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "clientValidationState": {
            "errorMessage": "Block: 'Log the file in the sheet', Error: The placeholder \"Indexing log sheet\" has no value",
            "valid": false
          },
          "connectionId": null,
          "enabled": true,
          "hostType": "SHARED",
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "methodName": "addRow",
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "Log row",
          "retryPolicy": null,
          "saveToVariable": null,
          "serviceId": "google-sheets",
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "subtype": "API_SERVICE",
          "type": "EXTENSION"
        },
        "name": "Log the file in the sheet",
        "nextElementIds": [],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "notes": "Fires when an indexing job fails. data.error_code says why. Event: job.failed.",
          "elementId": "EXTENSION:::SHARED:::default:::captain:::onJobFailed",
          "isFirstElement": false,
          "blockDefinitionId": "api-service-trigger",
          "newElementId": "EXTENSION:::SHARED:::default:::captain:::onJobFailed",
          "legacyElementId": null,
          "methodName": "onJobFailed",
          "position": {
            "x": 110,
            "y": 220
          }
        },
        "flowElementId": "C1A86B34-9616-4AD7-AF85-CD6DF052BB56",
        "groupId": "B5FBA554-5BCD-4C50-8766-359A5CF30607",
        "id": "DDC828CC-91A5-4422-8420-F1A579D68016",
        "metaInfo": {
          "callbackUrl": null,
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "condition": null,
          "connectionId": null,
          "eventName": "onJobFailed",
          "hostType": "SHARED",
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": null
          },
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "Failed job",
          "scope": "SINGLE_APP",
          "serviceId": "captain",
          "slaConditions": [],
          "staticData": {},
          "storeResult": true,
          "subtype": "REALTIME",
          "type": "CUSTOM"
        },
        "name": "Job failed",
        "nextElementIds": [],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "TRIGGER"
      },
      {
        "clientMetadata": {
          "notes": "Returns an indexing job's status, progress, credit usage and per-file results, with a cursor to page through the files.",
          "elementId": "EXTENSION:::SHARED:::default:::captain:::getJob",
          "isFirstElement": false,
          "blockDefinitionId": "api-service-method",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Get the job's files Result"
          },
          "newElementId": "EXTENSION:::SHARED:::default:::captain:::getJob",
          "legacyElementId": null,
          "methodName": "getJob",
          "position": {
            "x": 451,
            "y": 580
          }
        },
        "flowElementId": "95BFE73F-528B-436B-9E3D-581282D73729",
        "groupId": null,
        "id": "71153E19-B078-4248-B35F-580E58CD4A6F",
        "metaInfo": {
          "bodyParams": [
            {
              "name": "jobId",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Problem",
                    "subPathSegments": [
                      {
                        "key": "data",
                        "optional": false
                      },
                      {
                        "key": "data",
                        "optional": false
                      },
                      {
                        "key": "job_id",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "B5FBA554-5BCD-4C50-8766-359A5CF30607"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "filesLimit",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "NUMBER",
                    "label": null,
                    "type": "INPUT",
                    "value": 500
                  }
                ],
                "mode": "BASIC",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "filesCursor",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "connectionId": null,
          "enabled": true,
          "hostType": "SHARED",
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "methodName": "getJob",
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "Job details",
          "retryPolicy": null,
          "saveToVariable": null,
          "serviceId": "captain",
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "subtype": "API_SERVICE",
          "type": "EXTENSION"
        },
        "name": "Get the job's files",
        "nextElementIds": [
          "88544182-FC7D-4AB4-96E9-02D75298E035"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "notes": "Fires when an indexing job finishes and at least one file failed. The files that succeeded are searchable; Get Job Status lists the failures. Event: job.completed_with_errors.",
          "elementId": "EXTENSION:::SHARED:::default:::captain:::onJobCompletedWithErrors",
          "isFirstElement": false,
          "blockDefinitionId": "api-service-trigger",
          "newElementId": "EXTENSION:::SHARED:::default:::captain:::onJobCompletedWithErrors",
          "legacyElementId": null,
          "methodName": "onJobCompletedWithErrors",
          "position": {
            "x": 110,
            "y": 400
          }
        },
        "flowElementId": "E8B4B0F7-AA93-4C9A-BF2A-8BE7CE7AE5BD",
        "groupId": "B5FBA554-5BCD-4C50-8766-359A5CF30607",
        "id": "A1C50651-0585-4426-8C40-D6E834DE58C3",
        "metaInfo": {
          "callbackUrl": null,
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "condition": null,
          "connectionId": null,
          "eventName": "onJobCompletedWithErrors",
          "hostType": "SHARED",
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": null
          },
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "Job with errors",
          "scope": "SINGLE_APP",
          "serviceId": "captain",
          "slaConditions": [],
          "staticData": {},
          "storeResult": true,
          "subtype": "REALTIME",
          "type": "CUSTOM"
        },
        "name": "Job completed with errors",
        "nextElementIds": [],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "TRIGGER"
      },
      {
        "clientMetadata": {
          "notes": "Sends messages to Slack channels with optional Block Kit rich layouts. Supports plain text with Slack formatting, or advanced Block Kit JSON for buttons, menus, and interactive elements. Returns the message timestamp and channel ID for later updates or tracking.",
          "elementId": "EXTENSION:::SHARED:::default:::slack:::sendMessageToChannel",
          "isFirstElement": false,
          "blockDefinitionId": "api-service-method",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Tell #data in Slack Result"
          },
          "newElementId": "EXTENSION:::SHARED:::default:::slack:::sendMessageToChannel",
          "legacyElementId": "JS###v1###Slack###sendMessageToChannel",
          "methodName": "sendMessageToChannel",
          "position": {
            "x": 1067,
            "y": 580
          }
        },
        "flowElementId": "1A1376D9-34F7-4099-85BC-C933B473445E",
        "groupId": null,
        "id": "011A1EB2-369E-44E8-80AC-F89FAB47B905",
        "metaInfo": {
          "bodyParams": [
            {
              "name": "channelId",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "TEXT",
                    "label": null,
                    "type": "INPUT",
                    "value": ""
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "messageText",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Failed files",
                    "subPathSegments": [
                      {
                        "key": "text",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "88544182-FC7D-4AB4-96E9-02D75298E035"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "threadId",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "sendAsBot",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "K_FALSE",
                    "label": null,
                    "type": "KEYWORD",
                    "value": false
                  }
                ],
                "mode": "BASIC",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "botName",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "botIcon",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "replyBroadcast",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "K_FALSE",
                    "label": null,
                    "type": "KEYWORD",
                    "value": false
                  }
                ],
                "mode": "BASIC",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "imageURL",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "blocks",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "connectionId": null,
          "enabled": true,
          "hostType": "SHARED",
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "methodName": "sendMessageToChannel",
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "Team alert",
          "retryPolicy": null,
          "saveToVariable": null,
          "serviceId": "slack",
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "subtype": "API_SERVICE",
          "type": "EXTENSION"
        },
        "name": "Tell #data in Slack",
        "nextElementIds": [],
        "nextGroupIds": [
          "BA493C8C-CBB1-4D0A-AB7A-735B6E23F479"
        ],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      }
    ],
    "firstElementId": "B5FBA554-5BCD-4C50-8766-359A5CF30607",
    "groups": [
      {
        "clientMetadata": {
          "elementId": "list-iterator",
          "isFirstElement": false,
          "blockDefinitionId": "list-iterator",
          "viewport": {
            "x": -70,
            "y": 0,
            "zoom": 1
          },
          "position": {
            "x": 1067,
            "y": 759
          }
        },
        "flowElementId": "BF51F94C-BFE6-4571-8A4E-76B083119C85",
        "groupId": null,
        "id": "BA493C8C-CBB1-4D0A-AB7A-735B6E23F479",
        "loopType": "LIST_ITERATOR",
        "metaInfo": {
          "clientValidationState": {
            "errorMessage": "Block: 'For each failed file', Error: Children have error",
            "valid": false
          },
          "enabled": true,
          "firstElementId": "3B74A573-7DD7-42BD-A6FA-7F286B861036",
          "list": {
            "expression": [
              {
                "id": "ELEMENT_RESULT",
                "label": "Failed files",
                "subPathSegments": [
                  {
                    "key": "rows",
                    "optional": false
                  }
                ],
                "type": "ELEMENT_LINK",
                "value": "88544182-FC7D-4AB4-96E9-02D75298E035"
              }
            ],
            "mode": "EXPRESSION",
            "parseJsonString": false,
            "resultType": null
          },
          "onFailElemId": null,
          "resultAlias": "Each failed file",
          "storeResult": true
        },
        "name": "For each failed file",
        "nextElementIds": [],
        "nextGroupIds": [],
        "type": "LOOP"
      },
      {
        "clientMetadata": {
          "elementId": "triggers-group",
          "isFirstElement": true,
          "blockDefinitionId": "triggers-group",
          "viewport": {
            "x": 0,
            "y": 0,
            "zoom": 0.8
          },
          "position": {
            "x": 110,
            "y": 589
          }
        },
        "flowElementId": "4282E326-4C1E-4E0E-983D-853FE37F509C",
        "groupId": null,
        "id": "B5FBA554-5BCD-4C50-8766-359A5CF30607",
        "metaInfo": {
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "occurWithin": null,
          "occurrenceTimeUnit": null,
          "onFailElemId": null,
          "resultAlias": "Problem",
          "storeResult": true,
          "transitionMode": "ONE_OCCUR"
        },
        "name": "Indexing job had problems",
        "nextElementIds": [
          "71153E19-B078-4248-B35F-580E58CD4A6F"
        ],
        "nextGroupIds": [],
        "type": "TRIGGERS"
      }
    ],
    "id": "B32F5F2E-83BE-438A-9D99-762222950C71",
    "metaInfo": {
      "clientValidationState": {
        "errorMessage": "Please fix problems before start. Blocks with issues have red badge in the top-right corner of a block, hover it to see what needs to be done.",
        "valid": false
      },
      "errorMessage": "Please fix problems before start. Blocks with issues have red badge in the top-right corner of a block, hover it to see what needs to be done.",
      "executionStaticData": [
        {
          "description": "The Google Sheets spreadsheet URL or ID that logs failed files. Its first sheet has the columns Collection, File, Error, Job ID, Status and When.",
          "error": null,
          "name": "Indexing log sheet",
          "type": "STRING",
          "value": ""
        }
      ],
      "initialData": null,
      "initialDataDefaultValues": {},
      "ownerFlowVersionId": null,
      "schedule": null,
      "sharedMemory": {
        "anchor": {
          "missingAnchorPolicy": null,
          "path": null,
          "type": "FLOW_MEMORY"
        },
        "expirationInSec": null
      },
      "wasLive": false
    }
  },
  "slaCalendars": [],
  "slaGoals": [],
  "subFlows": [],
  "exportDate": "2026-12-02T08:37:38.054Z"
}
