{
  "elementsLearnedData": [],
  "elementsTestData": [],
  "flow": {
    "id": "41E83518-3CFD-49F8-8DCD-1516F8DDF4E1",
    "name": "Onfleet: failed deliveries rebooked or reviewed"
  },
  "flowVersion": {
    "clientMetadata": {
      "viewport": {
        "x": -62.94117647058823,
        "y": 2.5668449197860994,
        "zoom": 0.94
      },
      "autoSave": false,
      "descriptions": {
        "flow": "Starts when an Onfleet delivery fails. An AI agent reads the failure reason and the driver's notes. A failure a second try fixes (nobody home, closed, out of time) is cloned in Onfleet for the next day, with the task's metadata kept. Anything else gets a text to the customer from Twilio, and dispatch decides in Slack whether to rebook it or hold it.",
        "initialData": "",
        "initialDataFields": {}
      }
    },
    "description": "Checks Onfleet every 15 minutes for deliveries that failed since the last check. An AI agent reads the failure reason and the driver's notes. A failure a second try fixes (nobody home, closed, out of time) is rebooked for the next day. Anything else gets a text to the customer from Twilio, and dispatch decides in Slack whether to rebook it or hold it.",
    "elements": [
      {
        "clientMetadata": {
          "elementId": "condition",
          "isFirstElement": false,
          "blockDefinitionId": "condition",
          "position": {
            "x": 872,
            "y": 219
          }
        },
        "flowElementId": "088E621C-9D45-493C-826C-A88E107E296A",
        "groupId": null,
        "id": "A7E897DA-9077-4E69-94E1-742BBB78B59B",
        "metaInfo": {
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "condition": {
            "conditionParts": [
              {
                "id": "b4d91069-9c41-4ece-bddf-8c55a08596db",
                "nestedOperation": null,
                "operation": "isNotEmpty",
                "property": {
                  "expression": [
                    {
                      "id": "ELEMENT_RESULT",
                      "label": "Failure",
                      "subPathSegments": [
                        {
                          "key": "recipientPhone",
                          "optional": false
                        }
                      ],
                      "type": "ELEMENT_LINK",
                      "value": "D6CF4DCC-68DC-46BA-87A5-9C26A6A84CDA"
                    }
                  ],
                  "mode": "EXPRESSION",
                  "parseJsonString": false,
                  "resultType": null
                },
                "propertyType": "STRING",
                "values": []
              }
            ],
            "grouping": [
              "b4d91069-9c41-4ece-bddf-8c55a08596db"
            ]
          },
          "elseComponent": {
            "componentId": "B86333C5-BA58-4A6C-BAE5-CE4BC5824496",
            "componentType": "ELEMENT"
          },
          "logging": null,
          "onFailElemId": null,
          "resultAlias": "Has phone",
          "storeResult": false,
          "thenComponent": {
            "componentId": "C7DCA9CD-D093-4C48-81E3-2FC4D00F50C0",
            "componentType": "ELEMENT"
          }
        },
        "name": "Customer has a phone?",
        "nextElementIds": [
          "B86333C5-BA58-4A6C-BAE5-CE4BC5824496",
          "C7DCA9CD-D093-4C48-81E3-2FC4D00F50C0"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "preferredDateFormats": []
        },
        "type": "CONDITION"
      },
      {
        "clientMetadata": {
          "elementId": "ai-agent",
          "isFirstElement": false,
          "blockDefinitionId": "ai-agent",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Read why it failed Result"
          },
          "tools": {},
          "position": {
            "x": 1283,
            "y": 49
          }
        },
        "flowElementId": "702D0601-CD7A-4921-B320-8F375189C171",
        "groupId": null,
        "id": "FA1B6CDB-685C-4F1A-9081-239D8076757F",
        "metaInfo": {
          "aiApiKey": null,
          "aiModel": "claude-sonnet-5",
          "aiProvider": "ANTHROPIC",
          "clientValidationState": {
            "errorMessage": "Block: 'Read why it failed', Error: The placeholder \"Company name\" has no value",
            "valid": false
          },
          "dynamicAiApiKey": {
            "expression": [
              {
                "id": "PLACEHOLDER_DATA",
                "label": "Anthropic key",
                "subPathSegments": null,
                "type": "EXECUTION_CONTEXT_STATIC_DATA",
                "value": "Anthropic key"
              }
            ],
            "mode": "EXPRESSION",
            "parseJsonString": false,
            "resultType": null
          },
          "enabled": true,
          "files": [],
          "forceParsedOutput": true,
          "langSmithSettings": {
            "enabled": false,
            "apiKey": null,
            "projectName": null,
            "label": "FlowRunner AI-Agent",
            "accountCluster": "US"
          },
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "messagesHistoryEnabled": false,
          "messagesHistoryLimit": 15,
          "onFailElemId": null,
          "resultAlias": "Failure reading",
          "retryPolicy": null,
          "saveToVariable": null,
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "systemPrompt": {
            "expression": [
              {
                "id": "TEXT",
                "label": null,
                "type": "INPUT",
                "value": "You review failed final-mile deliveries for a carrier's dispatch team. From the failure reason code and the driver's notes, reply with JSON only, with these fields:\ndecision: \"reattempt\" when a second try the next day is likely to work (the recipient was not home or not available, the business was closed, the driver ran out of time or had a vehicle problem); \"ask\" for anything else (wrong or unfindable address, no access or a missing gate code, refused, damaged or short freight, a safety problem, or a reason you cannot tell)\nreason: one plain sentence for dispatch saying what happened\ncustomerText: a short, polite text message to the customer, under 300 characters, saying the delivery could not be completed today and why, and asking what is needed (a better time, the right address, a gate code). Do not promise a delivery date. Do not include a phone number or a signature."
              }
            ],
            "mode": "EXPRESSION",
            "parseJsonString": false,
            "resultType": null
          },
          "tools": [],
          "type": "AI_AGENT",
          "userPrompt": {
            "expression": [
              {
                "id": "TEXT",
                "label": null,
                "type": "INPUT",
                "value": "Company: "
              },
              {
                "id": "PLACEHOLDER_DATA",
                "label": "Company name",
                "subPathSegments": null,
                "type": "EXECUTION_CONTEXT_STATIC_DATA",
                "value": "Company name"
              },
              {
                "id": "TEXT",
                "label": null,
                "type": "INPUT",
                "value": "\nFailure reason code: "
              },
              {
                "id": "ELEMENT_RESULT",
                "label": "Failure",
                "subPathSegments": [
                  {
                    "key": "failureReason",
                    "optional": false
                  }
                ],
                "type": "ELEMENT_LINK",
                "value": "D6CF4DCC-68DC-46BA-87A5-9C26A6A84CDA"
              },
              {
                "id": "TEXT",
                "label": null,
                "type": "INPUT",
                "value": "\nDriver's notes: "
              },
              {
                "id": "ELEMENT_RESULT",
                "label": "Failure",
                "subPathSegments": [
                  {
                    "key": "driverNotes",
                    "optional": false
                  }
                ],
                "type": "ELEMENT_LINK",
                "value": "D6CF4DCC-68DC-46BA-87A5-9C26A6A84CDA"
              },
              {
                "id": "TEXT",
                "label": null,
                "type": "INPUT",
                "value": "\nThis was attempt "
              },
              {
                "id": "ELEMENT_RESULT",
                "label": "Failure",
                "subPathSegments": [
                  {
                    "key": "attempt",
                    "optional": false
                  }
                ],
                "type": "ELEMENT_LINK",
                "value": "D6CF4DCC-68DC-46BA-87A5-9C26A6A84CDA"
              },
              {
                "id": "TEXT",
                "label": null,
                "type": "INPUT",
                "value": ".\nCustomer: "
              },
              {
                "id": "ELEMENT_RESULT",
                "label": "Failure",
                "subPathSegments": [
                  {
                    "key": "recipientName",
                    "optional": false
                  }
                ],
                "type": "ELEMENT_LINK",
                "value": "D6CF4DCC-68DC-46BA-87A5-9C26A6A84CDA"
              },
              {
                "id": "TEXT",
                "label": null,
                "type": "INPUT",
                "value": "\nAddress: "
              },
              {
                "id": "ELEMENT_RESULT",
                "label": "Failure",
                "subPathSegments": [
                  {
                    "key": "address",
                    "optional": false
                  }
                ],
                "type": "ELEMENT_LINK",
                "value": "D6CF4DCC-68DC-46BA-87A5-9C26A6A84CDA"
              },
              {
                "id": "TEXT",
                "label": null,
                "type": "INPUT",
                "value": "\nTask notes: "
              },
              {
                "id": "ELEMENT_RESULT",
                "label": "Failure",
                "subPathSegments": [
                  {
                    "key": "notes",
                    "optional": false
                  }
                ],
                "type": "ELEMENT_LINK",
                "value": "D6CF4DCC-68DC-46BA-87A5-9C26A6A84CDA"
              }
            ],
            "mode": "EXPRESSION",
            "parseJsonString": false,
            "resultType": null
          }
        },
        "name": "Read why it failed",
        "nextElementIds": [
          "59CCD63B-0DF0-4848-9DAD-80AD4932BAC4"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "notes": "Sends an SMS message to a specified phone number using Twilio's messaging service.",
          "elementId": "EXTENSION:::SHARED:::default:::twilio:::sendSms",
          "isFirstElement": false,
          "blockDefinitionId": "api-service-method",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Text the customer Result"
          },
          "newElementId": "EXTENSION:::SHARED:::default:::twilio:::sendSms",
          "legacyElementId": "JS###v1###TwilioService###sendSms",
          "methodName": "sendSms",
          "position": {
            "x": 504,
            "y": 210
          }
        },
        "flowElementId": "8C759F57-C3FA-44C0-BD55-C62F295D214C",
        "groupId": null,
        "id": "C7DCA9CD-D093-4C48-81E3-2FC4D00F50C0",
        "metaInfo": {
          "bodyParams": [
            {
              "name": "to",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Failure",
                    "subPathSegments": [
                      {
                        "key": "recipientPhone",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "D6CF4DCC-68DC-46BA-87A5-9C26A6A84CDA"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "from",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "PLACEHOLDER_DATA",
                    "label": "Texting number",
                    "subPathSegments": null,
                    "type": "EXECUTION_CONTEXT_STATIC_DATA",
                    "value": "Texting number"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "body",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "PLACEHOLDER_DATA",
                    "label": "Company name",
                    "subPathSegments": null,
                    "type": "EXECUTION_CONTEXT_STATIC_DATA",
                    "value": "Company name"
                  },
                  {
                    "id": "TEXT",
                    "label": null,
                    "type": "INPUT",
                    "value": ": "
                  },
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Failure reading",
                    "subPathSegments": [
                      {
                        "key": "output",
                        "optional": false
                      },
                      {
                        "key": "customerText",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "FA1B6CDB-685C-4F1A-9081-239D8076757F"
                  },
                  {
                    "id": "TEXT",
                    "label": null,
                    "type": "INPUT",
                    "value": " Please call us at "
                  },
                  {
                    "id": "PLACEHOLDER_DATA",
                    "label": "Dispatch phone",
                    "subPathSegments": null,
                    "type": "EXECUTION_CONTEXT_STATIC_DATA",
                    "value": "Dispatch phone"
                  },
                  {
                    "id": "TEXT",
                    "label": null,
                    "type": "INPUT",
                    "value": "."
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "mediaUrl",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "clientValidationState": {
            "errorMessage": "Block: 'Text the customer', Error: The placeholder \"Texting number\" has no value",
            "valid": false
          },
          "connectionId": null,
          "enabled": true,
          "hostType": "SHARED",
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "methodName": "sendSms",
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "Customer text",
          "retryPolicy": null,
          "saveToVariable": null,
          "serviceId": "twilio",
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "subtype": "API_SERVICE",
          "type": "EXTENSION"
        },
        "name": "Text the customer",
        "nextElementIds": [
          "B86333C5-BA58-4A6C-BAE5-CE4BC5824496"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "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,
          "dynamicOptionLabels": {
            "channelId": {}
          },
          "blockDefinitionId": "api-service-method",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Ask dispatch Result"
          },
          "newElementId": "EXTENSION:::SHARED:::default:::slack:::sendMessageToChannel",
          "legacyElementId": "JS###v1###Slack###sendMessageToChannel",
          "methodName": "sendMessageToChannel",
          "position": {
            "x": 146,
            "y": 510
          }
        },
        "flowElementId": "7684E2E0-7603-41A6-929D-2B0557ECB1F9",
        "groupId": null,
        "id": "13792391-8C43-4F6C-8616-5EACB6F15898",
        "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": "Question card",
                    "subPathSegments": [
                      {
                        "key": "text",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "B86333C5-BA58-4A6C-BAE5-CE4BC5824496"
                  }
                ],
                "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": "EXPRESSION",
                "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": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "imageURL",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "blocks",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Question card",
                    "subPathSegments": [
                      {
                        "key": "blocks",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "B86333C5-BA58-4A6C-BAE5-CE4BC5824496"
                  }
                ],
                "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": "Question to dispatch",
          "retryPolicy": null,
          "saveToVariable": null,
          "serviceId": "slack",
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "subtype": "API_SERVICE",
          "type": "EXTENSION"
        },
        "name": "Ask dispatch",
        "nextElementIds": [
          "50DD7998-92E7-44D7-B32F-6C3D447DAC02"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "elementId": "custom-cloud-code",
          "isFirstElement": false,
          "blockDefinitionId": "custom-cloud-code",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Set tomorrow's window Result"
          },
          "position": {
            "x": 1272,
            "y": 519
          }
        },
        "flowElementId": "C82B8B96-8E20-4B0B-82B5-801EE010B10A",
        "groupId": null,
        "id": "F6E07B0F-4E12-4829-96A4-C3800DBBEE60",
        "metaInfo": {
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "codeArguments": [
            {
              "name": "failedAt",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Failure",
                    "subPathSegments": [
                      {
                        "key": "failedAt",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "D6CF4DCC-68DC-46BA-87A5-9C26A6A84CDA"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "completeAfter",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Failure",
                    "subPathSegments": [
                      {
                        "key": "completeAfter",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "D6CF4DCC-68DC-46BA-87A5-9C26A6A84CDA"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "completeBefore",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Failure",
                    "subPathSegments": [
                      {
                        "key": "completeBefore",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "D6CF4DCC-68DC-46BA-87A5-9C26A6A84CDA"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "timeZone",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "PLACEHOLDER_DATA",
                    "label": "Time zone",
                    "subPathSegments": null,
                    "type": "EXECUTION_CONTEXT_STATIC_DATA",
                    "value": "Time zone"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "notes",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Failure",
                    "subPathSegments": [
                      {
                        "key": "notes",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "D6CF4DCC-68DC-46BA-87A5-9C26A6A84CDA"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "attempt",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Failure",
                    "subPathSegments": [
                      {
                        "key": "attempt",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "D6CF4DCC-68DC-46BA-87A5-9C26A6A84CDA"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "shortId",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Failure",
                    "subPathSegments": [
                      {
                        "key": "shortId",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "D6CF4DCC-68DC-46BA-87A5-9C26A6A84CDA"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "reason",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Failure reading",
                    "subPathSegments": [
                      {
                        "key": "output",
                        "optional": false
                      },
                      {
                        "key": "reason",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "FA1B6CDB-685C-4F1A-9081-239D8076757F"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "failureReason",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Failure",
                    "subPathSegments": [
                      {
                        "key": "failureReason",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "D6CF4DCC-68DC-46BA-87A5-9C26A6A84CDA"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "codeBody": {
            "expression": [
              {
                "id": "TEXT",
                "label": null,
                "type": "INPUT",
                "value": "// The day after the failed attempt, in the dispatch time zone, keeping the original window's hours (8:00 to 18:00 when the task had none).\nconst HOUR = 3600000, DAY = 24 * HOUR;\nconst tz = timeZone || 'America/Chicago';\nconst fmt = new Intl.DateTimeFormat('en-US', { timeZone: tz, year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', hourCycle: 'h23' });\nconst partsOf = (ms) => Object.fromEntries(fmt.formatToParts(new Date(ms)).map((p) => [p.type, p.value]));\nconst offsetAt = (ms) => { const p = partsOf(ms); return Date.UTC(+p.year, +p.month - 1, +p.day, +p.hour, +p.minute) - Math.floor(ms / 60000) * 60000; };\nconst localToUtc = (y, m, d, h, min) => { const wall = Date.UTC(y, m - 1, d, h, min); return wall - offsetAt(wall - offsetAt(wall)); };\nconst failed = partsOf(Number(failedAt) || Date.now());\nconst next = new Date(Date.UTC(+failed.year, +failed.month - 1, +failed.day) + DAY);\nconst y = next.getUTCFullYear(), m = next.getUTCMonth() + 1, d = next.getUTCDate();\nconst hoursOf = (ms, h) => { if (!Number(ms)) return [h, 0]; const p = partsOf(Number(ms)); return [+p.hour, +p.minute]; };\nconst [ah, am] = hoursOf(completeAfter, 8);\nconst [bh, bm] = hoursOf(completeBefore, 18);\nconst after = localToUtc(y, m, d, ah, am);\nlet before = localToUtc(y, m, d, bh, bm);\nif (before <= after) before = after + 4 * HOUR;\nconst show = (ms, opts) => new Intl.DateTimeFormat('en-US', { timeZone: tz, ...opts }).format(new Date(ms));\nconst windowText = show(after, { weekday: 'long', month: 'short', day: 'numeric' }) + ', ' + show(after, { hour: 'numeric', minute: '2-digit' }) + ' to ' + show(before, { hour: 'numeric', minute: '2-digit' });\n// The clone keeps the task's metadata (the load number); its notes get the attempt count on top.\nconst kept = String(notes || '').split('\\n').filter((line) => !/^Attempt \\d+\\./.test(line)).join('\\n').trim();\nconst why = String(reason || failureReason || 'failed delivery').trim().replace(/\\.+$/, '');\nconst header = 'Attempt ' + (Number(attempt) + 1) + '. Reattempt of task ' + shortId + ': ' + why + '.';\nreturn { completeAfter: after, completeBefore: before, windowText, notes: [header, kept].filter(Boolean).join('\\n') };"
              }
            ],
            "mode": "EXPRESSION",
            "parseJsonString": false,
            "resultType": null
          },
          "enabled": true,
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "onFailElemId": null,
          "resultAlias": "Next day",
          "retryPolicy": null,
          "saveToVariable": null,
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "type": "CUSTOM_CLOUD_CODE"
        },
        "name": "Set tomorrow's window",
        "nextElementIds": [
          "64663DA1-E69F-438D-B281-9EBD07DE20D1"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "notes": "Fires when a task is completed as failed (Onfleet webhook taskFailed). The event carries the whole task under data.task, with the failure reason and notes in its completion details, its metadata and any photo and signature URLs the driver captured.",
          "elementId": "EXTENSION:::SHARED:::default:::onfleet:::onTaskFailed",
          "isFirstElement": true,
          "blockDefinitionId": "api-service-trigger",
          "newElementId": "EXTENSION:::SHARED:::default:::onfleet:::onTaskFailed",
          "legacyElementId": "JS###v1###OnfleetService###onTaskFailed",
          "methodName": "onTaskFailed",
          "position": {
            "x": 132,
            "y": 40
          }
        },
        "flowElementId": "E52A9141-9396-49C1-AA5D-B6790B5968E3",
        "groupId": null,
        "id": "B403C1ED-83B5-4CFB-BDD6-2CAB373927A3",
        "metaInfo": {
          "callbackUrl": null,
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "condition": null,
          "connectionId": null,
          "eventName": "onTaskFailed",
          "hostType": "SHARED",
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": null
          },
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "Failed task",
          "scope": "SINGLE_APP",
          "serviceId": "onfleet",
          "slaConditions": [],
          "staticData": {},
          "storeResult": true,
          "subtype": "REALTIME",
          "type": "CUSTOM"
        },
        "name": "Delivery failed in Onfleet",
        "nextElementIds": [
          "A9E9F9D3-B96A-4EC3-9E54-68DBB9F11431"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "TRIGGER"
      },
      {
        "clientMetadata": {
          "elementId": "external-callback",
          "isFirstElement": false,
          "blockDefinitionId": "external-callback",
          "position": {
            "x": 482,
            "y": 519
          }
        },
        "flowElementId": "4889D843-2A40-446F-BFDC-EEF07BA6E3F8",
        "groupId": null,
        "id": "50DD7998-92E7-44D7-B32F-6C3D447DAC02",
        "metaInfo": {
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "condition": null,
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": null
          },
          "onFailElemId": null,
          "resultAlias": "Dispatch decision",
          "slaConditions": [],
          "storeResult": true,
          "type": "CALLBACK"
        },
        "name": "Wait for dispatch's answer",
        "nextElementIds": [
          "0D0E10D1-F9AF-439B-98F6-5BC9B0E560B5"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "TRIGGER"
      },
      {
        "clientMetadata": {
          "elementId": "condition",
          "isFirstElement": false,
          "blockDefinitionId": "condition",
          "position": {
            "x": 1283,
            "y": 219
          }
        },
        "flowElementId": "B28F9DE4-7836-452A-A073-2A9179082592",
        "groupId": null,
        "id": "59CCD63B-0DF0-4848-9DAD-80AD4932BAC4",
        "metaInfo": {
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "condition": {
            "conditionParts": [
              {
                "id": "b33e51d7-6cea-4958-90f2-d896f317485e",
                "nestedOperation": null,
                "operation": "equal",
                "property": {
                  "expression": [
                    {
                      "id": "ELEMENT_RESULT",
                      "label": "Failure reading",
                      "subPathSegments": [
                        {
                          "key": "output",
                          "optional": false
                        },
                        {
                          "key": "decision",
                          "optional": false
                        }
                      ],
                      "type": "ELEMENT_LINK",
                      "value": "FA1B6CDB-685C-4F1A-9081-239D8076757F"
                    }
                  ],
                  "mode": "EXPRESSION",
                  "parseJsonString": false,
                  "resultType": null
                },
                "propertyType": "STRING",
                "values": [
                  {
                    "expression": [
                      {
                        "id": "TEXT",
                        "label": null,
                        "type": "INPUT",
                        "value": "reattempt"
                      }
                    ],
                    "mode": "EXPRESSION",
                    "parseJsonString": false,
                    "resultType": null
                  }
                ]
              },
              {
                "id": "6b4ebdba-ae1f-4449-a8d2-c61e32725239",
                "nestedOperation": null,
                "operation": "isTrue",
                "property": {
                  "expression": [
                    {
                      "id": "ELEMENT_RESULT",
                      "label": "Failure",
                      "subPathSegments": [
                        {
                          "key": "rebookable",
                          "optional": false
                        }
                      ],
                      "type": "ELEMENT_LINK",
                      "value": "D6CF4DCC-68DC-46BA-87A5-9C26A6A84CDA"
                    }
                  ],
                  "mode": "EXPRESSION",
                  "parseJsonString": false,
                  "resultType": null
                },
                "propertyType": "BOOLEAN",
                "values": []
              }
            ],
            "grouping": [
              "b33e51d7-6cea-4958-90f2-d896f317485e",
              "AND",
              "6b4ebdba-ae1f-4449-a8d2-c61e32725239"
            ]
          },
          "elseComponent": {
            "componentId": "A7E897DA-9077-4E69-94E1-742BBB78B59B",
            "componentType": "ELEMENT"
          },
          "logging": null,
          "onFailElemId": null,
          "resultAlias": "Rebook on its own",
          "storeResult": false,
          "thenComponent": {
            "componentId": "F6E07B0F-4E12-4829-96A4-C3800DBBEE60",
            "componentType": "ELEMENT"
          }
        },
        "name": "Rebook on its own?",
        "nextElementIds": [
          "A7E897DA-9077-4E69-94E1-742BBB78B59B",
          "F6E07B0F-4E12-4829-96A4-C3800DBBEE60"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "preferredDateFormats": []
        },
        "type": "CONDITION"
      },
      {
        "clientMetadata": {
          "elementId": "custom-cloud-code",
          "isFirstElement": false,
          "blockDefinitionId": "custom-cloud-code",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Read the failed delivery Result"
          },
          "position": {
            "x": 872,
            "y": 49
          }
        },
        "flowElementId": "B3D982AF-E7B2-45CB-A663-AEAA1608F8D0",
        "groupId": null,
        "id": "D6CF4DCC-68DC-46BA-87A5-9C26A6A84CDA",
        "metaInfo": {
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "codeArguments": [
            {
              "name": "task",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "RESULT",
                    "label": "Failed task",
                    "subPathSegments": [
                      {
                        "key": "data",
                        "optional": false
                      },
                      {
                        "key": "task",
                        "optional": false
                      }
                    ],
                    "type": "TRIGGER_DATA",
                    "value": "B403C1ED-83B5-4CFB-BDD6-2CAB373927A3"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "loadField",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "PLACEHOLDER_DATA",
                    "label": "Load number field",
                    "subPathSegments": null,
                    "type": "EXECUTION_CONTEXT_STATIC_DATA",
                    "value": "Load number field"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "maxAttempts",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "PLACEHOLDER_DATA",
                    "label": "Most attempts",
                    "subPathSegments": null,
                    "type": "EXECUTION_CONTEXT_STATIC_DATA",
                    "value": "Most attempts"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "codeBody": {
            "expression": [
              {
                "id": "TEXT",
                "label": null,
                "type": "INPUT",
                "value": "// One failed Onfleet task: the load number, how many tries it has had, and the driver's photos as the connector links them.\nconst t = task || {};\nconst c = t.completionDetails || {};\nconst key = String(loadField || '').trim().toLowerCase();\nconst meta = (t.metadata || []).find((m) => String(m.name || '').trim().toLowerCase() === key);\nlet loadNumber = meta && meta.value !== undefined && meta.value !== null ? String(meta.value).trim() : '';\nif (!loadNumber) {\n  const m = String(t.notes || '').match(/\\bload\\s*(?:#|no\\.?|number)?\\s*[:#]?\\s*([A-Z0-9][A-Z0-9-]{2,})/i);\n  loadNumber = m ? m[1] : '';\n}\nconst most = Number(maxAttempts) || 2;\nconst notes = String(t.notes || '');\nconst tried = notes.match(/^Attempt (\\d+)\\./m);\nconst attempt = tried ? Number(tried[1]) : 1;\nconst photos = Array.isArray(c.photoUrls) && c.photoUrls.length ? c.photoUrls : (c.photoUrl ? [c.photoUrl] : []);\nconst r = (t.recipients || [])[0] || {};\nconst a = (t.destination && t.destination.address) || {};\nreturn {\n  taskId: t.id,\n  shortId: t.shortId || t.id,\n  notes,\n  loadNumber,\n  failureReason: c.failureReason || '',\n  driverNotes: String(c.failureNotes || c.notes || '').trim(),\n  failedAt: Number(c.time) || Date.now(),\n  attempt,\n  rebookable: attempt < most,\n  recipientName: r.name || '',\n  recipientPhone: r.phone || '',\n  address: [a.number, a.street, a.apartment, a.city, a.state].filter(Boolean).join(' '),\n  completeAfter: Number(t.completeAfter) || 0,\n  completeBefore: Number(t.completeBefore) || 0,\n  photoLinks: photos.length ? photos.map((url, i) => `<${url}|Photo ${i + 1}>`).join('  ') : 'no photos',\n};"
              }
            ],
            "mode": "EXPRESSION",
            "parseJsonString": false,
            "resultType": null
          },
          "enabled": true,
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "onFailElemId": null,
          "resultAlias": "Failure",
          "retryPolicy": null,
          "saveToVariable": null,
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "type": "CUSTOM_CLOUD_CODE"
        },
        "name": "Read the failed delivery",
        "nextElementIds": [
          "FA1B6CDB-685C-4F1A-9081-239D8076757F"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "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,
          "dynamicOptionLabels": {
            "channelId": {}
          },
          "blockDefinitionId": "api-service-method",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Tell dispatch the reattempt is booked Result"
          },
          "newElementId": "EXTENSION:::SHARED:::default:::slack:::sendMessageToChannel",
          "legacyElementId": "JS###v1###Slack###sendMessageToChannel",
          "methodName": "sendMessageToChannel",
          "position": {
            "x": 825,
            "y": 680
          }
        },
        "flowElementId": "B317AA75-2B76-48D5-9758-702B7AB76F0D",
        "groupId": null,
        "id": "09750F4B-6E9D-423E-ACB5-02B607F80622",
        "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": "TEXT",
                    "label": null,
                    "type": "INPUT",
                    "value": "Rebooked: "
                  },
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Failure",
                    "subPathSegments": [
                      {
                        "key": "recipientName",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "D6CF4DCC-68DC-46BA-87A5-9C26A6A84CDA"
                  },
                  {
                    "id": "TEXT",
                    "label": null,
                    "type": "INPUT",
                    "value": ", "
                  },
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Failure",
                    "subPathSegments": [
                      {
                        "key": "address",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "D6CF4DCC-68DC-46BA-87A5-9C26A6A84CDA"
                  },
                  {
                    "id": "TEXT",
                    "label": null,
                    "type": "INPUT",
                    "value": ", for "
                  },
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Next day",
                    "subPathSegments": [
                      {
                        "key": "windowText",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "F6E07B0F-4E12-4829-96A4-C3800DBBEE60"
                  },
                  {
                    "id": "TEXT",
                    "label": null,
                    "type": "INPUT",
                    "value": " as Onfleet task "
                  },
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Reattempt task",
                    "subPathSegments": [
                      {
                        "key": "shortId",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "64663DA1-E69F-438D-B281-9EBD07DE20D1"
                  },
                  {
                    "id": "TEXT",
                    "label": null,
                    "type": "INPUT",
                    "value": ". The failed attempt: "
                  },
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Failure reading",
                    "subPathSegments": [
                      {
                        "key": "output",
                        "optional": false
                      },
                      {
                        "key": "reason",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "FA1B6CDB-685C-4F1A-9081-239D8076757F"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "threadId",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Question to dispatch",
                    "subPathSegments": [
                      {
                        "key": "messageId",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "13792391-8C43-4F6C-8616-5EACB6F15898"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "sendAsBot",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "K_FALSE",
                    "label": null,
                    "type": "KEYWORD",
                    "value": false
                  }
                ],
                "mode": "EXPRESSION",
                "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": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "imageURL",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "blocks",
              "type": "COMPLEX_LIST",
              "value": []
            }
          ],
          "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": "Booked note",
          "retryPolicy": null,
          "saveToVariable": null,
          "serviceId": "slack",
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "subtype": "API_SERVICE",
          "type": "EXTENSION"
        },
        "name": "Tell dispatch the reattempt is booked",
        "nextElementIds": [],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "elementId": "condition",
          "isFirstElement": false,
          "blockDefinitionId": "condition",
          "position": {
            "x": 883,
            "y": 519
          }
        },
        "flowElementId": "14BCE402-36A3-4EFA-9F3B-26A9FBA6D36D",
        "groupId": null,
        "id": "0D0E10D1-F9AF-439B-98F6-5BC9B0E560B5",
        "metaInfo": {
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "condition": {
            "conditionParts": [
              {
                "id": "a69c89b5-9925-4fca-81b8-b08f3f552e47",
                "nestedOperation": null,
                "operation": "equal",
                "property": {
                  "expression": [
                    {
                      "id": "RESULT",
                      "label": "Dispatch decision",
                      "subPathSegments": [
                        {
                          "key": "decision",
                          "optional": false
                        }
                      ],
                      "type": "TRIGGER_DATA",
                      "value": "50DD7998-92E7-44D7-B32F-6C3D447DAC02"
                    }
                  ],
                  "mode": "EXPRESSION",
                  "parseJsonString": false,
                  "resultType": null
                },
                "propertyType": "STRING",
                "values": [
                  {
                    "expression": [
                      {
                        "id": "TEXT",
                        "label": null,
                        "type": "INPUT",
                        "value": "rebook"
                      }
                    ],
                    "mode": "EXPRESSION",
                    "parseJsonString": false,
                    "resultType": null
                  }
                ]
              }
            ],
            "grouping": [
              "a69c89b5-9925-4fca-81b8-b08f3f552e47"
            ]
          },
          "elseComponent": {
            "componentId": "88FFC3E7-F544-4B0F-A789-CE8A60855579",
            "componentType": "ELEMENT"
          },
          "logging": null,
          "onFailElemId": null,
          "resultAlias": "Rebook it",
          "storeResult": false,
          "thenComponent": {
            "componentId": "F6E07B0F-4E12-4829-96A4-C3800DBBEE60",
            "componentType": "ELEMENT"
          }
        },
        "name": "Rebook it?",
        "nextElementIds": [
          "88FFC3E7-F544-4B0F-A789-CE8A60855579",
          "F6E07B0F-4E12-4829-96A4-C3800DBBEE60"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "preferredDateFormats": []
        },
        "type": "CONDITION"
      },
      {
        "clientMetadata": {
          "elementId": "custom-cloud-code",
          "isFirstElement": false,
          "blockDefinitionId": "custom-cloud-code",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Write the question for dispatch Result"
          },
          "position": {
            "x": 110,
            "y": 219
          }
        },
        "flowElementId": "4C11AAD5-3719-4490-9718-7A746C7E6831",
        "groupId": null,
        "id": "B86333C5-BA58-4A6C-BAE5-CE4BC5824496",
        "metaInfo": {
          "clientValidationState": {
            "errorMessage": "Block: 'Write the question for dispatch', Error: The placeholder \"Answer link\" has no value",
            "valid": false
          },
          "codeArguments": [
            {
              "name": "recipient",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Failure",
                    "subPathSegments": [
                      {
                        "key": "recipientName",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "D6CF4DCC-68DC-46BA-87A5-9C26A6A84CDA"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "address",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Failure",
                    "subPathSegments": [
                      {
                        "key": "address",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "D6CF4DCC-68DC-46BA-87A5-9C26A6A84CDA"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "loadNumber",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Failure",
                    "subPathSegments": [
                      {
                        "key": "loadNumber",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "D6CF4DCC-68DC-46BA-87A5-9C26A6A84CDA"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "shortId",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Failure",
                    "subPathSegments": [
                      {
                        "key": "shortId",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "D6CF4DCC-68DC-46BA-87A5-9C26A6A84CDA"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "attempt",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Failure",
                    "subPathSegments": [
                      {
                        "key": "attempt",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "D6CF4DCC-68DC-46BA-87A5-9C26A6A84CDA"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "reason",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Failure reading",
                    "subPathSegments": [
                      {
                        "key": "output",
                        "optional": false
                      },
                      {
                        "key": "reason",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "FA1B6CDB-685C-4F1A-9081-239D8076757F"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "failureReason",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Failure",
                    "subPathSegments": [
                      {
                        "key": "failureReason",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "D6CF4DCC-68DC-46BA-87A5-9C26A6A84CDA"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "driverNotes",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Failure",
                    "subPathSegments": [
                      {
                        "key": "driverNotes",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "D6CF4DCC-68DC-46BA-87A5-9C26A6A84CDA"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "photoLinks",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Failure",
                    "subPathSegments": [
                      {
                        "key": "photoLinks",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "D6CF4DCC-68DC-46BA-87A5-9C26A6A84CDA"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "customerTexted",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Customer text",
                    "subPathSegments": [
                      {
                        "key": "sid",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "C7DCA9CD-D093-4C48-81E3-2FC4D00F50C0"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "customerText",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Failure reading",
                    "subPathSegments": [
                      {
                        "key": "output",
                        "optional": false
                      },
                      {
                        "key": "customerText",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "FA1B6CDB-685C-4F1A-9081-239D8076757F"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "answerLink",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "PLACEHOLDER_DATA",
                    "label": "Answer link",
                    "subPathSegments": null,
                    "type": "EXECUTION_CONTEXT_STATIC_DATA",
                    "value": "Answer link"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "executionId",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "EXECUTION_ID",
                    "label": null,
                    "subPathSegments": null,
                    "type": "EXECUTION_CONTEXT_PATH",
                    "value": "executionContext.executionId",
                    "valueSegments": [
                      {
                        "key": "executionContext",
                        "optional": false
                      },
                      {
                        "key": "executionId",
                        "optional": false
                      }
                    ]
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            }
          ],
          "codeBody": {
            "expression": [
              {
                "id": "TEXT",
                "label": null,
                "type": "INPUT",
                "value": "const link = (decision) => `${answerLink}?execution=${encodeURIComponent(executionId)}&decision=${decision}`;\nconst lines = [\n  `*Delivery failed: ${recipient}, ${address}*`,\n  loadNumber ? `Load ${loadNumber}, Onfleet task ${shortId}, attempt ${attempt}` : `Onfleet task ${shortId}, attempt ${attempt}`,\n  `What happened: ${reason}`,\n  failureReason ? `Reason the driver picked: ${failureReason}` : null,\n  driverNotes ? `Driver's notes: ${driverNotes}` : null,\n  `Driver's photos: ${photoLinks}`,\n  customerTexted ? `We texted the customer: \"${customerText}\"` : '*The customer has no phone number in Onfleet, so nobody has told them yet.*',\n].filter(Boolean);\nreturn {\n  text: `Delivery failed for ${recipient}. Rebook it or hold it?`,\n  blocks: [\n    { type: 'section', text: { type: 'mrkdwn', text: lines.join('\\n') } },\n    { type: 'actions', elements: [\n      { type: 'button', style: 'primary', text: { type: 'plain_text', text: 'Rebook for tomorrow' }, url: link('rebook') },\n      { type: 'button', text: { type: 'plain_text', text: 'Hold for the customer' }, url: link('hold') },\n    ] },\n  ],\n};"
              }
            ],
            "mode": "EXPRESSION",
            "parseJsonString": false,
            "resultType": null
          },
          "enabled": true,
          "logging": {
            "input": {
              "logData": false,
              "message": null
            },
            "output": {
              "logData": false,
              "message": null
            }
          },
          "onFailElemId": null,
          "resultAlias": "Question card",
          "retryPolicy": null,
          "saveToVariable": null,
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "type": "CUSTOM_CLOUD_CODE"
        },
        "name": "Write the question for dispatch",
        "nextElementIds": [
          "13792391-8C43-4F6C-8616-5EACB6F15898"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "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,
          "dynamicOptionLabels": {
            "channelId": {}
          },
          "blockDefinitionId": "api-service-method",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Confirm the delivery is on hold Result"
          },
          "newElementId": "EXTENSION:::SHARED:::default:::slack:::sendMessageToChannel",
          "legacyElementId": "JS###v1###Slack###sendMessageToChannel",
          "methodName": "sendMessageToChannel",
          "position": {
            "x": 1249,
            "y": 380
          }
        },
        "flowElementId": "45598937-76F3-4E73-AABC-9BF308BB6298",
        "groupId": null,
        "id": "88FFC3E7-F544-4B0F-A789-CE8A60855579",
        "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": "TEXT",
                    "label": null,
                    "type": "INPUT",
                    "value": "On hold. No new delivery is booked for "
                  },
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Failure",
                    "subPathSegments": [
                      {
                        "key": "recipientName",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "D6CF4DCC-68DC-46BA-87A5-9C26A6A84CDA"
                  },
                  {
                    "id": "TEXT",
                    "label": null,
                    "type": "INPUT",
                    "value": " until someone creates one in Onfleet."
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "threadId",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Question to dispatch",
                    "subPathSegments": [
                      {
                        "key": "messageId",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "13792391-8C43-4F6C-8616-5EACB6F15898"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "sendAsBot",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "K_FALSE",
                    "label": null,
                    "type": "KEYWORD",
                    "value": false
                  }
                ],
                "mode": "EXPRESSION",
                "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": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "imageURL",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "blocks",
              "type": "COMPLEX_LIST",
              "value": []
            }
          ],
          "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": "Hold confirmation",
          "retryPolicy": null,
          "saveToVariable": null,
          "serviceId": "slack",
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "subtype": "API_SERVICE",
          "type": "EXTENSION"
        },
        "name": "Confirm the delivery is on hold",
        "nextElementIds": [],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "notes": "Creates a new task as a copy of an existing one, for example to re-attempt a failed delivery or schedule a return trip. Optionally copy the source task's metadata, barcodes and dependencies, and override its destination, recipients, notes, pickup or dropoff, service time, metadata and completion window. The new task's sourceTaskId points back to the original.",
          "elementId": "EXTENSION:::SHARED:::default:::onfleet:::cloneTask",
          "isFirstElement": false,
          "blockDefinitionId": "api-service-method",
          "setResultToVariable": false,
          "saveToVariable": {
            "dataBucket": "Default",
            "variable": "Book the reattempt for tomorrow Result"
          },
          "newElementId": "EXTENSION:::SHARED:::default:::onfleet:::cloneTask",
          "legacyElementId": "JS###v1###OnfleetService###cloneTask",
          "methodName": "cloneTask",
          "position": {
            "x": 1240,
            "y": 680
          }
        },
        "flowElementId": "399D5ED1-9703-47CB-A432-C3F7ED97EF87",
        "groupId": null,
        "id": "64663DA1-E69F-438D-B281-9EBD07DE20D1",
        "metaInfo": {
          "bodyParams": [
            {
              "name": "taskId",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Failure",
                    "subPathSegments": [
                      {
                        "key": "taskId",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "D6CF4DCC-68DC-46BA-87A5-9C26A6A84CDA"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "includeMetadata",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "K_TRUE",
                    "label": null,
                    "type": "KEYWORD",
                    "value": true
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "includeBarcodes",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "K_TRUE",
                    "label": null,
                    "type": "KEYWORD",
                    "value": true
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "includeDependencies",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "K_FALSE",
                    "label": null,
                    "type": "KEYWORD",
                    "value": false
                  }
                ],
                "mode": "BASIC",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "destinationId",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "recipientIds",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "notes",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Next day",
                    "subPathSegments": [
                      {
                        "key": "notes",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "F6E07B0F-4E12-4829-96A4-C3800DBBEE60"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "taskType",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "serviceTime",
              "type": "SIMPLE",
              "value": {
                "expression": [],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "metadata",
              "type": "COMPLEX_LIST",
              "value": []
            },
            {
              "name": "completeAfter",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Next day",
                    "subPathSegments": [
                      {
                        "key": "completeAfter",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "F6E07B0F-4E12-4829-96A4-C3800DBBEE60"
                  }
                ],
                "mode": "EXPRESSION",
                "parseJsonString": false,
                "resultType": null
              }
            },
            {
              "name": "completeBefore",
              "type": "SIMPLE",
              "value": {
                "expression": [
                  {
                    "id": "ELEMENT_RESULT",
                    "label": "Next day",
                    "subPathSegments": [
                      {
                        "key": "completeBefore",
                        "optional": false
                      }
                    ],
                    "type": "ELEMENT_LINK",
                    "value": "F6E07B0F-4E12-4829-96A4-C3800DBBEE60"
                  }
                ],
                "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": "cloneTask",
          "onFailElemId": null,
          "packageId": "default",
          "resultAlias": "Reattempt task",
          "retryPolicy": null,
          "saveToVariable": null,
          "serviceId": "onfleet",
          "simulationResult": null,
          "slaConditions": [],
          "storeResult": true,
          "subtype": "API_SERVICE",
          "type": "EXTENSION"
        },
        "name": "Book the reattempt for tomorrow",
        "nextElementIds": [
          "09750F4B-6E9D-423E-ACB5-02B607F80622"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "learningStatus": "OFF"
        },
        "type": "ACTION"
      },
      {
        "clientMetadata": {
          "elementId": "condition",
          "isFirstElement": false,
          "blockDefinitionId": "condition",
          "position": {
            "x": 490,
            "y": 49
          }
        },
        "flowElementId": "C9E67768-4AD1-4588-BD06-F6B568FCA3C8",
        "groupId": null,
        "id": "A9E9F9D3-B96A-4EC3-9E54-68DBB9F11431",
        "metaInfo": {
          "clientValidationState": {
            "errorMessage": null,
            "valid": true
          },
          "condition": {
            "conditionParts": [
              {
                "id": "c3183ae9-852d-47de-9684-12367bd1a1af",
                "nestedOperation": null,
                "operation": "isNotTrue",
                "property": {
                  "expression": [
                    {
                      "id": "RESULT",
                      "label": "Failed task",
                      "subPathSegments": [
                        {
                          "key": "data",
                          "optional": false
                        },
                        {
                          "key": "task",
                          "optional": false
                        },
                        {
                          "key": "pickupTask",
                          "optional": false
                        }
                      ],
                      "type": "TRIGGER_DATA",
                      "value": "B403C1ED-83B5-4CFB-BDD6-2CAB373927A3"
                    }
                  ],
                  "mode": "EXPRESSION",
                  "parseJsonString": false,
                  "resultType": null
                },
                "propertyType": "BOOLEAN",
                "values": []
              }
            ],
            "grouping": [
              "c3183ae9-852d-47de-9684-12367bd1a1af"
            ]
          },
          "elseComponent": null,
          "logging": null,
          "onFailElemId": null,
          "resultAlias": "Not a pickup",
          "storeResult": false,
          "thenComponent": {
            "componentId": "D6CF4DCC-68DC-46BA-87A5-9C26A6A84CDA",
            "componentType": "ELEMENT"
          }
        },
        "name": "A delivery, not a pickup?",
        "nextElementIds": [
          "D6CF4DCC-68DC-46BA-87A5-9C26A6A84CDA"
        ],
        "nextGroupIds": [],
        "serverFields": {
          "preferredDateFormats": []
        },
        "type": "CONDITION"
      }
    ],
    "firstElementId": "B403C1ED-83B5-4CFB-BDD6-2CAB373927A3",
    "groups": [],
    "id": "618F9C87-EF5E-45FA-AAFB-E2A44D03310E",
    "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": "Block 'Read why it failed' has an invalid configuration. User Prompt is not valid. Placeholder Data 'Company name': value is required",
      "executionStaticData": [
        {
          "description": "",
          "error": null,
          "name": "Anthropic key",
          "type": "API_KEY",
          "value": null
        },
        {
          "description": "The URL of the block Wait for dispatch's answer. The Slack buttons open it.",
          "error": null,
          "name": "Answer link",
          "type": "STRING",
          "value": ""
        },
        {
          "description": "Your Twilio number customers are texted from, in +1 format.",
          "error": null,
          "name": "Texting number",
          "type": "STRING",
          "value": ""
        },
        {
          "description": "Your company name as customers know it, used in texts.",
          "error": "Placeholder Data 'Company name': value is required",
          "name": "Company name",
          "type": "STRING",
          "value": ""
        },
        {
          "description": "Your dispatch time zone, used to set the next day's delivery window.",
          "error": null,
          "name": "Time zone",
          "type": "STRING",
          "value": ""
        },
        {
          "description": "Deliveries that have failed this many times go to dispatch instead of being rebooked on their own.",
          "error": null,
          "name": "Most attempts",
          "type": "INT",
          "value": ""
        },
        {
          "description": "The Onfleet task metadata field that holds the load number. Without it, the flow looks for 'Load 12345' in the task notes.",
          "error": null,
          "name": "Load number field",
          "type": "STRING",
          "value": ""
        },
        {
          "description": "The phone number customers call to reach dispatch, as it should appear in the text message.",
          "error": null,
          "name": "Dispatch phone",
          "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-11-26T05:50:55.771Z"
}
